Skip to content

Commit

Permalink
fix: egg segment for local dependency (#1552)
Browse files Browse the repository at this point in the history
* fix: egg segment for local dependency

* add news

* fix: egg segment for local dependency with hash on folder name
  • Loading branch information
micaelmalta authored Dec 8, 2022
1 parent 35219db commit b357d0c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions news/1552.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug with egg segment for local dependency
7 changes: 4 additions & 3 deletions src/pdm/models/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
add_ssh_scheme_to_git_uri,
normalize_name,
path_to_url,
path_without_fragments,
url_to_path,
url_without_fragments,
)
Expand Down Expand Up @@ -292,11 +293,11 @@ def _parse_url(self) -> None:
path = get_relative_path(self.url)
if path is None:
try:
self.path = Path(url_to_path(self.url))
self.path = path_without_fragments(url_to_path(self.url))
except AssertionError:
pass
else:
self.path = Path(path)
self.path = path_without_fragments(path)
if self.url:
self._parse_name_from_url()

Expand All @@ -305,7 +306,7 @@ def relocate(self, backend: BuildBackend) -> None:
if self.path is None or self.path.is_absolute():
return
# self.path is relative
self.path = Path(os.path.relpath(self.path, backend.root))
self.path = path_without_fragments(os.path.relpath(self.path, backend.root))
self.url = backend.relative_path_to_url(self.path.as_posix())

@property
Expand Down
10 changes: 10 additions & 0 deletions src/pdm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from pdm._types import Source
from pdm.compat import Distribution

_egg_fragment_re = re.compile(r"(.*)[#&]egg=[^&]*")


def create_tracked_tempdir(
suffix: str | None = None, prefix: str | None = None, dir: str | None = None
Expand Down Expand Up @@ -410,3 +412,11 @@ def is_pip_compatible_with_python(python_version: Version | str) -> bool:
pip = importlib_metadata.distribution("pip")
requires_python = get_specifier(pip.metadata["Requires-Python"])
return requires_python.contains(python_version, True)


def path_without_fragments(path: str) -> Path:
"""Remove egg fragment from path"""
match = _egg_fragment_re.search(path)
if not match:
return Path(path)
return Path(match.group(1))
5 changes: 5 additions & 0 deletions tests/fixtures/projects/demo-#-with-hash/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import os

import chardet

print(os.name)
15 changes: 15 additions & 0 deletions tests/fixtures/projects/demo-#-with-hash/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from setuptools import setup


setup(
name="demo",
version="0.0.1",
description="test demo",
py_modules=["demo"],
python_requires=">=3.3",
install_requires=["idna", "chardet; os_name=='nt'"],
extras_require={
"tests": ["pytest"],
"security": ['requests; python_version>="3.6"'],
},
)
2 changes: 2 additions & 0 deletions tests/models/test_candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def test_parse_abnormal_specifiers(project):
"demo @ file:///${PROJECT_ROOT}/tests/fixtures/artifacts/demo-0.0.1.tar.gz",
"demo @ file:///${PROJECT_ROOT}/tests/fixtures/projects/demo",
"-e ./tests/fixtures/projects/demo",
"-e file:///${PROJECT_ROOT}/tests/fixtures/projects/demo#egg=demo",
"-e file:///${PROJECT_ROOT}/tests/fixtures/projects/demo-#-with-hash#egg=demo",
],
)
def test_expand_project_root_in_url(req_str, core):
Expand Down

0 comments on commit b357d0c

Please sign in to comment.