Skip to content

Commit cf293d5

Browse files
authored
Fix bug with paths with spaces (#6381)
* Fix bug with paths with spaces * Add news * fix lint * fix test * fix build * fix build * fix test * Fix test * Fix test * fix ruff
1 parent 719470e commit cf293d5

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

news/6381.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed an issue with installing local packages that have spaces in their path names.

pipenv/utils/dependencies.py

+5
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,11 @@ def expansive_install_req_from_line(
999999
"""
10001000
name = None
10011001
pip_line = pip_line.strip("'").lstrip(" ")
1002+
1003+
# Handle paths with escaped spaces
1004+
if os.path.exists(os.path.expanduser(pip_line.replace("\\ ", " "))):
1005+
pip_line = pip_line.replace("\\ ", " ")
1006+
10021007
for new_req_symbol in ("@ ", " @ "): # Check for new style pip lines
10031008
if new_req_symbol in pip_line:
10041009
pip_line_parts = pip_line.split(new_req_symbol, 1)
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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_spaces(pipenv_instance_pypi):
14+
with pipenv_instance_pypi() as p:
15+
# Create a test directory with spaces in the name
16+
test_dir = Path(p.path) / "test dir with spaces"
17+
test_dir.mkdir()
18+
19+
# Create a simple package in the directory with spaces
20+
package_dir = test_dir / "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
27+
28+
setup(
29+
name="simple-package",
30+
version="0.1.0",
31+
)
32+
""")
33+
34+
# Create the package module
35+
with open(package_dir / "simple_package.py", "w") as f:
36+
f.write("""
37+
def hello():
38+
return "Hello from simple package!"
39+
""")
40+
41+
# Install the package using a path with spaces
42+
# Use both escaped spaces and quoted path to test both scenarios
43+
c = p.pipenv(f'install "{package_dir}"')
44+
assert c.returncode == 0
45+
46+
# Verify the package was installed correctly
47+
c = p.pipenv('run python -c "import simple_package; print(simple_package.hello())"')
48+
assert c.returncode == 0
49+
assert "Hello from simple package!" in c.stdout
50+
51+
# Test with escaped spaces
52+
p.pipenv("uninstall simple-package")
53+
escaped_path = package_dir.as_posix().replace(" ", "\\ ")
54+
c = p.pipenv(f'install {escaped_path}')
55+
assert c.returncode == 0
56+
57+
# Verify the package was installed correctly
58+
c = p.pipenv('run python -c "import simple_package; print(simple_package.hello())"')
59+
assert c.returncode == 0
60+
assert "Hello from simple package!" in c.stdout

0 commit comments

Comments
 (0)