Skip to content

Resolve relative direct URLs for local sources - #10917

Merged
radoering merged 3 commits into
python-poetry:mainfrom
puneetdixit200:fix/10830-directory-url-reference
Jun 20, 2026
Merged

radoering merged 3 commits into
python-poetry:mainfrom
puneetdixit200:fix/10830-directory-url-reference

Conversation

@puneetdixit200

Copy link
Copy Markdown
Contributor

Resolves: #10830

When Poetry writes PEP 610 direct_url.json metadata for local directory or file sources, it now resolves relative source paths before converting them to file URIs. This avoids Path.as_uri() raising for relative paths such as repositories cloned under a relative virtualenvs path.

Added a regression test for relative directory source URLs and kept the existing file/directory direct-url behavior covered.

  • Added tests for changed code.
  • Updated documentation for changed code.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The new _path_to_file_url helper assumes package.source_url is always a filesystem path; if there’s any chance it might be a file:// URI or another scheme, consider either normalizing/handling those cases or adding a clear assertion/comment so future callers don’t accidentally pass non-path strings.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `_path_to_file_url` helper assumes `package.source_url` is always a filesystem path; if there’s any chance it might be a `file://` URI or another scheme, consider either normalizing/handling those cases or adding a clear assertion/comment so future callers don’t accidentally pass non-path strings.

## Individual Comments

### Comment 1
<location path="tests/installation/test_executor.py" line_range="952-961" />
<code_context>
     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(),
+    }
+
</code_context>
<issue_to_address>
**suggestion (testing):** Add a companion test for relative file sources to cover `_create_file_url_reference` and the common `_path_to_file_url` helper.

This regression test covers the relative directory case. Since `_path_to_file_url` is also used by `_create_file_url_reference` for `source_type="file"`, please add a similar test for a relative file path (e.g. a temp file under `tmp_path`, using `_create_file_url_reference` with a relative `source_url`, and asserting the resulting `"url"` matches `file_path.as_uri()`) so both call sites are exercised.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them âœĻ
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread tests/installation/test_executor.py Outdated
@puneetdixit200
puneetdixit200 force-pushed the fix/10830-directory-url-reference branch from 64600a0 to 5d5dc6a Compare May 23, 2026 15:05
@puneetdixit200

Copy link
Copy Markdown
Contributor Author

Pushed 5d5dc6a after rebasing on current main and adding the relative file-source direct URL test requested in review.

Verified:

  • .venv/bin/python -m pytest tests/installation/test_executor.py::test_executor_should_create_pep610_url_reference_for_relative_directory tests/installation/test_executor.py::test_executor_should_create_pep610_url_reference_for_relative_file -q
  • .venv/bin/python -m ruff check tests/installation/test_executor.py
  • git diff --check

@puneetdixit200
puneetdixit200 force-pushed the fix/10830-directory-url-reference branch from 5d5dc6a to ccf2480 Compare May 24, 2026 15:01
@puneetdixit200

Copy link
Copy Markdown
Contributor Author

Rebased again on current main (448eadfa). No code changes beyond the rebase.

Verified locally:

  • python3 -m py_compile src/poetry/installation/executor.py tests/installation/test_executor.py
  • git diff --check upstream/main...HEAD

@puneetdixit200
puneetdixit200 force-pushed the fix/10830-directory-url-reference branch from 52af34e to d534920 Compare May 28, 2026 17:03
@puneetdixit200

Copy link
Copy Markdown
Contributor Author

Rebased onto current main; no code changes beyond replaying the existing patch.

New head: d534920b589b.

Verified locally:

  • python3 -m py_compile src/poetry/installation/executor.py tests/installation/test_executor.py
  • git diff --check upstream/main...HEAD

@puneetdixit200
puneetdixit200 force-pushed the fix/10830-directory-url-reference branch from d534920 to dab6f7a Compare June 2, 2026 23:17
@radoering
radoering force-pushed the fix/10830-directory-url-reference branch from dab6f7a to e0e87af Compare June 20, 2026 10:57
@radoering
radoering enabled auto-merge (squash) June 20, 2026 11:23
@radoering
radoering merged commit cf54a1c into python-poetry:main Jun 20, 2026
52 checks passed
@dosubot

dosubot Bot commented Jun 20, 2026

Copy link
Copy Markdown

📄 Knowledge review

✏ïļ Documentation updates

1 page was updated by changes in this PR.

Page Library Status
CHANGELOG /poetry/blob/main/CHANGELOG.md Python Poetry ✅ Updated
📝 CHANGELOG — changes
@@ -9,6 +9,7 @@
 ### Fixed
 
 - Fix an issue where `poetry update <package>` failed when `<package>` was a transitive dependency ([#10885](https://github.com/python-poetry/poetry/pull/10885)).
+- Fix an issue where Poetry raised an error when writing PEP 610 `direct_url.json` metadata for local directory or file sources with relative paths ([#10830](https://github.com/python-poetry/poetry/issues/10830), [#10917](https://github.com/python-poetry/poetry/pull/10917)).
 
 
 ## [2.4.0] - 2026-05-03

Leave Feedback Ask Dosu about poetry Add Dosu to your team

@github-actions

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected relative paths when using subdirectory argument with nested git based dependencies

2 participants