Skip to content

Commit

Permalink
Fix _configure_syspath to handle .pth files
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
sharkykh committed Sep 8, 2018
1 parent db3d9d7 commit 9068899
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
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)
17 changes: 15 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,20 @@ def _ext_lib_location():


def _configure_syspath():
sys.path.insert(1, _lib_location())
sys.path.insert(1, _ext_lib_location())
# Note: Paths are inserted in reverse order (LIFO)
paths_to_insert = [
_lib_location(),
_ext_lib_location()
]

# Handle `.pth` files: 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 9068899

Please sign in to comment.