Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/poetry/installation/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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`.
Expand Down
35 changes: 35 additions & 0 deletions tests/installation/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,41 @@ 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)
Comment thread
puneetdixit200 marked this conversation as resolved.

assert executor._create_directory_url_reference(package) == {
"dir_info": {},
"url": source.as_uri(),
}


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,
Expand Down
Loading