Commit Graph

129 Commits

Author SHA1 Message Date
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
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
Miro Hrončok
5b8bb42933 %pyproject_save_files: Add a workaround error for spaces and [brackets]
See the added links for details.
We cannot fix this for now,
so we error out early instead of producing a broken filelist.
2021-09-09 15:56:15 +02:00
Miro Hrončok
27cff80a5f %pyproject_save_files: Expand the namespace error message, also display it with / 2021-09-09 15:56:15 +02:00
Tomas Hrnciar
5169e0e340 Automatically detect LICENSE files and mark them with %license macro 2021-07-23 13:30:43 +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
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
Fedora Release Engineering
3406e9332b - Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2021-07-23 04:29:49 +00:00
Miro Hrončok
c3161aefe4 Explicitly require the "basic" Python RPM macros 2021-07-17 15:05:33 +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
Miro Hrončok
d204ac14cd Escape weird paths generated by %pyproject_save_files 2021-07-13 11:29:19 +02:00
Miro Hrončok
299caacb5b Fix typos in %changelog 2021-07-13 01:30:43 +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
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
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
cc5688e49d Include nested __pycache__ directories in %pyproject_save_files 2021-02-07 20:05:47 +01: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
Fedora Release Engineering
59d092e9dd - Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2021-01-27 08:56:41 +00:00
Miro Hrončok
7d98feee23 Update the description of the package to match the new README content
https://bugzilla.redhat.com/show_bug.cgi?id=1914450#c5
2021-01-15 18:47:11 +01:00
Miro Hrončok
d8b6408932 %pyproject_save_files: List all files from RECORD and their %dirs
This is done to avoid troubles with %lang files listed as duplicated.

 1. It gets rid of a warning
 2. It fixes a problem described in:
    http://lists.rpm.org/pipermail/rpm-list/2020-November/002041.html

This is a backwards incompatible change,
packages that rename or remove the installed files after %pyproject_install
might no longer be compatible with %pyproject_save_files.
2021-01-11 15:14:21 +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
Miro Hrončok
290941c5f3 Support PEP 517 list based backend-path
The PEP 517 shows an example backend-path like this:

    [build-system]
    # Defined by PEP 518:
    requires = ["flit"]
    # Defined by this PEP:
    build-backend = "local_backend"
    backend-path = ["backend"]

https://www.python.org/dev/peps/pep-0517/#source-trees

See that backend-path is a list. Our code previously only supported string path.

Obviously a string path is wrong, but we keep it to support projects that have
made the mistake, such as flit-core.

Add a small integration test for both cases.
Note that the new spec files deliberately don't do much, to save CI time.
2020-10-07 08:35:45 +02: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
Lumir Balhar
faa42c8681 Release bump and changelog 2020-10-01 09:28:21 +02: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
3b95c7d66c Check the requirements after installing "requires_for_build_wheel"
If not checked, installing runtime requirements might fail.

When a requirement is specified in setuptools' setup_requires:

    setup(
        ...
        setup_requires=["pytest-runner"],
    )

It is part of the get_requires_for_build_wheel hook output.

When runtime requirements are parsed with setuptools without all setup_requires
present, it tries to get them from the internet (at least on Fedora 33).

By checking the requirements after installing "requires_for_build_wheel",
we make sure all setup_requires are already installed.

When runtime requirements are not installed, this adds an unneeded check,
but the script would end at that point anyway, so there is no real difference.
2020-09-23 11:16:41 +02:00
Miro Hrončok
c4743014ca Changelog dates corrections 2020-09-12 09:53:24 +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
80a2764884 Remove a no longer useful warning for unrecognized files in %pyproject_save_files
The warning is not actionable and with +auto even redundant.
2020-09-07 11:44: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
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
da3d9bc23d Automatically mark language files with %lang macro 2020-09-04 10:39:52 +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
Lumir Balhar
59bc07b713 Release bump and changelog for universal macros 2020-08-10 12:05:45 +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
Tomas Hrnciar
79678f7e72 Replace +bindir argument with +auto to include all unclassified files to
filelist.
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
Fedora Release Engineering
26607dc0db - Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2020-07-28 23:22:27 +00:00
Miro Hrončok
262f6d3bc3 %pyproject_buildrequires -x now implies -r
The usage without -r errored anyway, this way instead of forcing the user to add it,
we do it ourselves.

Machines stealing human's labor, yet again.
2020-07-16 13:38:50 +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
Miro Hrončok
99d952cd6c Tox dependency generator: Handle deps read in from a text file
Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1808601

tox docs: https://tox.readthedocs.io/en/latest/example/basic.html#depending-on-requirements-txt-or-defining-constraints

Relevant tox-current-env issue: https://github.com/fedora-python/tox-current-env/issues/22
2020-03-05 13:44:54 +01:00
Miro Hrončok
dbb90f5dc1 Preserve existing flags in shebangs of Python files in /usr/bin
Use pathfix.py with -k and -a flags

Solves problems like https://bugzilla.redhat.com/show_bug.cgi?id=1335203
2020-02-07 18:35:06 +01:00
Miro Hrončok
6210f94e46 Handle backends with colon, fallback to setuptools.build_meta:__legacy__
Falling back to setuptools.build_meta:__legacy__ is the standard behavior,
not setuptools.build_meta. See PEP 517:

https://www.python.org/dev/peps/pep-0517/

> If the pyproject.toml file is absent, or the build-backend key is missing,
> the source tree is not using this specification, and tools should revert
> to the legacy behaviour of running setup.py (either directly, or by
> implicitly invoking the setuptools.build_meta:__legacy__ backend).

Falling back to setuptools.build_meta had very similar results so far.,
but the behavior might change in the feature.

While working on this, I have uncovered a problem in our code.
It was not able to handle backends with ":". Looking at PEP 517 again:

> build-backend is a string naming a Python object that will be used to
> perform the build. This is formatted following the same module:object syntax
> as a setuptools entry point. For instance, if the string is "flit.api:main",
> this object would be looked up by executing the equivalent of:
>
>    import flit.api
>    backend = flit.api.main
>
> It's also legal to leave out the :object part, e.g.
>
>    build-backend = "flit.api"
>
> which acts like:
>
>    import flit.api
>    backend = flit.api

We now handle such cases properly. Witch the change of the default backend,
we also test a backend with colon in our tests.
2020-02-05 13:31:45 +01:00
Fedora Release Engineering
52b92ea408 - Rebuilt for https://fedoraproject.org/wiki/Fedora_32_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2020-01-30 10:14:51 +00:00
Patrik Kopkan
49a323e46e create directory in $PWD for built wheel
It is little bit more explicit than installing wheels from $PWD.
2019-11-21 13:12:18 +01:00
Anna Khaitovich
8cce1fad47 Remove stray __pycache__ directory from /usr/bin when running %pyproject_install
Solves bz#1739848
2019-11-14 11:40:28 +01:00
Miro Hrončok
d5c3fb3c5a When tox fails, print tox output before failing
Previously, it wasn't possible to see why tox failed:

...
Requirement satisfied: tox-current-env >= 0.0.2
   (installed: tox-current-env 0.0.2)
Traceback (most recent call last):
  File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 269, in main
    generate_requires(
  File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 221, in generate_requires
    generate_tox_requirements(toxenv, requirements)
  File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 184, in generate_tox_requirements
    r = subprocess.run(
  File "/usr/lib64/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['tox', '--print-deps-to-file', '/tmp/tmp96smu4rv', '-qre', 'py38']' returned non-zero exit status 1.

Now it is:

...
Requirement satisfied: tox-current-env >= 0.0.2
   (installed: tox-current-env 0.0.2)
ERROR: tox config file (either pyproject.toml, tox.ini, setup.cfg) not found
Traceback (most recent call last):
  File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 270, in main
    generate_requires(
  File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 222, in generate_requires
    generate_tox_requirements(toxenv, requirements)
  File "/usr/lib/rpm/redhat/pyproject_buildrequires.py", line 193, in generate_tox_requirements
    r.check_returncode()
  File "/usr/lib64/python3.8/subprocess.py", line 444, in check_returncode
    raise CalledProcessError(self.returncode, self.args, self.stdout,
subprocess.CalledProcessError: Command '['tox', '--print-deps-to-file', '/tmp/tmpwp8sffv1', '-qre', 'py38']' returned non-zero exit status 1.

Inspired by https://src.fedoraproject.org/rpms/python-chaospy/pull-request/1#comment-32750
2019-10-25 16:57:01 +02:00
Miro Hrončok
102626373e Move a verbose line of %pyproject_buildrequires from stdout to stderr
The `rm -v` command prints the output to stderr, polluting the generated buildrequires

  $ rm -rfv pytest_harvest.dist-info/
  removed 'pytest_harvest.dist-info/METADATA'
  removed 'pytest_harvest.dist-info/LICENSE'
  removed 'pytest_harvest.dist-info/top_level.txt'
  removed 'pytest_harvest.dist-info/entry_points.txt'
  removed directory 'pytest_harvest.dist-info/'

This can lead to RPM errors:

  error: Dependency tokens must begin with alpha-numeric, '_' or '/': 'pytest_harvest.dist-info/METADATA'

Or bogus dependencies -- the SRPM requires "removed" and "directory".

See https://github.com/rpm-software-management/rpm/pull/889
2019-10-08 13:01:08 +02:00
Petr Viktorin
137aa316c4 Bump release 2019-09-20 10:18:12 +02:00
Petr Viktorin
d262d909f5 Use importlib_metadata rather than pip freeze 2019-09-18 16:16:17 +02:00
Miro Hrončok
fda0a23075 -t means "use tox", -e means "use this toxenv", -e implies -t
Further fixes
2019-08-13 14:42:21 +02:00
Miro Hrončok
ec073171f3 Add %tox macro to invoke tests 2019-07-29 14:42:53 +02:00
Miro Hrončok
8a60635881 Allow to fetch test dependencies from tox 2019-07-26 15:07:11 +02:00
Fedora Release Engineering
6cfe9d4b22 - Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2019-07-26 11:47:03 +00:00
Petr Viktorin
bc156c4460 Generate run-time requirements for tests 2019-07-18 08:59:44 +02:00
Petr Viktorin
204b801da2 Add --without tests bcond 2019-07-18 08:38:42 +02:00
Petr Viktorin
50645e10a3 Refactor and add tests 2019-07-17 15:57:02 +02:00
Miro Hrončok
fdf511644e Add %pyproject_buildrequires 2019-07-05 11:28:55 +02:00
Patrik Kopkan
ff932e5705 Merge #2 Use source names instead of numbers 2019-07-02 12:46:53 +00:00
Miro Hrončok
48b7c9c2bf Add changelog for 253976c and a94281a 2019-07-02 14:02:54 +02:00
Miro Hrončok
286c22ff34 Use source names instead of numbers
Inspired by the redhat-rpm-config package.
2019-07-02 13:42:40 +02:00
Miro Hrončok
a4df3c984a Add rpmlint RC file and URL 2019-07-02 13:06:11 +02:00
Patrik Kopkan
162b0ca345 initial import (#1717389) 2019-07-02 12:41:04 +02:00