Skip to content

Resolve relative file:// URLs in [requires] correctly - #163

Merged
virtuald merged 1 commit into
robotpy:mainfrom
dellagd:fix/local-path-deps
May 15, 2026
Merged

Resolve relative file:// URLs in [requires] correctly#163
virtuald merged 1 commit into
robotpy:mainfrom
dellagd:fix/local-path-deps

Conversation

@dellagd

@dellagd dellagd commented May 14, 2026

Copy link
Copy Markdown
Contributor

What doesn't work

file:// URLs in [tool.robotpy] with relative paths.

Why this is an issue

PEP 508 permits direct URL requirements like bread @ file://../../lib/bread.

git+https://... already works today because cli_sync.py routes direct URL requirements through pip_wheel. Relative file:// URLs, however, are rejected by pip before that logic is reached: urlparse treats the first path segment as the netloc, and url_to_path()
raises:

ValueError: non-local file URIs are not supported for any non-empty, non-localhost netloc.

This breaks using monorepo-style path dependencies in pyproject.toml when otherwise that section works like normal for a pyproject.toml

How

pyproject._load() now takes an optional base_path (defaulted from pyproject.load() to the project directory) and
rewrites any relative file:// URL in a Requirement to an absolute file:// URL. Absolute URLs, non-file: schemes,
and loads() without a base path are unchanged.

Tests

5 new tests in tests/test_pyproject.py covering relative file://, file://./... dot segments, absolute URLs,
non-file URLs, and loads() with no base path.

pyproject.toml's `[tool.robotpy] requires` list accepts PEP 508
direct-URL requirements like `bread @ git+https://...`. Relative
`file://` URLs are also valid PEP 508 syntax, but pip rejects them:
urlparse interprets the first path segment as the netloc, and pip's
url_to_path() raises "non-local file URIs are not supported" for any
non-empty, non-localhost netloc.

This blocked using path dependencies (e.g. `bread @ file://../../lib/bread`)
in monorepos, forcing workarounds like symlinks or pre-built wheels
dropped into the pip cache.

Fix by resolving relative file:// URLs to absolute file:// URLs against
the project directory when loading pyproject.toml. Absolute URLs,
non-file schemes, and URLs without a base path (e.g. `loads()` without
an explicit base_path) are left untouched.
@dellagd dellagd changed the title Resolve relative file:// URLs in requires to absolute paths Resolve relative file:// URLs in requires correctly May 14, 2026
@dellagd dellagd changed the title Resolve relative file:// URLs in requires correctly Resolve relative file:// URLs in [requires] correctly May 14, 2026
@TheTripleV
TheTripleV requested a review from Copilot May 14, 2026 01:02

Copilot AI 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.

Pull request overview

Adds support for relative file:// URL requirements in [tool.robotpy].requires. pyproject._load() (and load/loads) now optionally accept a base_path and rewrite any relative file:// URL in a Requirement to an absolute file:// URI rooted at the project directory, working around pip's rejection of non-empty netlocs caused by urlparse treating the first path segment as netloc.

Changes:

  • Added _resolve_relative_file_url helper that detects relative file:// URLs (including the file://./... form) and rewrites them to absolute URIs rooted at base_path.
  • Threaded an optional base_path parameter through load(), loads(), and _load(), applied to every parsed requirement.
  • Added 5 tests in tests/test_pyproject.py covering relative, dot-segment, absolute, non-file, and missing-base-path cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
robotpy_installer/pyproject.py Adds base_path-aware rewriting of relative file:// requirement URLs.
tests/test_pyproject.py Adds tests covering the new relative-URL resolution behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@virtuald
virtuald merged commit e052e89 into robotpy:main May 15, 2026
24 checks passed
@virtuald

Copy link
Copy Markdown
Member

This is a bit esoteric, but if it works for you then it LGTM. Thanks.

@dellagd
dellagd deleted the fix/local-path-deps branch May 15, 2026 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants