Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
Fix pypa#104 (path pollution)
Browse files Browse the repository at this point in the history
_in_process.py is executed as a subprocess. This causes its parent
directory to become sys.path[0]. Any extra files in the same directory
shadow pypi libraries eg colorlog.

Solution: put _in_process.py in its own special subdirectory.
Note: the directory has to be a module because
importlib.resources.path does not support resources with directory
separators in their name:

https://docs.python.org/3/library/importlib.html#importlib.resources.path :
> resource is the name of the resource to open within package;
> it may not contain path separators and it may not have sub-resources
> (i.e. it cannot be a directory).
  • Loading branch information
hexagonrecursion committed Jan 31, 2021
1 parent 9b744ec commit 63dcd6d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
12 changes: 12 additions & 0 deletions pep517/in_process/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from os.path import dirname, abspath, join as pjoin
from contextlib import contextmanager

try:
import importlib.resources as resources

def _in_proc_script_path():
return resources.path(__package__, '_in_process.py')
except ImportError:
@contextmanager
def _in_proc_script_path():
yield pjoin(dirname(abspath(__file__)), '_in_process.py')
File renamed without changes.
11 changes: 1 addition & 10 deletions pep517/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from tempfile import mkdtemp

from . import compat
from .in_process import _in_proc_script_path

__all__ = [
'BackendUnavailable',
Expand All @@ -19,16 +20,6 @@
'Pep517HookCaller',
]

try:
import importlib.resources as resources

def _in_proc_script_path():
return resources.path(__package__, '_in_process.py')
except ImportError:
@contextmanager
def _in_proc_script_path():
yield pjoin(dirname(abspath(__file__)), '_in_process.py')


@contextmanager
def tempdir():
Expand Down

0 comments on commit 63dcd6d

Please sign in to comment.