Skip to content

Commit

Permalink
Improve PEP 518 build isolation (#5824)
Browse files Browse the repository at this point in the history
Handle .pth files, so namespace packages are correctly supported under Python 3.2 and earlier, and more.
  • Loading branch information
benoit-pierre authored and pradyunsg committed Oct 16, 2018
1 parent 1228f64 commit 83b879b
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/html/reference/pip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions news/5656.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Improve PEP 518 build isolation: handle .pth files, so namespace packages are correctly supported under Python 3.2 and earlier.
10 changes: 10 additions & 0 deletions src/pip/_internal/build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import os
import sys
import textwrap
from distutils.sysconfig import get_python_lib
from sysconfig import get_paths

Expand Down Expand Up @@ -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):
Expand Down
Binary file not shown.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools",
"wheel",
"simple_namespace",
]
2 changes: 2 additions & 0 deletions tests/data/src/pep518_with_namespace_package-1.0/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
universal=1
10 changes: 10 additions & 0 deletions tests/data/src/pep518_with_namespace_package-1.0/setup.py
Original file line number Diff line number Diff line change
@@ -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'],
)
2 changes: 2 additions & 0 deletions tests/data/src/simple_namespace/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
universal=1
9 changes: 9 additions & 0 deletions tests/data/src/simple_namespace/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from setuptools import setup


setup(
name='simple_namespace',
version='1.0',
namespace_packages=['simple_namespace'],
packages=['simple_namespace.module'],
)
Empty file.
Empty file.
10 changes: 10 additions & 0 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 83b879b

Please sign in to comment.