-
-
Notifications
You must be signed in to change notification settings - Fork 422
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
Link is not defined if not TYPE_CHECKING but it's used #2151
Comments
Can you submit a fix? |
Technically yes but I do not understand the details of the problem :) Why it is inside condition in the first place? This code seems preety common, am I only one getting this error, maybe due to some nix/pdx shenaningans? |
You already found the cause, didn't you? What you need to do is add a line in this function to import Link from unearth: pdm/src/pdm/models/candidates.py Lines 76 to 89 in fa34573
Others don't encounter this because they never enter the loop, because |
yes it is using static_links because that is the easiest method to enforce the internal packages to be resolved from internal PyPi and others from public one without using the --extra-index-url shenanigans that are a vulnerability. I wouldn't add import inside a function, it is a correct syntax-wise but imports inside functions seems hacky. Can we move it just 2 lines above to skip the type checking condition? |
No, that is an intended change, because |
A bit frustrating with the level of hacking we do to piggyback on top of PDM internals. Ending up also removing PDM 2.8 due to bug, pdm-project/pdm#2151, which was only fixed in 2.9. Apart from that all versions seem to work now. Will put up a PR with new CI image elsewhere.
Make sure you run commands with
-v
flag before pasting the output.Steps to reproduce
File "/nix/store/5a457g4zr7q11b4mz0ifc9z88kwcp8g7-python3-3.10.12/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/dgoslawski/.local/pipx/venvs/pdm/lib/python3.10/site-packages/pdm/installers/synchronizers.py", line 277, in install_candidate
self.manager.install(can)
File "/home/dgoslawski/.local/pipx/venvs/pdm/lib/python3.10/site-packages/pdm/installers/manager.py", line 33, in install
installer(str(prepared.build()), self.environment, prepared.direct_url())
File "/home/dgoslawski/.local/pipx/venvs/pdm/lib/python3.10/site-packages/pdm/models/candidates.py", line 379, in build
self.obtain(allow_all=False)
File "/home/dgoslawski/.local/pipx/venvs/pdm/lib/python3.10/site-packages/pdm/models/candidates.py", line 413, in obtain
self.link = _find_best_match_link(
File "/home/dgoslawski/.local/pipx/venvs/pdm/lib/python3.10/site-packages/pdm/models/candidates.py", line 88, in _find_best_match_link
links = [Link(f["url"]) for f in files if "url" in f]
File "/home/dgoslawski/.local/pipx/venvs/pdm/lib/python3.10/site-packages/pdm/models/candidates.py", line 88, in
links = [Link(f["url"]) for f in files if "url" in f]
NameError: name 'Link' is not defined
Actual behavior
pdm refuses to install. Installs when candidates.py is modified to move
from unearth import Link, Package, PackageFinder
outside the TYPE_CHECKING conditionExpected behavior
pdm installs
Environment Information
The text was updated successfully, but these errors were encountered: