diff --git a/docs/html/reference/pip.rst b/docs/html/reference/pip.rst index 905be1ea611..fff2e652bbc 100644 --- a/docs/html/reference/pip.rst +++ b/docs/html/reference/pip.rst @@ -158,6 +158,8 @@ appropriately. does not support the use of environment markers and extras (only version specifiers are respected). +* ``pip<18.1``: build dependencies using .pth files are not properly supported; + as a result namespace packages do not work under Python 3.2 and earlier. Future Developments ~~~~~~~~~~~~~~~~~~~ diff --git a/news/5656.bugfix b/news/5656.bugfix new file mode 100644 index 00000000000..5bf365a8d5b --- /dev/null +++ b/news/5656.bugfix @@ -0,0 +1 @@ +- Improve PEP 518 build isolation: handle .pth files, so namespace packages are correctly supported under Python 3.2 and earlier. diff --git a/src/pip/_internal/build_env.py b/src/pip/_internal/build_env.py index 673409d2645..409e01067ff 100644 --- a/src/pip/_internal/build_env.py +++ b/src/pip/_internal/build_env.py @@ -4,6 +4,7 @@ import logging import os import sys +import textwrap from distutils.sysconfig import get_python_lib from sysconfig import get_paths @@ -61,6 +62,15 @@ def __enter__(self): os.environ['PYTHONNOUSERSITE'] = '1' + # Ensure .pth files are honored. + with open(os.path.join(purelib, 'sitecustomize.py'), 'w') as fp: + fp.write(textwrap.dedent( + ''' + import site + site.addsitedir({!r}) + ''' + ).format(purelib)) + return self.path def __exit__(self, exc_type, exc_val, exc_tb): diff --git a/tests/data/packages/simple_namespace-1.0-py2.py3-none-any.whl b/tests/data/packages/simple_namespace-1.0-py2.py3-none-any.whl new file mode 100644 index 00000000000..21d03a0df50 Binary files /dev/null and b/tests/data/packages/simple_namespace-1.0-py2.py3-none-any.whl differ diff --git a/tests/data/src/pep518_with_namespace_package-1.0/pep518_with_namespace_package.py b/tests/data/src/pep518_with_namespace_package-1.0/pep518_with_namespace_package.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/data/src/pep518_with_namespace_package-1.0/pyproject.toml b/tests/data/src/pep518_with_namespace_package-1.0/pyproject.toml new file mode 100644 index 00000000000..255a212825d --- /dev/null +++ b/tests/data/src/pep518_with_namespace_package-1.0/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools", + "wheel", + "simple_namespace", +] diff --git a/tests/data/src/pep518_with_namespace_package-1.0/setup.cfg b/tests/data/src/pep518_with_namespace_package-1.0/setup.cfg new file mode 100644 index 00000000000..3c6e79cf31d --- /dev/null +++ b/tests/data/src/pep518_with_namespace_package-1.0/setup.cfg @@ -0,0 +1,2 @@ +[bdist_wheel] +universal=1 diff --git a/tests/data/src/pep518_with_namespace_package-1.0/setup.py b/tests/data/src/pep518_with_namespace_package-1.0/setup.py new file mode 100644 index 00000000000..7e58d0de60a --- /dev/null +++ b/tests/data/src/pep518_with_namespace_package-1.0/setup.py @@ -0,0 +1,10 @@ +from setuptools import setup + +import simple_namespace.module + + +setup( + name='pep518_with_namespace_package', + version='1.0', + py_modules=['pep518_with_namespace_package'], +) diff --git a/tests/data/src/simple_namespace/setup.cfg b/tests/data/src/simple_namespace/setup.cfg new file mode 100644 index 00000000000..3c6e79cf31d --- /dev/null +++ b/tests/data/src/simple_namespace/setup.cfg @@ -0,0 +1,2 @@ +[bdist_wheel] +universal=1 diff --git a/tests/data/src/simple_namespace/setup.py b/tests/data/src/simple_namespace/setup.py new file mode 100644 index 00000000000..20ee0044b7c --- /dev/null +++ b/tests/data/src/simple_namespace/setup.py @@ -0,0 +1,9 @@ +from setuptools import setup + + +setup( + name='simple_namespace', + version='1.0', + namespace_packages=['simple_namespace'], + packages=['simple_namespace.module'], +) diff --git a/tests/data/src/simple_namespace/simple_namespace/__init__.py b/tests/data/src/simple_namespace/simple_namespace/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/data/src/simple_namespace/simple_namespace/module/__init__.py b/tests/data/src/simple_namespace/simple_namespace/module/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index 1be8e10e392..b6fce2dbb72 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -100,6 +100,16 @@ def test_pep518_with_extra_and_markers(script, data, common_wheels): ) +def test_pep518_with_namespace_package(script, data, common_wheels): + script.pip( + 'wheel', '--no-index', + '-f', common_wheels, + '-f', data.find_links, + data.src.join("pep518_with_namespace_package-1.0"), + use_module=True, + ) + + @pytest.mark.timeout(60) @pytest.mark.parametrize('command', ('install', 'wheel')) @pytest.mark.parametrize('package', ('pep518_forkbomb',