Skip to content

Commit

Permalink
Merge pull request #105 from hexagonrecursion/fix104
Browse files Browse the repository at this point in the history
Fix #104 (path pollution)
  • Loading branch information
takluyver committed Mar 11, 2021
2 parents d28f438 + a0db2b8 commit 17a7f86
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ __pycache__/
.tox
.pytest_cache
doc/_build/
*.egg-info/
17 changes: 17 additions & 0 deletions pep517/in_process/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""This is a subpackage because the directory is on sys.path for _in_process.py
The subpackage should stay as empty as possible to avoid shadowing modules that
the backend might import.
"""
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.
13 changes: 2 additions & 11 deletions pep517/wrappers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import threading
from contextlib import contextmanager
import os
from os.path import dirname, abspath, join as pjoin
from os.path import abspath, join as pjoin
import shutil
from subprocess import check_call, check_output, STDOUT
import sys
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
3 changes: 3 additions & 0 deletions tests/samples/test-for-issue-104/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
11 changes: 11 additions & 0 deletions tests/samples/test-for-issue-104/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sys
from setuptools import setup
from os import path, environ, listdir
import json

children = listdir(sys.path[0])
out = path.join(environ['PEP517_ISSUE104_OUTDIR'], 'out.json')
with open(out, 'w') as f:
json.dump(children, f)

setup()
17 changes: 17 additions & 0 deletions tests/test_call_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import toml
import zipfile
import sys
import json

try:
from mock import Mock # Prefer the backport below python 3.6
Expand Down Expand Up @@ -154,3 +155,19 @@ def test_custom_python_executable(monkeypatch, tmpdir):
hooks.get_requires_for_build_wheel()
runner.assert_called_once()
assert runner.call_args[0][0][0] == 'some-python'


def test_issue_104():
hooks = get_hooks('test-for-issue-104')
with TemporaryDirectory() as outdir:
with modified_env({
'PYTHONPATH': BUILDSYS_PKGS,
'PEP517_ISSUE104_OUTDIR': outdir,
}):
hooks.get_requires_for_build_wheel({})
with open(pjoin(outdir, 'out.json')) as f:
children = json.load(f)
assert set(children) <= {
'__init__.py', '__init__.pyc', '_in_process.py', '_in_process.pyc',
'__pycache__',
}

0 comments on commit 17a7f86

Please sign in to comment.