Commit Graph

29 Commits

Author SHA1 Message Date
Miro Hrončok
5ab7319ece Use tomli for older Pythons, now when RHEL 9 has it 2023-05-31 09:51:54 +02:00
Miro Hrončok
193a077e5b
Use lowercase tox in test case names, as upstream wants it 2023-05-23 19:19:38 +00:00
Miro Hrončok
9d4e88e1a6 Tests: Make them pass with setuptools < 60
This makes the tests work on EL 9 and Fedora 36.

 - Move metadata to setup.cfg in self-referential extras tests
 - Skip tests for pyproject.toml [project] metadata when setuptools < 60
2023-04-27 18:45:43 +02:00
Miro Hrončok
bd7890110c %pyproject_buildrequires: Add support for self-referential extras requirements 2023-04-27 11:18:18 +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
Miro Hrončok
85fc41174d %pyproject_buildrequires: Avoid leaking stdout from subprocesses
When the build backend prints to stdout via non-Python means,
for example when a setup.py script calls a verbose program via os.system(),
the output leaked to stdout of %pyproject_buildrequires was treated as generated BuildRequires.

Fore example, if the setup.py script has:

    rv = os.system('/usr/bin/patch -N -p3 -d build/lib < lib/py-lmdb/env-copy-txn.patch')

(From https://github.com/jnwatson/py-lmdb/blob/py-lmdb_1.0.0/setup.py#L117)

The stdout of /usr/bin/patch leaked to stdout of %pyproject_buildrequires:

    [lmdb-1.0.0]$ /usr/bin/python3 -Bs /usr/lib/rpm/redhat/pyproject_buildrequires.py --python3_pkgversion 3 2>/dev/null
    python3dist(setuptools) >= 40.8
    python3dist(wheel)
    patching file lmdb.h
    patching file mdb.c
    python3dist(wheel)
    patching file lmdb.h
    patching file mdb.c

This resulted in DNF errors like this:

    No matching package to install: 'lmdb.h'
    No matching package to install: 'mdb.c'
    No matching package to install: 'patching'

Moreover, it resulted in bogus BuildRequires that may have existed (e.g. "file").

By replacing the usage of contextlib.redirect_stdout
(which only redirects Python's sys.stdout)
with a custom context manager that captures stdout on file descriptor level
(in addition to Python's sys.stdout),
we avoid this leak.

File descriptor magic heavily inspired by the capfd pytest fixture.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2166888
2023-02-06 21:17:42 +01:00
Miro Hrončok
d06c69a096 Adjust %pyproject_buildrequires tests for tox 4
Fixes: https://bugzilla.redhat.com/2160687
2023-01-14 23:57:52 +01: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
5cffd20919 Make the whitespace identical to c9s to avoid further conflicts 2022-02-02 21:24:10 +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
Gordon Messmer
92802d7afe Sync dependency conversion with upstream pyreq2rpm.
Improve handling of > operator, preventing post-release from satisfying most rpm requirements.
Improve handling of < operator, preventing pre-release from satisfying rpm requirement.
Improve handling of != operator with prefix matching, preventing pre-release from satisfying rpm requirements.
2021-11-03 12:46:16 +01:00
Miro Hrončok
27e23c1e87 %pyproject_buildrequires: Accept installed pre-releases for all requirements
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2014639
2021-10-25 15:02:22 +00:00
Petr Viktorin
aeb21f671f Split requirements.txt parsing to its own module; test & improve it 2021-07-23 10:00:01 +02:00
Miro Hrončok
f8a3343abc %pyproject_buildrequires now fails when it encounters an invalid requirement
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1983053
2021-07-23 10:00:01 +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
Miro Hrončok
ddaf2e9fb2 %pyproject_buildrequires: Support x.* versions
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1981558
2021-07-13 12:23:35 +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
2abcad96dd Don't accidentally treat "~= X.0" requirement as "~= X"
Don't canonicalize the version twice.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1977060
2021-06-29 12:43:13 +02:00
Miro Hrončok
99ed4639da Generate BuildRequires on extras in lower case 2021-04-07 16:25:06 +02:00
Miro Hrončok
7e1a8fd079 Handle tox provision (tox.requires / tox.minversion) 2021-04-07 16:01:33 +02: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
38ef5fb85b Allow multiple -e in %pyproject_buildrequires 2020-11-04 18:35:22 +01:00
Miro Hrončok
2ecbed7441 Support multiple -x options for %pyproject_buildrequires
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1877978
2020-10-01 16:35:07 +02:00
Miro Hrončok
9f3eea2ae5 Support the extras configuration option of tox in %pyproject_buildrequires -t
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1877977
2020-10-01 16:33:58 +02:00
Gordon Messmer
cb38f210d2 Support more Python version specifiers in generated BuildRequires
This change introduces code from pyreq2rpm, a tested set of
requirement conversion functions used in pyp2rpm and rpm's
pythondistdeps.

This adds support for the '~=' operator and wildcards.
2020-09-12 01:09:48 +02: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
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
Miro Hrončok
6a8d86ed70 Allow multiple, comma-separated extras in %pyproject_buildrequires -x 2020-08-11 15:54:42 +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