-
-
Notifications
You must be signed in to change notification settings - Fork 615
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
Periods get converted to dashes in package name #1576
Comments
These days pip is doing more canonicalization, and so pip-tools is following to ensure consistency and accurate comparisons. This request as I understand it is for package names to recreate their exact input names in the output. I'm personally a maybe on this. FWIW: In [1]: from pip._vendor.packaging.utils import canonicalize_name
In [2]: canonicalize_name??
Source:
def canonicalize_name(name: str) -> NormalizedName:
# This is taken from PEP 503.
value = _canonicalize_regex.sub("-", name).lower()
return cast(NormalizedName, value)
In [3]: from pip._vendor.packaging.utils import _canonicalize_regex
In [4]: _canonicalize_regex
Out[4]: re.compile(r'[-_.]+', re.UNICODE) |
Thank you for that information. Then I suppose I would prefer that all the periods get converted to dashes, including the comments under my-sub-package==1.1.1
# via
# -r requirements.txt
# my-package I can file a bug with my team to handle |
I believe the annotation periods are converted to dashes as of the recent |
@sawatsky Do you think the current approach (converging names) is good enough to close this, or should it be kept open to discuss re-applying original names? |
@AndydeCleyre I'm on python 3.8.12 and this behavior introduces the following error: |
I'm not at a computer for now but will try to replicate and investigate when I can. Can you provide definite reproduction steps? |
Sure. This is how we face the issue: This is the full trace:
|
Thanks! This might be outside of pip-tools. Sounds like the req file is compiled alright.
|
Thanks for your help! In the meantime, doing some testing I realised we only have the issue when installing in editable mode via Here are the answers to your questions: Are you using pip-sync to install them? If not, how are you installing the packages?
Can you reproduce this with a plain venv?
What version of click are you using?
What's the output of pip list | grep -i c4.spanner?
|
I haven't been able to reproduce yet, @aflaisler . Can you do so with https://github.com/andydeCleyre/1576 ? $ python3 -m venv venv
$ . ./venv/bin/activate
$ pip install -U pip -r requirements.txt
$ pip install -e .
$ test-with-editable-dots
success If not, can you modify that example project to reproduce the problem? |
I'm seeing this issue with one of my team's builds. @AndydeCleyre I've reproduced this in a modified version of your example project: https://github.com/laurence-kobold/1576 I've made two changes:
Running your sample code produces the following error:
|
This problem also happens in my team's build process, because we set the |
Thanks, that's helpful stuff! In your particular case, do you really need to parse the I'm looking into this, but my guess right now is that it's a bug in setuptools' handling of A temporary workaround is to replace dashes with dots when populating |
|
Good question. We could get around this by relying on users to keep both in sync, though that seems error prone. Potentially we might be able to get enough information by parsing the
The issue with that is that we'd have to distinguish between dashes due to normalization and dashes that were in the original package name. I think an easier temporary fix is for us to downgrade pip-tools.
I'm still seeing this issue with |
Ah yes, my mistake. |
I do think this is a bug in setuptools, and can be reproduced without pip-tools, just with If you edit the launcher file that setuptools created and replace it with the much simpler: #!/...keep original shebang here
import re
import sys
from testing_editable_dots.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main()) then it seems to work fine. |
Note that IDEs managing package installation through requirements.txt can complain that requirements are not satisified (Exemple with |
Related:
What still looks like the best idea to me is for everyone who wants to predictably compare or identify Python packages to use the normalization procedure described in PEP 503:
import re
def normalize(name):
return re.sub(r"[-_.]+", "-", name).lower() |
Thanks for opening that |
Setuptools just released v62, with better matching logic, and seems to fix the issues 🎉. Can you confirm your needs are met by installing the relevant packages with setuptools 62? |
Do you think we ought to constrain our setuptools dependency to |
I'd prefer not to. It might be too restrictive for users. |
@AndydeCleyre wrote:
Genuine question (because maybe I've missed something important)... Can anyone explain to me why are we (the python community, pip maintainers, pip-tools maintainers, PyCharm maintainers, me, you, etc.) normalising package names using "the normalization procedure described in PEP 503" for any purpose other than constructing URL path fragments in python package repository implementations? Because as far as I can see that purpose is all that PEP 503 is talking about when it defines this normalisation. Specifically, normalization is mentioned in PEP 503 in these places:
Now, a shallow reading of that paragraph might conclude that PEP 426 defines this normalisation and that it's a standard thing to do with package names — but PEP 426 does not (see below), and AFAICS the normalisation isn't defined anywhere relevant: it's just a PEP 503 thing defined for the purpose of constructing URL path fragments in a package repo implementation. There's a whole rabbit hole worth diving into, but no mention of normalisation...
What you can find are regexes for package names, but those regexes treat periods and dashes (and underscores, in fact) identically. So I ask again: why is this happening in non-repo-package-URL contexts? It's obviously causing problems all over the place (I'll add this fresh one to the mix, particularly as I hit it myself an hour ago), and I keep seeing PEP 503 referenced as if that justifies it... but it just doesn't. What's going on here? And again, I'm asking this in genuine curiosity and with the assumption I'm missing something. I'm in general a user not a contributor when it comes to these amazing tools, my basic stance is gratitude, and my starting assumption is "smarter people than I know better" — |
@gimbo These are good questions. My absolutely personal perspective:
|
Thanks @AndydeCleyre, that makes a lot of sense. Can I then ask two more questions...?
Thanks! |
It may be that your naming issue is resolved today with the new setuptools release, so I'd give that another try. Yes, setup.cfg is definitely an improvement, and yes, the pyproject.toml spec has come far enough now that IMO there's little reason not to use it, and it will be the best-supported standard for its purpose going forward. That said, there's a reason pip-tools itself uses setup.cfg, but I can't recall what it is. @atugushev can probably remind us. |
Yup, upgrading to v62 of setuptools fixes this issue! |
Excellent! @desaintmartin, I'm inclined to close this issue here, as it seems pip, pip-tools, and setuptools are getting along on this front now. Maybe some of the IDE issues will become resolved if they're using setuptools behind the scenes, and any issues that remain are probably best addressed by the IDE developers. What do you (and the rest of you) think? Feel free to express yourself with emoji reactions and I'll get my emoji interpreter on the case, pronto. Thanks! |
I believe we're still experiencing this issue, even when upgrading both pip and setuptools. With a requirements.in of
Using the command It always generates as
Converting the We're using the latest pip and setuptools version
Maybe I haven't fully understood the desired behaviour, I'm assuming that the packages should remain using the |
Current expectation is to use the normalized form with dashes in our output, and this issue is figuring out if there are any significant problems with that (which could outweigh the simplification benefits). @Amwam are you seeing any problems with this behavior? |
Looks like we're not seeing issues anymore. I think its safe for us to say, upgrading setuptools also solves our problem. |
@AndydeCleyre I just found this thread. Please let me know if I should open an additional issue to continue the discussion. I will comment here in the meantime.
One issue is PyCharm complaining that requirements are not satisfied per @desaintmartin's comment:
I couldn't find a fix or workaround for that currently. Another issue is consistency with the intended use of normalization. Paul Moore (CPython core developer) says the following about using the normalized form in user output (Revisiting distribution name normalization):
pip 22.2.1 lists the packages with dots:
|
@alexpulver wrote:
Just to say: for PyCharm (and I guess other IDEs), this is a problem which goes beyond the situations covered in this issue: it comes up with any package where the project/distribution name differs from the package name. E.g. for wxPython, The PyCharm issue tracker gets a constant stream of issues of this type (e.g. here's the wxPython one, and @AndydeCleyre's earlier comment points to many more) where its internal mapping tracking this stuff needs to be updated. It's annoying. To be clear: I'm not saying there isn't something here for pip-tools to pay attention to (and I like the quote from Paul Moore!) — just that this issue comes up even without dots, dashes, or underscores in project/package names. (I also note that PEP 423 recommends always using the same name for project and package — but that PEP was deferred; a shame, I think, if only for this point. And if that was generally accepted, then converting periods to dashes would obviously be covered by that and maybe we wouldn't be having this conversation... or maybe we still would. 🙂) |
FWIW, if/when we can adapt to use pip's new resolution json report (#1654), I think proper names will come "for free." At least one blocker exists for that: pypa/pip#11316 |
This behavior just tripped us up as well. Specifically:
If I replace "jaraco-classes" with "jaraco.classes" in the pip-compile output file, then license_finder works OK. The pip calls that license_finder is using to resolve the package are here. Should license_finder be using some other way of resolving the package that knows about normalisation? |
I have a
requirements.txt
file with the following:When I run
python -m piptools compile
, the periods in the package name get converted to dashes:I need the periods to stay periods. I have no control over the names of the packages. Some package names may have both periods and dashes, such as
My.More-Complex.Package
, and I don't want that to change tomy-more-complex-package
.Yes, the output file above functions correctly, but we're doing extra parsing on it that's breaking because the periods are now dashes.
Edit:
Per comment below, if the periods are converted to dashes to be consistent with
pip
, then I'd prefer all periods can converted to dashes, including# my.package
to# my-package
in the example above.The text was updated successfully, but these errors were encountered: