Skip to content

Commit

Permalink
Fix unable to start Medusa due to configparser ImportError (#5145)
Browse files Browse the repository at this point in the history
* Fix `_configure_syspath` to handle `.pth` files

Fix `configparser`s package structure.
Add missing `.pth` file for configparser
`.pth` file renamed for simplicity - original name: `configparser-3.5.0-py2.7-nspkg.pth`.

* Explain the code better

* Update info on `ext/readme.md`

* Prepare `syspath` code for the future

* Update changelog
  • Loading branch information
sharkykh authored and p0psicles committed Sep 9, 2018
1 parent 31171bc commit a1e7e1a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
- Fixed UI bugs in home page (when using "split home in tabs") and status page ([#5126](https://github.com/pymedusa/Medusa/pull/5126) + [#5127](https://github.com/pymedusa/Medusa/pull/5127))
- Fixed error due to `null` values in the episodes database table ([#5132](https://github.com/pymedusa/Medusa/pull/5132))
- Fixed extraneous calls to AniDB when navigating to any show's page ([#5166](https://github.com/pymedusa/Medusa/pull/5166))
- Fixed being unable to start Medusa due to an import error ([#5145](https://github.com/pymedusa/Medusa/pull/5145))


-----

Expand Down
2 changes: 0 additions & 2 deletions ext/backports/__init__.py

This file was deleted.

1 change: 1 addition & 0 deletions ext/configparser.pth
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import sys, types, os;has_mfs = sys.version_info > (3, 5);p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('backports',));importlib = has_mfs and __import__('importlib.util');has_mfs and __import__('importlib.machinery');m = has_mfs and sys.modules.setdefault('backports', importlib.util.module_from_spec(importlib.machinery.PathFinder.find_spec('backports', [os.path.dirname(p)])));m = m or sys.modules.setdefault('backports', types.ModuleType('backports'));mp = (m or []) and m.__dict__.setdefault('__path__',[]);(p not in mp) and mp.append(p)
2 changes: 1 addition & 1 deletion ext/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
:: | `chardet` | [3.0.4](https://pypi.org/project/chardet/3.0.4/) | **`medusa`**, `beautifulsoup4`, `feedparser`, `html5lib`, `pysrt`, `requests`, `subliminal` | -
:: | `cloudflare-scrape` | pymedusa/[320456e](https://github.com/pymedusa/cloudflare-scrape/tree/320456e8b28cedb807363a7a892b1379db843f66) | **`medusa`** | Module: `cfscrape`
:: | <code><b>configobj</b>.py</code><br>`validate.py`<br>`_version.py` | [5.0.6](https://pypi.org/project/configobj/5.0.6/) | **`medusa`** | -
:: | <code><b>configparser</b>.py</code><br>`backports.configparser` | [3.5.0](https://pypi.org/project/configparser/3.5.0/) | `adba` | -
:: | <code><b>configparser</b>.py</code><br>`configparser.pth`<br>`backports.configparser` | [3.5.0](https://pypi.org/project/configparser/3.5.0/) | `adba` | `configparser.pth` was renamed from `configparser-3.5.0-py2.7-nspkg.pth`
:: | <code><b>contextlib2</b>.py</code> | [0.5.5](https://pypi.org/project/contextlib2/0.5.5/) | **`medusa`**, `tvdbapiv2`, `vcrpy`(?) | Markers: `python_version < '3.5'`
:: | <code><b>decorator</b>.py</code> | [4.3.0](https://pypi.org/project/decorator/4.3.0/) | `validators` | -
:: | `dirtyjson` | [1.0.7](https://pypi.org/project/dirtyjson/1.0.7/) | **`medusa`** | -
Expand Down
36 changes: 34 additions & 2 deletions medusa/init/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import mimetypes
import os
import shutil
import site
import sys


Expand Down Expand Up @@ -46,8 +47,39 @@ def _ext_lib_location():


def _configure_syspath():
sys.path.insert(1, _lib_location())
sys.path.insert(1, _ext_lib_location())
"""Add the vendored libraries into `sys.path`."""
# Note: These paths will be inserted into `sys.path` in reverse order (LIFO)
# So the last path on this list will be inserted as the first path on `sys.path`
# right after the current working dir.
# For example: [ cwd, pathN, ..., path1, path0, <rest_of_sys.path> ]

paths_to_insert = [
_lib_location(),
_ext_lib_location()
]

if sys.version_info[0] == 2:
# Add Python 2-only vendored libraries
paths_to_insert.extend([
# path_to_lib2,
# path_to_ext2
])
elif sys.version_info[0] == 3:
# Add Python 3-only vendored libraries
paths_to_insert.extend([
# path_to_lib3,
# path_to_ext3
])

# Insert paths into `sys.path` and handle `.pth` files
# Inspired by: https://bugs.python.org/issue7744
for dirpath in paths_to_insert:
# Clear `sys.path`
sys.path, remainder = sys.path[:1], sys.path[1:]
# Add directory as a site-packages directory and handle `.pth` files
site.addsitedir(dirpath)
# Restore rest of `sys.path`
sys.path.extend(remainder)


def _register_utf8_codec():
Expand Down

0 comments on commit a1e7e1a

Please sign in to comment.