Commit Graph

68 Commits

Author SHA1 Message Date
Miro Hrončok
efe31871f8 Make %pyproject_build_lib work with RPM 4.16
Related: rhbz#2208971
2023-05-30 11:25:32 +02:00
Miro Hrončok
a5e7a3cd07 Deprecate the provisional %{pyproject_build_lib} macro
There is no scheduled removal.

See https://lists.fedoraproject.org/archives/list/python-devel@lists.fedoraproject.org/thread/HMLOPAU3RZLXD4BOJHTIPKI3I4U6U7OE/
2023-04-26 23:08:07 +02:00
Miro Hrončok
456903666c Redirect stdout to stderr via Shell
Dependencies are recorded to a text file that is catted at the end.

This should prevent subtle bugs like https://bugzilla.redhat.com/2183519 in the future.
2023-04-17 15:32:26 +02:00
Lumir Balhar
1e37a4d872 Remove .dist-info directory at the end of %pyproject_buildrequires
An incomplete .dist-info directory in $PWD can confuse tests in %check.
For example, virtualenv uses importlib.metadata to load its
entry points and it does not work when it finds a virtualenv...dist-info without them.
2023-03-03 10:02:49 +01:00
Miro Hrončok
a4d05ba2c2 Add pyproject-srpm-macros with a minimal %pyproject_buildrequires macro
pyproject-srpm-macros is intended to be installed in the default buildroot.

That way, no explicit BuildRequires for pyproject-rpm-macros are required,
as long as %pyproject_buildrequires is used in %generate_buildrequires.

When only pyproject-srpm-macros is installed, the minimal implementation of
%pyproject_buildrequires generates a dependency on pyproject-rpm-macros.
When pyproject-rpm-macros is installed, it overrides the implementation
of %pyproject_buildrequires with the full one.

Note that in Fedora, pyproject-rpm-macros is required by python3-devel,
but not in RHEL.
This allows us to keep pyproject-rpm-macros in the RHEL CRB repository.
2023-01-20 21:57:49 +01:00
Miro Hrončok
f21e684a67 Use %py3_test_envvars in %tox when available
The new %py3_test_envvars macro was added
to remove duplication of environment variables used in %check.

We reuse it in %tox to gain support e.g. for PYTEST_XDIST_AUTO_NUM_WORKERS.

However, we keep support for platforms where the macro is not yet available,
not to be forced to backport %py3_test_envvars everywhere right away.

Technically, this should change little, but it sets CFLAGS and LDFLAGS now,
hence a new Y version.
2022-12-15 19:52:09 +01:00
Miro Hrončok
5b7df3cdd7 %pyproject_buildrequires: Support Package information on ELF objects
When extension modules are built in %pyproject_buildrequires,
we need to create the package note file.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2097535

This is tested via python-ldap -- %pyproject_buildrequires -w fails without the fix.

Neither python-markupsafe nor python-mistune can be used as a test
because they only warn when the extension module cannot be built
because they fallback to pure Python.
2022-06-17 11:03:18 +02:00
Benjamin A. Beasley
1996e90259 %pyproject_build_lib: support setuptools 62.1.0 and later 2022-06-16 08:00:09 -04:00
Owen W. Taylor
946c8726cf %pyproject_install: pass %{_prefix} explicitly to pip install
This makes things work for %{_prefix} other than user, when combined
with a change in python-rpm-macros to the definition of python3_sitelib/python3_sitearch.

https://lists.fedoraproject.org/archives/list/python-devel@lists.fedoraproject.org/thread/KEQMMNJ4HTTHSQLK6P4DJJTVPA36SS3W/

Co-Authored-By: Miro Hrončok <miro@hroncok.cz>
2022-06-08 14:11:27 +02:00
Miro Hrončok
07577de8ad Use tomllib from the standard library on Python 3.11+ 2022-06-02 11:34:14 +02:00
Miro Hrončok
40f6765e0e Allow building wheels in %pyproject_buildrequires to support other build backends
The hook is optional, see https://www.python.org/dev/peps/pep-0517/#prepare-metadata-for-build-wheel

> If a build frontend needs this information and the method is not defined,
> it should call build_wheel and look at the resulting metadata directly.

This is not yet automatically detected because the feature is provisional.
Use `%pyproject_buildrequires -w` to opt-in.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2076994
2022-04-29 12:42:37 +02:00
Miro Hrončok
1642d25ee2 %_pyproject_wheeldir is absolute since 29157c19b0 2022-04-29 11:40:15 +02:00
Miro Hrončok
ae639fc020 Prefix paths of intermediate files (such as %{pyproject_files}) with NVRA
Apparently, when you repeatedly run `rpmbuild -ba`, files in %_builddir are not cleaned.
This way, we at least make sure the files are unique between different NVRAs,
so 2 unrelated builds don't share the files between each other.

Keeping files contained in the build subdirectory is the more common way of doing this,
but we cannot technically do that, because we don't know what's it gonna be (before %prep).

Should be backwards compatible, as we only modify underscore-prefixed macros and %{pyproject_files},
where the exact value should not matter to the packagers.
2022-03-22 18:22:11 +01:00
Miro Hrončok
f4bbff36d2 %pyproject_buildrequires: Generate BuildRequires for this package
This package is already installed -- otherwise the macro would not even exist.

However, since python3-devel has started to Require pyproject-rpm-macros,
it is no longer possible to use `repoquery --whatrequires pyproject-rpm-macros`
to get a reliable list of packages that use the macros.

This was, all packages that use %pyproject_buildrequires will BuildRequire the macros explicitly.

(In the future, we could even include a stub version of %pyproject_buildrequires
in pyproject-srpm-macros (always installed in the buildroot),
that only echoes this package,
so packagers would not need to manually BuildRequire anything at all.)
2022-01-25 16:45:49 +01:00
Karolina Surma
c3a20e9a33 Include compressed manpages correctly in the RPM package
Compressed manpages have different extension than those listed in the RECORD file,
so they were not recognized when %%pyproject_save_files '+auto' flag
was provided.
To enable the path recognition, if the manpage extension matches the one
listed in brp-compres, the extension is removed, and an asterisk is now added
to the manpages filenames.
Source: https://docs.fedoraproject.org/en-US/packaging-guidelines/#_manpages
Fixes: https://bugzilla.redhat.com/2033254
2022-01-20 19:57:47 +01:00
Miro Hrončok
8c8afba774 %pyproject_buildrequires: Make -r (include runtime) the default, use -R to opt-out
See the proposal:
https://lists.fedoraproject.org/archives/list/python-devel@lists.fedoraproject.org/thread/2R6NKELTHAWE6PI3CCZBVW5PMGO5VPDG/

 - -N now implies -R
 - the macro still guards against -Nr and now also against -Rr
2022-01-18 17:50:00 +01:00
Miro Hrončok
55905e4681 Define provisional %pyproject_build_lib 2021-12-10 12:40:50 +01:00
Karolina Surma
c1baa534b6 Introduce %%pyproject_check_import
%%pyproject_save_files newly saves also a list of importable modules.
The list is used by %%pyproject_check_import to invoke the import test
on each module name.
%%pyproject_check_import accepts two options:
-t: filter only top-level modules
-e: exclude module names matching the given glob from the import check
2021-10-29 08:40:42 +02:00
Miro Hrončok
8588098b34 Rename %_pyproject_ghost_distinfo and %_pyproject_record to indicate they are private 2021-07-23 10:01:13 +02:00
Miro Hrončok
196bc9049d All supported Fedoras can have dependencies on extras 2021-07-17 15:06:23 +02:00
Tomas Hrnciar
5b1caad68e %pyproject_buildrequires: Fallback to setuptools.build_meta:__legacy__ only if setup.py exists
Fixes: rhbz#1976459
2021-07-17 00:36:57 +02:00
Tomas Hrnciar
d6ad9a778a Generate BuildRequires from file
%pyproject_buildrequires macro now accepts multiple file names to load
additional dependencies from them.

New option -N was added to disable automatical generation of requirements
in case package does not use build system. Option -N cannot be used in
combination with options -r, -e, -t, -x.

Co-authored-by: Miro Hrončok <miro@hroncok.cz>
2021-07-08 13:08:04 +02:00
Miro Hrončok
5470f5688e Avoid leaking %{_pyproject_builddir} to pytest collection
Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1935212

Requires a %pytest change: https://src.fedoraproject.org/rpms/python-rpm-macros/pull-request/102
2021-06-28 14:07:29 +02:00
Miro Hrončok
29157c19b0 Set %_pyproject_wheeldir and %_pyproject_builddir relative to the source tree, not $PWD
This allows users to do:

    %build
    cd somewhere
    %pyproject_wheel
    cd -
    cd somewhere_else
    %pyproject_wheel
    cd -

    %install
    %pyproject_install

Without a need to copy paste the wheels to a common location.

This is in fact a breaking change, I'll make sure to adapt the affected packages in Fedora.
2021-05-27 21:28:01 +02:00
Miro Hrončok
c95238388a Don't leak $TMPDIR outside of pyproject macros
During %install, the BRB scripts might be affected by it
2021-05-27 21:28:01 +02:00
Major Hayden
3309d2d16d Write warning to >&2 instead of /dev/stderr
Writing to /dev/stderr with > or >> does not work properly in a mock chroot.

https://bugzilla.redhat.com/show_bug.cgi?id=1965470
2021-05-27 18:42:37 +00:00
Miro Hrončok
ff396611dd Generate python3dist(setuptools/wheel) BuildRequires directly from the macro
The macro already checks if pyproject.toml exists and echoes the dependency
on python3dist(toml) early. This adds an else branch to echo the default backend.

For projects without pyproject.toml, the number of installation rounds
is reduced. Previously:

 1. (python3-devel +) pip + packaging
 2. setuptools + wheel
 3. ...

Now:

 1. (python3-devel +) pip + packaging + setuptools + wheel
 2. ...

This duplicates the information about the default build backend,
because the script still needs to handle projects with pyproject.toml without
an explicit build backend option.
Hence, the script was not adapted (except a comment).
2021-02-03 12:00:58 +01:00
Miro Hrončok
06b21e1976 Generate python3dist(toml) BuildRequires directly from the macro
The macro checks if pyproject.toml exists and echoes the dependency early.

For projects with pyproject.toml, this saves one installation round.
Previously, the installation steps by %generate_buildrequires were:

 1. (python3-devel +) pip + packaging
 2. toml
 3. parsed dependencies from pyproject.toml
 4. ...

Now they are:

 1. (python3-devel +) pip + packaging + toml
 2. parsed dependencies from pyproject.toml
 3. ...

For projects without pyproject.toml, the number of rounds remains the same:

 1. (python3-devel +) pip + packaging
 2. setuptools + wheel
 3. ...

This is also more consistent:
The Python script now only outputs dependencies of the probed project,
it no longer partially outputs dependencies for itself.
2021-02-03 12:00:58 +01:00
Miro Hrončok
390b9713aa Remove support for Python 3.7 from %pyproject_buildrequires
Fedora 31 is EOL and was the last one with Python 3.7 packages.
EL 8 has Python 3.6 but doesn'T have %generate_buildrequires.
2021-02-03 12:00:58 +01:00
Miro Hrončok
32790fff20 Pass PYTHONDONTWRITEBYTECODE=1 to %tox to avoid packaged PYTEST bytecode 2020-12-04 10:50:58 +01:00
Miro Hrončok
38ef5fb85b Allow multiple -e in %pyproject_buildrequires 2020-11-04 18:35:22 +01:00
Lumir Balhar
c5d2f62b23 Use --verbose and --force when removing RECORD and REQUESTED files 2020-10-01 09:28:21 +02:00
Lumir Balhar
efdfb4727f Automatically remove dist-info/REQUESTED files together with RECORD 2020-10-01 09:28:21 +02:00
Lumir Balhar
8d5b3ac22f Restructure %pyproject_install to remove duplicated for loop 2020-09-25 12:24:50 +00:00
Lumir Balhar
894e21291e Preprocess dist-info/RECORD file in %install and remove it.
According to PEP 627, the RECORD file is optional and
doesn't make sense to keep it for system packages. Moreover,
its absence should indicate to other tools like pip that
they should not touch such packages.

Now, we process content of all RECORD files to one
pyproject-record (JSON) which is then used in
%pyproject_save_files. That way, we can remove the original
files in %pyproject_install and keep their content for
later.

PEP 627: https://www.python.org/dev/peps/pep-0627/#optional-record-file
2020-09-25 12:24:50 +00:00
Miro Hrončok
b4fd1c2e74 Only require toml for projects with pyproject.toml
Pros:

 - projects without pyproject.toml will have 1 less dependency
 - toml will be buildable with pyproject-rpm-macros out of the box
 - easier bootstrap sequence (in theory)

Cons:

 - projects with pyproject.toml will have 1 more %generate_buildrequires round
2020-09-07 09:48:27 +02:00
Miro Hrončok
1e199ca6f4 Make code in $PWD importable from %pyproject_buildrequires
In %pyproject_buildrequires, don't run python with -I but -s.

This allows projects used by the script itself, such as packaging or toml,
to be packaged using the macros, using "self" -- i.e. the code from $PWD.
2020-09-04 21:47:35 +00:00
Tomas Hrnciar
a506123afe Replace pathfix with py3_shebang_fix
%pyproject_install currently has:
`pathfix%{python3_version}.py -pni "%{__python3}" -k%{?py3_shbang_opts: -a%{py3_shbang_opts_nodash}} %{buildroot}%{_bindir}/*`

We should replace it with `%py3_shebang_fix %{buildroot}%{_bindir}/*` which expands to:
~~~~
  if [ -f /usr/bin/pathfix%{python3_version}.py ]; then
    pathfix=/usr/bin/pathfix%{python3_version}.py
  else
    # older versions of Python don't have it and must BR /usr/bin/pathfix.py from python3-devel explicitly
    pathfix=/usr/bin/pathfix.py
  fi
  $pathfix -pni %{__python3} -k%{?py3_shebang_flags:a %py3_shebang_flags}} %{buildroot}%{_bindir}/*
~~~~

Mainly so that we:
 - switch to %py3_shebang_flags
 - have only one place to fix the invocation

Fixes: rhbz#1868347
2020-09-04 18:24:30 +02:00
Miro Hrončok
a613e176e3 Handle Python Extras in %pyproject_buildrequires on Fedora 33+
There is a slight problem when reporting that a dependency with extra is satisfied.
In fact, we only check the "base" dependency.
This can lead to a problem when a dependency is wrongly assumed as present
and the script proceeds to the "next stage" without restarting --
if the next stage tries to use (import) the missing dependency,
the script would crash.

However, that might be a very unlikely set of events and if such case ever happens,
we'll workaround it or fix it.
2020-08-20 15:30:49 +02:00
Lumir Balhar
cb8e334272 Use python -m tox instead of just tox
This way, macros can use whatever Python has tox module available
instead of only the main one which owns /usr/bin/tox.
2020-08-10 12:04:22 +02:00
Lumir Balhar
5561755a00 Make %pyproject_buildrequires more universal
so it can work with any non-main Python version and generate
proper dependencies.
2020-08-10 12:04:22 +02:00
Lumir Balhar
64e45518ef Use versioned pathfixX.Y.py script
so pyproject-rpm-macros can depend on any pythonX.Y-devel package
2020-08-10 12:04:22 +02:00
Tomas Hrnciar
1fc1c18fd9 Removes bindir parameter from script
This parameter is not necessary anymore with +auto argument replacing +bindir.
2020-08-06 15:26:37 +02:00
Miro Hrončok
7e5adc9c02 Fix a copy paste error in %pyproject_extras_subpkg definition
Also, add a comment for unreadable RPM expression.

This is a fixup of cb4e43c670
2020-08-04 15:17:16 +02:00
Miro Hrončok
cb4e43c670 Implement %pyproject_extras_subpkg 2020-07-29 17:40:37 +02:00
Miro Hrončok
37216e779e Set HOSTNAME to prevent tox 3.17+ from a DNS query
Tox calls socket.getfqdn() and that call does a DNS query.
In mock with disabled networking, it takes a minute until that times out.
When a spec file uses %pyproject_buildrequires -t and %tox, it is a 3 minute delay.

Since 3.17, tox does not call socket.getfqdn() when HOSTNAME variable is set to a value:

https://github.com/tox-dev/tox/pull/1616

The value is only used in result log, so setting it to "rpmbuild"
actually makes the logs more reproducible as well.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1856356
when tox is used in %pyproject_buildrequires -t or %tox.
2020-07-15 13:24:40 +02:00
Miro Hrončok
ed5dd772f3 Switch from upstream deprecated pytoml to toml 2020-06-23 11:09:03 +00:00
Tomas Hrnciar
19f84b1f4c Adapt pyproject_install macro to PEP 610
With changes in PEP 610 there is new file direct_url.json created, since it is not useful
for us we prevent it's creation. This commit changes %pyproject_install macro to install wheel using
name instead of path.

This commit also includes new test to check if file direct_url.json wasn't created.

https://discuss.python.org/t/pep-610-usage-guidelines-for-linux-distributions/4012
2020-05-07 13:08:22 +02:00
Miro Hrončok
95ba8376f5 Handle extracting debuginfo from extension modules
Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1806625

Upstream issue for a proper fix https://github.com/pypa/pip/issues/7555

Co-Authored-By: Petr Viktorin <pviktori@redhat.com>
2020-04-16 15:45:48 +02:00
Patrik Kopkan
2800b49530 Add %pyproject_save_files macro
This macro save generates file section to %pyproject_files. It should
simplify %files section and allow to build by some automatic machinery

Supposed use case in Fedora:
    %install
    %pyproject_install
    %pyproject_save_files requests _requests

    %files -n python3-requests -f %{pyproject_files}
    %doc README.rst
    %license LICENSE

Automatic build of arbitrary packages (e.g. in Copr):
    %install
    %pyproject_install
    %pyproject_save_files * +bindir // save all modules with executables

    %files -n python3-requests -f %{pyproject_files}

Co-Authored-By: Miro Hrončok <miro@hroncok.cz>
2020-04-15 16:45:10 +02:00