-
Notifications
You must be signed in to change notification settings - Fork 251
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
Add an escape_name()
function
#542
Comments
This comment was marked as resolved.
This comment was marked as resolved.
The runs of symbols is taken care of by |
There's one tiny bit of ambiguity here, PEP 427 escaping doesn't require canonicalizing the name, while PEP 625 does. However, in practice the practical difference between those two statements is whether or not the output is lowercase or not. However, PEP 427 doesn't treat names as case sensitive, so there's no requirement to preserve case so I think it's perfectly fine to do that. Actually, the other practical difference is that PEP 427 normalize leaves I think that's OK, since the name of the function is import re
def escape_filename_segment(segment): # better name?
return re.sub("[^\w\d.]+", "_", segment, re.UNICODE) Since that would work for all cases. If not, does it make sense to add Dunno, I think all of the options are fine, just spelling out the edge cases. |
That was my thinking: only care about a portion of the file when e.g. constructing an sdist file name.
Interesting idea. I just don't know how often people are escaping the entire file at the end versus as they go.
I don't think so? But I don't have a good reason to think otherwise. |
Thinking about this more, maybe it would be better to expand the |
Or if we’re to add an API, I’d propose having something like |
Since PyPI now requires PEP 625 filenames when uploading sdists, such a function (or at least clear documentation of the workaround) would be helpful. |
See #527 for the motivation. Basically
utils.canonicalize_name(name).replace("-", "_")
to match PEP 503 and 427 for project name normalization for sdists and wheels.The text was updated successfully, but these errors were encountered: