-
-
Notifications
You must be signed in to change notification settings - Fork 307
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
Feature request: hatchling should implement the prepare_metadata_for_build_wheel hook #128
Comments
I can do this. Is the |
Per https://www.python.org/dev/peps/pep-0517/#build-wheel:
So, without access to build-time data Therefore, we have three options:
|
You can just build the wheel in that case, the PEP even says that. We even provide a helper that does just that in pypa/build, https://pypa-build.readthedocs.io/en/latest/api.html#build.util.project_wheel_metadata.
This does not make sense, as people should be running
Can you elaborate here? |
Hatch has the concept of build hooks like https://github.com/ofek/hatch-mypyc. Wheels recognize these fields which plugins can use to modify builds. For example, the aforementioned one does this to package compiled files.
That's a really good point. @musicinmybrain Is there a reason why Fedora doesn't do that? |
That's what |
I’m not sure I’m in a position to answer that question clearly, but I’ll try to rough out some context. A modern Fedora RPM spec file for a Python library looks something like: # [… name, description, sources, etc. …]
BuildRequires: python3-devel
%package python3-foo
# […]
%prep
# unpack the tarball
%autosetup -n foo-%{version}
%generate_buildrequires
# -r means generate runtime dependencies, not just build-time, and is the default
%pyproject_buildrequires -r
%build
%pyproject_wheel
%install
%pyproject_install
%pyproject_save_files foo
%check
# run the tests
%files -n python3-foo -f %{pyproject_files} The Generating the runtime dependencies as (RPM-level) build dependencies prevents accidentally creating a package that can’t be installed due to unsatisfied dependencies, and it’s also typically necessary for running any tests. Maybe there’s a way to be more clever in Here is where and how the hook is actually used in Fedora. A workaround to get the metadata I actually need to generate runtime dependencies for BuildRequires: python3dist(tomli)
# […]
%generate_buildrequires
'%{python3}' <<EOF
from tomli import load
def emit(tomlbase, reqtag, getdeps):
with open(f'{tomlbase}.toml', 'rb') as cfgfile:
deps = getdeps(load(cfgfile))
with open(f'requirements.{reqtag}.txt', 'w') as reqfile:
reqfile.writelines(f'{dep}\n' for dep in deps)
emit('pyproject', 'pyproject', lambda cfg: cfg['project']['dependencies'])
EOF
%pyproject_buildrequires -R requirements.pyproject.txt Another workaround would be to simply maintain the list of Mentioning @hroncok, who is the primary author of this machinery in Fedora and who might be interested in this discussion. |
The current situation is that if the prepare metadata for wheel hook is not available, our %pyproject_buildrequires macro cannot do anything wrt runtime requires. This could be changed by falling back to building the wheel instead, but that could lead to surprising results. For instance, the environment variables set during the %build phase are different than during the %generate_buildrequires phase. I'm sure there are semantic expectations about what is done in %generate_buildrequires and building the entire package isn't what RPM devs expected. Technically, it's probably possible. |
I keep pondering whether or not to implement this but it just doesn't make sense to given that build hooks may modify the I think each distribution's machinery should adhere to the PEP. Is that okay? |
@musicinmybrain If you wish to experiment with building the wheel in %generate_buildrequires, open an RFE for pyproject-rpm-macros. I bet it's actually doable somehow. |
Thanks. Currently, there are three packages in Fedora that would benefit: If I’ll go ahead and close this issue. Thanks for considering and investigating it. |
I've opened https://bugzilla.redhat.com/show_bug.cgi?id=2076994 tox 4 now uses hatchling |
From the above I cannot understand the workaround, or otherwise why this was closed... Trying to install
Thanks for any hint! |
Thanks, will try adding also |
Packaging for Fedora Linux, I find that simply having I don’t know much about the NixOS Way of Doing Things, but for distribution packagers in general, if you find yourself needing to build from a GitHub archive instead of a PyPI sdist for some reason (because some upstreams don’t include documentation or tests in the PyPI sdist, for example, although this isn’t an issue for export SETUPTOOLS_SCM_PRETEND_VERSION="${MY_PACKAGE_VERSION}" works for |
In Fedora Linux, the
prepare_metadata_for_build_wheel
hook is used to generate a package’s runtime requirements to use as build-time RPM dependencies, which is helpful for ensuring everything is in place to run the tests. Sincehatchling
does not implement this hook, it’s not possible to do this forhatchling
or for projects that use it as a build backend. The most popular Python build systems (setuptools
,poetry
,flit
,build
, etc.) do support this hook.This is just an inconvenience, and can be worked around by some manual effort or project-specific scripting hacks, but it would be a helpful feature if it’s practical to implement.
The text was updated successfully, but these errors were encountered: