From abe64e4658266168b5441f2c7f6239cd52e24456 Mon Sep 17 00:00:00 2001 From: Puneet Dixit <236133619+puneetdixit200@users.noreply.github.com> Date: Thu, 21 May 2026 15:39:05 +0530 Subject: [PATCH 1/2] Resolve relative direct URLs for local sources --- src/poetry/installation/executor.py | 12 ++++++++++-- tests/installation/test_executor.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/poetry/installation/executor.py b/src/poetry/installation/executor.py index af9cf784a1e..40edcc354c6 100644 --- a/src/poetry/installation/executor.py +++ b/src/poetry/installation/executor.py @@ -922,7 +922,7 @@ def _create_file_url_reference(self, package: Package) -> dict[str, Any]: assert package.source_url is not None return { - "url": Path(package.source_url).as_uri(), + "url": self._path_to_file_url(package.source_url), "archive_info": archive_info, } @@ -934,10 +934,18 @@ def _create_directory_url_reference(self, package: Package) -> dict[str, Any]: assert package.source_url is not None return { - "url": Path(package.source_url).as_uri(), + "url": self._path_to_file_url(package.source_url), "dir_info": dir_info, } + @staticmethod + def _path_to_file_url(path: str) -> str: + source = Path(path) + if not source.is_absolute(): + source = source.resolve() + + return source.as_uri() + def _get_archive_info(self, package: Package) -> dict[str, Any]: """ Create dictionary `archive_info` for file `direct_url.json`. diff --git a/tests/installation/test_executor.py b/tests/installation/test_executor.py index 08aa1bf294b..9b950035319 100644 --- a/tests/installation/test_executor.py +++ b/tests/installation/test_executor.py @@ -949,6 +949,23 @@ def test_executor_should_write_pep610_url_references_for_directories( assert not prepare_spy.spy_return.exists(), "archive not cleaned up" +def test_executor_should_create_pep610_url_reference_for_relative_directory( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + source = tmp_path / "source" + source.mkdir() + monkeypatch.chdir(tmp_path) + + package = Package("demo", "0.1.2", source_type="directory", source_url="source") + + executor = object.__new__(Executor) + + assert executor._create_directory_url_reference(package) == { + "dir_info": {}, + "url": source.as_uri(), + } + + def test_executor_should_write_pep610_url_references_for_editable_directories( tmp_venv: VirtualEnv, pool: RepositoryPool, From ccf24801b172e6590c9775de8b9d007c229e3acd Mon Sep 17 00:00:00 2001 From: Puneet Dixit <236133619+puneetdixit200@users.noreply.github.com> Date: Sat, 23 May 2026 20:34:43 +0530 Subject: [PATCH 2/2] test: cover relative file direct URLs --- tests/installation/test_executor.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/installation/test_executor.py b/tests/installation/test_executor.py index 9b950035319..baeac76fca0 100644 --- a/tests/installation/test_executor.py +++ b/tests/installation/test_executor.py @@ -966,6 +966,24 @@ def test_executor_should_create_pep610_url_reference_for_relative_directory( } +def test_executor_should_create_pep610_url_reference_for_relative_file( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + source = tmp_path / "source.tar.gz" + source.write_bytes(b"archive") + monkeypatch.chdir(tmp_path) + + package = Package("demo", "0.1.2", source_type="file", source_url="source.tar.gz") + + executor = object.__new__(Executor) + executor._hashes = {} + + assert executor._create_file_url_reference(package) == { + "archive_info": {}, + "url": source.as_uri(), + } + + def test_executor_should_write_pep610_url_references_for_editable_directories( tmp_venv: VirtualEnv, pool: RepositoryPool,