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

uv-lock chokes on dynamic version metadata in pre-commit.ci #35

Open
neutrinoceros opened this issue Jan 8, 2025 · 10 comments
Open

uv-lock chokes on dynamic version metadata in pre-commit.ci #35

neutrinoceros opened this issue Jan 8, 2025 · 10 comments

Comments

@neutrinoceros
Copy link

Here's a self-contained MRE repo: https://github.com/neutrinoceros/uv-pre-commit-reprod
It contains a bare Python package with minimal metadata, and uses uv-lock from uv-pre-commit.
Seemingly, the important part is that project::version is declared as dynamic in pyproject.toml:

  × Failed to build `uv-pre-commit-reprod @ file:///code`
  ├─▶ Failed to resolve requirements from `build-system.requires`
  ├─▶ No solution found when resolving: `setuptools>=61.2`
  ├─▶ Failed to fetch: `https://pypi.org/simple/setuptools/`
  ├─▶ Could not connect, are you offline?
  ├─▶ Request failed after 3 retries
  ├─▶ error sending request for url (https://pypi.org/simple/setuptools/)
  ├─▶ client error (Connect)
  ├─▶ dns error: failed to lookup address information: Temporary failure in
  │   name resolution
  ╰─▶ failed to lookup address information: Temporary failure in name
      resolution

Meanwhile, locally, running uv lock directly or invoking pre-commit run --all-files gives the expected result.

I have no idea if this is an issue with uv, uv-pre-commit, or pre-commit.ci, so I thought I'd just report to the intermediate layer in that stack.
Possibly related to #25

@neutrinoceros
Copy link
Author

neutrinoceros commented Jan 8, 2025

I can guess what is going on actually:
pre-commit.ci likely disables network access when running hooks (which I guess is a security measure). Meanwhile, uv lock needs to record the version of the project, but cannot do so without build-time requirements, which it obviously needs network access for...
I'm not sure why it's important to record the project's own version within the lock file though, but I can see how this plays poorly with dynamic metadata.

@danielhollas
Copy link

I ran into this as well, with the following pyproject.toml using the flit backend

[build-system]
build-backend = 'flit_core.buildapi'                                                                                                 
requires = ['flit_core >=3.4,<4']

[project]
dynamic = ['version']

The error

Using CPython 3.10.12 interpreter at: /usr/bin/python3
error: Failed to generate package metadata for `aiida-core==2.6.2.post0 @ editable+.`
  Caused by: Failed to resolve requirements from `build-system.requires`
  Caused by: No solution found when resolving: `flit-core>=3.4, <4`
  Caused by: Failed to fetch: `https://pypi.org/simple/flit-core/`
  Caused by: Could not connect, are you offline?
  Caused by: Request failed after 3 retries
  Caused by: error sending request for url (https://pypi.org/simple/flit-core/)
  Caused by: client error (Connect)
  Caused by: dns error: failed to lookup address information: Temporary failure in name resolution
  Caused by: failed to lookup address information: Temporary failure in name resolution

@danielhollas
Copy link

pre-commit.ci likely disables network access when running hooks (which I guess is a security measure).

Just confirming that pre-commit.ci indeed disables network access: pre-commit-ci/issues#189

@danielhollas
Copy link

Looks like this issue might get resolved soon in astral-sh/uv#10622

@neutrinoceros
Copy link
Author

Apparently this wasn't sufficient, see neutrinoceros/uv-pre-commit-reprod#3

@danielhollas
Copy link

Indeed, the issue is still there, here's an updated error

uv-lock..................................................................Failed
- hook id: uv-lock
- exit code: 2

warning: `VIRTUAL_ENV=/pc/clone/lRBR-gjYQKOXQpweusrLMA/py_env-python3` does not match the project environment path `.venv` and will be ignored
Using CPython 3.10.12 interpreter at: /usr/bin/python3
error: Failed to generate package metadata for `aiida-core @ editable+.`
  Caused by: Failed to resolve requirements from `build-system.requires`
  Caused by: No solution found when resolving: `flit-core>=3.4, <4`
  Caused by: Failed to fetch: `https://pypi.org/simple/flit-core/`
  Caused by: Could not connect, are you offline?
  Caused by: Request failed after 3 retries
  Caused by: error sending request for url (https://pypi.org/simple/flit-core/)
  Caused by: client error (Connect)
  Caused by: dns error: failed to lookup address information: Temporary failure in name resolution
  Caused by: failed to lookup address information: Temporary failure in name resolution

Here's our pyproject.toml in case that is helpful: https://github.com/aiidateam/aiida-core/blob/main/pyproject.toml

@danielhollas
Copy link

I opened a tracking issue for the remaining work: astral-sh/uv#10689

@neutrinoceros
Copy link
Author

Thank you. I see the issue you linked was resolved in uv 0.5.21. However, this still doesn't resolve this one, see neutrinoceros/uv-pre-commit-reprod#4

@danielhollas
Copy link

Interesting, it works for us: https://results.pre-commit.ci/run/github/77234579/1737200748.0L_2sy30S1eqbCv5JpbFkA

Maybe there's something else in your pyproject.toml that's causing the build backend to be invoked?
(we don't have anything dynamic besides the version)

@danielhollas
Copy link

Hmm, your pyproject

[project]
name = "uv-pre-commit-reprod"
dynamic = ["version"]

[build-system]
requires = ["setuptools>=61.2"]
build-backend = "setuptools.build_meta"

[tool.setuptools.dynamic]
version = {attr = "uv_pre_commit_reprod.__version__"}

We have

[build-system]
build-backend = 'flit_core.buildapi'    
requires = ['flit_core >=3.4,<4']

[project]
dynamic = ['version']

[tool.flit.module]
name = 'aiida'

[tool.flit.sdist]
exclude = [
   'docs/',
  'tests/',
]
...
...

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

No branches or pull requests

2 participants