-
Notifications
You must be signed in to change notification settings - Fork 249
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
Added an API for working with wheel files #805
base: main
Are you sure you want to change the base?
Conversation
Note to self: remember to take into account older versions of specs (pypa/wheel#440 (comment)) when normalizing/validating wheel names. |
tags: frozenset[Tag] | ||
|
||
@classmethod | ||
def from_filename(cls, fname: str) -> WheelMetadata: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to have the other direction, too? A to_filename
method? Or even just a __str__
that would produce the filename? I had a method like this:
@property
def name_ver(self) -> str:
name = self.metadata.canonical_name.replace("-", "_")
# replace - with _ as a local version separator
version = str(self.metadata.version).replace("-", "_")
return f"{name}-{version}"
@property
def basename(self) -> str:
pyver = ".".join(sorted({t.interpreter for t in self.tags}))
abi = ".".join(sorted({t.abi for t in self.tags}))
arch = ".".join(sorted({t.platform for t in self.tags}))
optbuildver = (
[self.wheel_metadata.build_tag] if self.wheel_metadata.build_tag else []
)
return "-".join([self.name_ver, *optbuildver, pyver, abi, arch])
Edit: ahh, I see the new helper function. But it seems like wrapping it in a method here would be natural. But the functionality is there in make_wheel_filename
.
Why isn't this I guess it supports an empty tuple. Though then it seems BuildTag | None
, by the way?make_wheel_filename
could default to an empty tuple instead of supporting None.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isn't this BuildTag | None, by the way? I guess it supports an empty tuple. Though then it seems make_wheel_filename could default to an empty tuple instead of supporting None.
Can you clarify what you're talking about here?
How would one support |
src/packaging/wheelfile.py
Outdated
msg.add_header(key, value) | ||
|
||
if "Metadata-Version" not in msg: | ||
msg["Metadata-Version"] = "2.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why default to 2.1? 2.3 is the current version, and in general, a default can't be safely updated, so IMO this should be required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't aware; I just copied this from the old code.
Separating the metadata preparation step should cover that use case. No need to jump through unnecessary hoops then. |
What changes would that actually entail? From what I can see, only |
Hello there 👋 I'm the person who had the bright idea to build this jankyness back in the day, and now has to maintain it for the sake of all internal APIs we've built with it in the company I work for :). It would be great to have one method for writing both files and directories. This way, if there's a list of paths to include (e.g. from a configuration file), the code doesn't have to perform the Out of curiosity: what's the reason behind the split between |
Can you elaborate on this? Only
I frankly don't understand what tar files have to do with wheels. |
It is the API user that will have to I would like to do a Since you are already performing that check in
PEP-517 defines two hooks: one for bdists, and one for sdists. I can |
Can you elaborate on your use case? Why can you not use |
Because it will throw a I'm unsure what there is to elaborate further. I feel like I'm wasting everyone's time with a relatively minor point. The code is already making the necessary check in |
I've been asking about your use case and you haven't been answering my question, so I will keep asking until you do. What reason do you have to use the API to write individual files/directories to the wheel? That's what I've been wanting to find out. Are the contents coming from outside the file system? |
:) I thought this was good enough: writing to a wheel based on a list of paths. We are talking about generic mechanic, so I gave a generic use case. This should come down to API design principles, not to whether I'm capable of coming up with examples on the level of specificity you expect, but let me try: A dead-simple build backend that creates wheels by packaging only the paths given by the user, as they are specified inside a list in one of Speaking personally, I don't want to have to care whether each path is a directory/symlink/file. That's all there is to this. Really. I don't need 2 (or, god forbid, 3) methods for this, and I don't want to have to choose between them based on my own path checks - I'd like the API to take care of the checking and choosing what's right for each path.
It's akin to asking "what reason do you have to use the There's no esoteric use case here. It's just a trivial point about the ergonomics of this API. I don't want to bikeshed this any further. |
My point is that if you're unable to come up with any practical use case for making this change, then why should I do it? It's hardly economical for |
I gave you a practical use case. I already use this to help QA folks package their Robot Framework sources into wheels. They do not necessarily have a good understanding of how Python build systems work, so having an explicit list of paths helps a lot.
If the cost of adding one syscall to I don't think it's a good argument. Further, current semantics mean that the code using this API has to perform this check twice: once to figure out which method to use, then, again inside Why not just make that method do both and have one less sharp edge? |
Closes #697.