|
| 1 | +import os |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | + |
| 7 | +@pytest.mark.install |
| 8 | +@pytest.mark.needs_internet |
| 9 | +@pytest.mark.skipif( |
| 10 | + os.name == "nt", |
| 11 | + reason="This test is not for Windows", |
| 12 | +) |
| 13 | +def test_install_path_with_nested_setup_module(pipenv_instance_pypi): |
| 14 | + with pipenv_instance_pypi() as p: |
| 15 | + # Install setuptools first for Python 3.12+ compatibility |
| 16 | + c = p.pipenv("install setuptools") |
| 17 | + assert c.returncode == 0 |
| 18 | + |
| 19 | + # Create a simple package. |
| 20 | + package_dir = Path(p.path) / "simple_package" |
| 21 | + package_dir.mkdir() |
| 22 | + |
| 23 | + # Create a simple setup.py file |
| 24 | + with open(package_dir / "setup.py", "w") as f: |
| 25 | + f.write(""" |
| 26 | +from setuptools import setup, find_packages |
| 27 | +
|
| 28 | +setup( |
| 29 | + name="simple-package", |
| 30 | + version="0.1.0", |
| 31 | + packages=find_packages(), |
| 32 | +) |
| 33 | +""") |
| 34 | + module_dir = package_dir / "simple_package" |
| 35 | + module_dir.mkdir() |
| 36 | + |
| 37 | + (module_dir / "__init__.py").touch() |
| 38 | + |
| 39 | + # Create a test module that contains setup.py-like content but isn't setup.py |
| 40 | + with open(module_dir / "test_setup.py", "w") as f: |
| 41 | + f.write(""" |
| 42 | +def setup(name = ''): |
| 43 | + return f'Setup package {name}' |
| 44 | +
|
| 45 | +def configure(): |
| 46 | + return setup(name='my_simple_package') |
| 47 | +""") |
| 48 | + |
| 49 | + # Install the package using a path with spaces |
| 50 | + # Use both escaped spaces and quoted path to test both scenarios |
| 51 | + relative_package_dir = f'"{package_dir.relative_to(p.path)}"' |
| 52 | + c = p.pipenv(f'install -e {relative_package_dir}') |
| 53 | + assert c.returncode == 0 |
| 54 | + |
| 55 | + # Verify the package was installed correctly |
| 56 | + c = p.pipenv('run python -c "' |
| 57 | + 'import simple_package.test_setup; ' |
| 58 | + 'print(simple_package.test_setup.configure())"') |
| 59 | + assert c.returncode == 0 |
| 60 | + assert "Setup package my_simple_package" in c.stdout |
| 61 | + |
| 62 | + # Ensure my_simple_package was not parsed from the test_setup.py module |
| 63 | + # inside the package - this is the key test for our fix. |
| 64 | + with open(Path(p.path) / "Pipfile") as f: |
| 65 | + pipfile_content = f.read() |
| 66 | + assert "my_simple_package" not in pipfile_content |
| 67 | + assert "simple-package" in pipfile_content # Should find the correct name |
0 commit comments