-
Notifications
You must be signed in to change notification settings - Fork 122
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
Listing filenames of produced distributions in the CLI #198
Comments
IMO this is out of scope. Maybe if this information wasn't in the file name I would agree on having a manifest with extra information. I think it is fairly simple to write a Python module that just parses the wheel name and output json or something like that. import argparse
import json
import os.path
import re
from typing import Any, Dict, Optional
_WHEEL_NAME_REGEX = re.compile(
r'(?P<distribution>.+)-(?P<version>.+)'
r'(-(?P<build_tag>.+))?-(?P<python_tag>.+)'
r'-(?P<abi_tag>.+)-(?P<platform_tag>.+).whl'
)
def parse(name: str) -> Optional[Dict[str, str]]:
if m := re.match(_WHEEL_NAME_REGEX, name):
return m.groupdict()
return None
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument(
'file',
type=str,
help='wheel file',
)
args = parser.parse_args()
if info := parse(os.path.basename(args.file)):
print(json.dumps(info, indent=4, sort_keys=True))
else:
print('Inavlid wheel name, see https://www.python.org/dev/peps/pep-0427/#file-name-convention')
|
Perhaps something for https://github.com/pypa/wheel? |
I think you're misunderstanding - I don't want to parse the wheel filename into its constituent tags. I want $ python -m build --write-manifest-to manifest.json
$ python -m install $(jq .wheel manifest.json) |
Hum, I still am not convinced. I would like to keep the CLI fairly simple. As you said
Unless there is a reasonable use-case this would either block or make significantly harder, I am -1. |
I think this could be achieved if we print the generated files on stdout and forward other output to sys.stderr:
Though, in general, I'm tempted not to support this. I can see a valid use case for this in the sense that currently if you want to build a package and then upload it, you need something like:
Because otherwise, dist might contain previous builds you don't want to upload via a simple globbing. I'm solid -1 on the JSON part, but I'm -0.5 on the stderr/stdout part... 🤔 |
But you can simply choose other dist folder. If this was not possible I would agree with this feature, but you can... I think it is trivial to output to another folder if you need to separate things, and then move the files afterward if you want to have everything in the same folder at the end. |
How do you select a folder name that's guaranteed to be empty/not existing without invoking an rm first? |
As I've been working on a project with @gaborbernat I've run into this exact problem as well. The only reason that this works properly today for In a CI job I'm running As best I can tell PEP 517 requires the build backend to return the basename of the thing it built, and |
FWIW if you know the package name in advance, you can do |
Calling pip just to find the names IMHO is the way too heavyweight a solution. |
I was responding to kpfleming’s comment, which was talking about actually installing the built wheels. If you know the project names in advance, you can pass those to pip to install the packages (instead of using path, which needs either glob expansion or knowing the dynamically-generated file names). I made no mention of using pip just to find out the names. pip cannot even do that (without you manually parsing its debug output). |
Okay, I see the need, though I don't think adding a new option for the might be the best solution. So, the usage in this case would be something like:
TLDR: Keep |
I'm personally -1 on this proposal. Would confuse more than help to have to maintain and use two separate entry-points depending on your use case. But considering twine accepts glob expressions I'm personally not too fussed about this at the moment, so I have no strong feelings of a solution, and I feel introducing two entry-points is more confusing/pricey than its benefit... PS. Your proposal is also against UNIX design philosophies, I haven't this duality in other tools, for example, there is not an |
Perhaps this is something that we could roll into #192 - if the output format were to be customisable - say, if
This would mean we've got cook up some kind of JSON schema and we'd need to think about whether this would be more generally useful - would people care about other |
I was going to suggest something similar as well; if Another solution to this would be offer a programmatic API that matches exactly one-to-one to the command line, that either returns or passes to hooks structured data containing relevant information. The stdlib |
I think I am okay with going with @uranusjr proposal of a programmatic API, though it is not the cleanest solution for this. It would still be useful on its own. What about a I would really like to keep this separate for the main command for two reasons, 1) it makes the command much simpler, and 2) it becomes easy to separate the command to another package if needed. I would like to keep things simple and fairly modularized given that this is a critical package to bootstrap Python environments, I want to be able to easily drop functionality, especially as runtime requirements, if we run into any issues. |
How about having I like the idea of a programmatic API, though it's a bit of work to document, it would be nice to have (and sometimes cleans up the internals a little).
I don't like this, personally. First, what do you do with If it's only json, then json's pretty easy to handle with stdlib utils, so I don't think it would hurt bootstrapping. |
Sorry to bump an old thread, but here's another use case: generating the name of the Sdist and Wheel files before actually building them (when possible, e.g. when a dynamic |
This can't be done before, as it's up to the build backend to decide the outputs. Build can't know if the build backend is going to produce a pure Python wheel, a compiled wheel, or something in-between (like one that doesn't depend on the Python version but does depend on the OS). |
I've been writing built dist filenames to a JSON file in the dist folder, but that ends up being picked up by twine with |
What I think would work would be a This can't be done with stdout / stderr since the build backend is allowed to write there, and the info is important / useful. |
How would I reproduce this in uv? It doesn't expose a build command. |
When uv is building (like for |
Ah, but that’s for IPC with the build backend. pyproject-hooks works exactly the same way. |
Source distribution and wheel filenames are variable; they encode a variety of information (e.g. platform, Python version, distribution version) which might vary between build invocations. We might want to think about offering a way to retrieve these from the CLI (e.g. through a new option which would create a manifest) for scripts and automation tools to refer to which would provide a minor convenience over globbing.
The text was updated successfully, but these errors were encountered: