Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve find-links paths relative to the configuration file #10827

Merged
merged 8 commits into from
Jan 22, 2025

Conversation

NightRa
Copy link
Contributor

@NightRa NightRa commented Jan 21, 2025

One-liner

Relative find-links configuration to local path from a pyproject.toml or uv.toml is now relative to the config file

Summary

Background

One can configure find-links in a pyproject.toml or uv.toml file, which are located from the cli arg, system directory, user directory, or by traversing parent directories until one is encountered.

This PR addresses the following scenario:

  • A project directory which includes a pyproject.toml or uv.toml file
  • The config file includes a find-links option. (eg under [tool.uv] for pyproject.toml)
  • The find-links option is configured to point to a local subdirectory in the project: packages/
  • There is a subdirectory called subdir, which is the current working directory
  • I run uv run my_script.py. This will locate the pyproject.toml in the parent directory

Current Behavior

  • uv tries to use the path subdir/packages/ to find packages, and fails.

New Behavior

  • uv tries to use the path packages/ to find the packages, and succeeds
  • Specifically, any relative local find-links path will resolve to be relative to the configuration file.

Why is this behavior change OK?

  • I believe no one depends on the behavior that a relative find-links when running in a subdir will refer to different directories each time
  • Thus this change only allows a more common use case which didn't work previously.

Test Plan

  • I re-created the setup mentioned above:
UvTest/
├── packages/
│   ├── colorama-0.4.6-py2.py3-none-any.whl
│   └── tqdm-4.67.1-py3-none-any.whl
├── subdir/
│   └── my_script.py
└── pyproject.toml
# pyproject.toml
[project]
name = "uvtest"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
    "tqdm>=4.67.1",
]

[tool.uv]
offline = true
no-index = true
find-links = ["packages/"]
  • With working directory under subdir, previously, running uv sync --offline would fail resolving the tdqm package, and after the change it succeeds.
  • Additionally, one can use uv sync --show-settings to show the actually-resolved settings - now having the desired path in flat_index.url.path

Alternative designs considered

  • I considered modifying the impl Deserialize for IndexUrl to parse ahead of time directly with a base directory by having a custom Deserializer with a base dir field, but it seems to contradict the design of the serde Deserialize trait - which should work with all Deserializers

Future work

  • Support for adjusting all other local-relative paths in Options would be desired, but is out of scope for the current PR.

@charliermarsh
Copy link
Member

Thanks. It would be useful to include a test here (that fails on main but passes on this branch) to guard against regressions (and make sure we understand the problematic scenario).

@NightRa
Copy link
Contributor Author

NightRa commented Jan 21, 2025

@charliermarsh

  • A test corresponding to the scenario I described would need to have a whl file for some package.
  • Which minimal test package would you consider appropriate for this?
  • This would also imply it needs to be checked in the uv repository
  • Where would be an appropriate location in the repository to hold this whl file for the test?

@charliermarsh
Copy link
Member

We already have a few checked-in that you can use in ./scripts/links. Grep around for tests that use scripts/links for examples?

@NightRa
Copy link
Contributor Author

NightRa commented Jan 21, 2025

@charliermarsh
Done.
Also checked the test fails on master and succeeds here.
Previously it would fail with:

error: Failed to read `--find-links` directory: C:\Users\...\AppData\Roaming\uv\tests\.tmpS7JaZu\temp\subdir\packages
  Caused by: The system cannot find the path specified. (os error 3)

@NightRa
Copy link
Contributor Author

NightRa commented Jan 22, 2025

@charliermarsh Anything else required to merge here?

@charliermarsh
Copy link
Member

No, I just need time to review the changes.

@NightRa
Copy link
Contributor Author

NightRa commented Jan 22, 2025

Great, thanks for your time!

@charliermarsh charliermarsh added the bug Something isn't working label Jan 22, 2025
@charliermarsh charliermarsh enabled auto-merge (squash) January 22, 2025 19:36
@charliermarsh charliermarsh merged commit b1e4bc7 into astral-sh:main Jan 22, 2025
68 checks passed
@zanieb zanieb changed the title [uv-settings]: Correct behavior for relative find-links paths when run from a subdir Resolve find-links paths relative to the configuration file Jan 22, 2025
@NightRa
Copy link
Contributor Author

NightRa commented Jan 22, 2025

Indeed wasn't sure about the &mut. Thanks for the fixes
Love the quick support. Would recommend. 10/10

@charliermarsh
Copy link
Member

Yeah the &mut worked, I just generally prefer to use these kinds of immutability patterns. Thanks for the PR!

tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Jan 26, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [astral-sh/uv](https://github.com/astral-sh/uv) | patch | `0.5.22` -> `0.5.24` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>astral-sh/uv (astral-sh/uv)</summary>

### [`v0.5.24`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0524)

[Compare Source](astral-sh/uv@0.5.23...0.5.24)

##### Enhancements

-   Improve determinism of resolution by always setting package priorities ([#&#8203;10853](astral-sh/uv#10853))
-   Upgrade to `cargo-dist` 0.28.0; improves several installer behaviors ([#&#8203;10884](astral-sh/uv#10884))

##### Performance

-   Remove dependencies clone in resolver ([#&#8203;10880](astral-sh/uv#10880))
-   Use Hashbrown's raw entry API to reduce hashes and clone in resolver priority determination ([#&#8203;10881](astral-sh/uv#10881))

##### Bug fixes

-   Allow fallback to Python download on non-critical discovery errors ([#&#8203;10908](astral-sh/uv#10908))

##### Preview features

-   Register managed Python version with the Windows Registry (PEP 514) ([#&#8203;10634](astral-sh/uv#10634))

##### Documentation

-   Improve documentation for some environment variables ([#&#8203;10887](astral-sh/uv#10887))
-   Add git subdirectory example ([#&#8203;10894](astral-sh/uv#10894))

### [`v0.5.23`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0523)

[Compare Source](astral-sh/uv@0.5.22...0.5.23)

##### Enhancements

-   Add `--refresh` to `uv venv` ([#&#8203;10834](astral-sh/uv#10834))
-   Add `--no-default-groups` command-line flag ([#&#8203;10618](astral-sh/uv#10618))

##### Bug fixes

-   Sort extras and groups when comparing lockfile requirements ([#&#8203;10856](astral-sh/uv#10856))
-   Include `commit_id` and `requested_revision` in `direct_url.json` ([#&#8203;10862](astral-sh/uv#10862))
-   Invalidate lockfile when static versions change ([#&#8203;10858](astral-sh/uv#10858))
-   Make GitHub fast path errors non-fatal ([#&#8203;10859](astral-sh/uv#10859))
-   Remove warnings for `--frozen` and `--locked` in `uv run --script` ([#&#8203;10840](astral-sh/uv#10840))
-   Resolve `find-links` paths relative to the configuration file ([#&#8203;10827](astral-sh/uv#10827))
-   Respect visitation order for proxy packages ([#&#8203;10833](astral-sh/uv#10833))
-   Treat version mismatch errors as non-fatal in fast paths ([#&#8203;10860](astral-sh/uv#10860))
-   Mark `--locked` and `--upgrade` are conflicting ([#&#8203;10836](astral-sh/uv#10836))
-   Relax error checking around unconditional enabling of conflicting extras ([#&#8203;10875](astral-sh/uv#10875))

##### Documentation

-   Reduce ambiguity in conflicting extras example ([#&#8203;10877](astral-sh/uv#10877))
-   Update pre-commit documentation  ([#&#8203;10756](astral-sh/uv#10756))

##### Error messages

-   Error when workspace contains conflicting Python requirements ([#&#8203;10841](astral-sh/uv#10841))
-   Improve uvx error message when uv is missing ([#&#8203;9745](astral-sh/uv#9745))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMjIuMCIsInVwZGF0ZWRJblZlciI6IjM5LjEyNC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants