Commit Graph

43 Commits

Author SHA1 Message Date
Miro Hrončok 4abed5f105 Use the values of %_py3_shebang_s and %_py3_shebang_P in the shebang opts/flags
As proposed in https://src.fedoraproject.org/rpms/python-rpm-macros/pull-request/141#comment-109228
And discussed in:

 - https://lists.fedoraproject.org/archives/list/python-devel@lists.fedoraproject.org/thread/4YD2X7HU5U5DFO3N4FWJLPSKVMKH4VSB/
 - https://lists.fedoraproject.org/archives/list/packaging@lists.fedoraproject.org/thread/4YD2X7HU5U5DFO3N4FWJLPSKVMKH4VSB/
2022-07-19 16:30:33 +02:00
Miro Hrončok 4d31ea8034 https://fedoraproject.org/wiki/Changes/PythonSafePath 2022-07-19 16:30:32 +02:00
Miro Hrončok 4085ef49f2 Define %python3_cache_tag / %python_cache_tag, e.g. cpython-311
When reviewing https://src.fedoraproject.org/rpms/pyproject-rpm-macros/pull-request/291
we have discovered that there is no macronized way to get this part of some paths
and that packagers need to hardcode it as cpython-%{python3_version_nodots}.

This way, we have a standardized macro packagers (and other macros) can use.
2022-07-19 11:42:56 +02:00
Owen W. Taylor 546e9a3544 Support installing to %{_prefix} other than /usr
Pass %{_prefix} to install commands and when determining
the sitelib and sitearch variables.

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 13:03:06 +02:00
Tomas Orsava e250f28d09 %py_provides: Do not generate Obsoletes for names containing parentheses
This mechanism is already implemented in the old %python_provide macro.
2022-02-08 12:39:49 +01:00
Miro Hrončok 5547a87f0b Add eval tests to RHEL %py_provides Obsoletes functionality 2022-01-20 18:57:55 +01:00
Miro Hrončok a8b26546eb Set %__python3 value according to %python3_pkgversion
I.e. when %python3_pkgversion is 3.12, %__python3 is /usr/bin/python3.12

We assume that when packagers pacakge for Python 3.X, they want to change both
%python3_pkgversion and %__python3 value.

Hence instead of copy-pasting this:

    %global python3_pkgversion 3.X
    %global __python3 /usr/bin/python3.X

They just need to do:

    %global python3_pkgversion 3.X

Packagers who want to change the value of %__python3 without touching
%python3_pkgversion can still do it:

    %global __python3 /usr/bin/pypy3

Related to https://bugzilla.redhat.com/1821489
2021-12-08 15:35:51 +01:00
Miro Hrončok 9d81ad40e7 %py(3)_check_import: Process .pth files in site(arch|lib)
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2018551
2021-11-02 16:05:11 +01:00
Karolina Surma 824ef3d4af Fix %%py_shebang_flags handling within %%py_check_import
%%py{3}_check_import now respects the custom setting of %%py{3}_shebang_flags
and invokes Python with the respective values.
If %%py{3}_shebang_flags is undefined or set to no value,
there no flags are passed to Python on invoke.
Resolves: rhbz#2018615
2021-11-02 16:05:09 +01:00
Karolina Surma b20d8aa23a Allow multiline arguments processing for %%py3_check_import
Fixes the regression introduced with the macro reimplementation.
Resolves: rhbz#2018809
2021-11-02 16:03:14 +01:00
Karolina Surma 2d0673afb1 Add new options for %%py{3}_check_import: -f, -t, -e
-f: optionally read a file with module names to test
-t: bool flag - if set, filter only top-level modules
-e: optionally exclude module names matching the given glob (Unix
shell-style wildcards)
Importing all modules may cause bogus failures in some cases,
eg. when the imported code assumes there is an existing graphical window.
Such behaviour may be by design, hence for automatic processing it's
more convinient to - in some cases - check only for top-level modules
or filter out the troublemakers.
2021-10-27 15:57:37 +02:00
Tomas Orsava 9b797df44d Define a new macros %python_wheel_dir and %python_wheel_pkg_prefix 2021-10-20 16:40:57 +02:00
Petr Viktorin 77cc1a43a2 Test bytecompilation & hardlinking with 3.8 and 2.7 2021-09-10 17:50:49 +02:00
Petr Viktorin 37bf640f37 Use --hardlink-dupes in %py_byte_compile and brp-python-bytecompile
(for Python 3.9+)

Resolves: rhbz#1977895
2021-09-10 10:50:01 +02:00
Miro Hrončok 76209d7bf3 Fedora CI eval tests: Make the python3.6 dependency optional
It is not available on RHEL 9, where we would like to be able to run the tests.

See https://bugzilla.redhat.com/show_bug.cgi?id=1984407
2021-08-24 21:35:32 +02:00
Miro Hrončok c2305ea368 Introduce %py3_check_import
With $PATH and $PYTHONPATH set to the %buildroot,
the macro tries to import the given Python 3 module(s).
Useful as a smoke test in %check when ruining tests is not feasible.
Accepts spaces or commas as separators.

Package python-six:

    %check
    %py3_check_import six

    Executing(%check): ...
    ...
    + PATH=...
    + PYTHONPATH=...
    + PYTHONDONTWRITEBYTECODE=1
    + /usr/bin/python3 -c 'import six'
    + RPM_EC=0
    ++ jobs -p
    + exit 0

    %py3_check_import six seven

    ...
    + /usr/bin/python3 -c 'import six, seven'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ModuleNotFoundError: No module named 'seven'

    error: Bad exit status from ... (%check)

    ...
    %py3_check_import five, six, seven

    + /usr/bin/python3 -c 'import five, six, seven'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ModuleNotFoundError: No module named 'five'

    error: Bad exit status from ... (%check)

Package python-packaging:

    %py3_check_import packaging, packaging.markers  packaging.requirements, packaging.tags

    Executing(%check): ...
    ...
    + PATH=...
    + PYTHONPATH=...
    + PYTHONDONTWRITEBYTECODE=1
    + /usr/bin/python3 -c 'import packaging, packaging.markers, packaging.requirements, packaging.tags'
    + RPM_EC=0
    ++ jobs -p
    + exit 0

    %py3_check_import packaging, packaging.markers  packaging.notachance, packaging.tags

    ...
    + /usr/bin/python3 -c 'import packaging, packaging.markers, packaging.notachance, packaging.tags'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ModuleNotFoundError: No module named 'packaging.notachance'

    error: Bad exit status from ... (%check)
2021-07-07 14:46:04 +02:00
Miro Hrončok d905710a8d %pytest: Set $PYTEST_ADDOPTS when %{__pytest_addopts} is defined
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1935212
2021-06-28 11:34:10 +02:00
Miro Hrončok 187e049d6c Document a TESTED_FILES value that currently works 2021-04-08 15:39:13 +02:00
Miro Hrončok 39166a7b4b Tests: Assert single-line macros are single-line 2021-04-08 15:33:22 +02:00
Karolina Surma 9d2fcef337 Use sysconfig.get_path() to define %python_sitelib and %python_sitearch
Distutils which were used to define the macros are deprecated in Python3.10:
https://www.python.org/dev/peps/pep-0632/.
Sysconfig isn't and it works across our Pythons, making it better choice for the task.
2021-04-08 14:57:19 +02:00
Miro Hrončok a44ae31ad0 Allow commas as argument separator for extras names in %python_extras_subpkg
This allows e.g.:

    %global extras cli,ghostwriter,pytz,dateutil,lark,numpy,pandas,pytest,redis,zoneinfo,django
    %{pyproject_extras_subpkg -n python3-hypothesis %{extras}}
    ...
    %pyproject_buildrequires -x %{extras}

(Note that %pyproject_extras_subpkg is a tiny wrapper around %python_extras_subpkg.)
2021-04-07 12:48:38 +02:00
Lumir Balhar bc016cbbc5 Make extras_subpkg description more general
Because extra subpackages actually might contain code.
See for example: https://src.fedoraproject.org/rpms/python-dns/pull-request/9
2021-03-16 13:05:31 +01:00
Miro Hrončok a6382f5b5a Fix %python_extras_subpkg with underscores in extras names
Fixes https://lists.fedoraproject.org/archives/list/packaging@lists.fedoraproject.org/thread/FI6J7JNKIOYGBYIN5UJVWYG24UIIES2U/
2021-02-20 12:52:02 +01:00
Miro Hrončok 230ce7f061 Tests: Amend the comment for TESTED_FILES
Arguably, this is easier.
2021-02-08 12:04:29 +01:00
Miro Hrončok c746b25f28 Automatically word-wrap the description of extras subpackages
This only works for package and extra names less than 79 characters long.
I don't expect many actual packages to exceed this limit.
78 characters should be enough for everybody.

Why 78? 79 is the line-lenght limit from rpmlint.
And we need to put punctuation in there.
2021-02-08 12:04:29 +01:00
Miro Hrončok e5429a7a48 Support defining %py3_shebang_flags to %nil 2020-12-09 11:39:08 +01:00
Miro Hrončok 06987f5024 Add %python3_platform_triplet and %python3_ext_suffix
Also add %python_platform_triplet and %python_ext_suffix.

The CI tests are limited to x86_64 for now.

https://fedoraproject.org/wiki/Changes/Python_Upstream_Architecture_Names
2020-09-16 17:32:39 +02:00
Miro Hrončok a712d455f8 python3-devel is required on the CI for pythontest.spec 2020-09-16 17:32:39 +02:00
Lumir Balhar 0253654076 Use versioned pytest executable in `%pytest` macro for non-main Python stack 2020-09-10 07:51:07 +02:00
Lumir Balhar 431e4380cc Add a test for %py_byte_compile macro 2020-09-07 11:20:40 +02:00
Lumir Balhar 2eb41fe707 Implement an environment variable to run tests with specific macros 2020-07-24 13:16:23 +02:00
Lumir Balhar 1979a78de9 Adapt %py(3)_shebang_fix to use versioned pathfixX.Y.py
Versioned pathfixX.Y.py is available in main as well as in
alternative Pythons so this change enables to build
an alternative Python stack without a dependency on the main
python3-devel.
2020-07-24 13:13:56 +02:00
Lumir Balhar 638f809f4c Make %py3_dist respect %python3_pkgversion
By default, %{py3_dist foo} generates python3dist(foo).
This change makes it respect %python3_pkgversion so when
it is redefined as X.Y, %{py3_dist foo} generates pythonX.Y(foo).
2020-07-21 13:42:58 +02:00
Miro Hrončok 0086612c98 Define %python_platform (as a Python version agnostic option to %python3_platform)
%python2_platform is also defined, for consistency.
2020-07-20 18:13:44 +02:00
Miro Hrončok 69b1b30d53 Make the unversioned %__python macro error
See https://fedoraproject.org/wiki/Changes/PythonMacroError

While doing it, make %python macros more consistent with %python3 macros,
mostly wrt whitespace but also to use python -m pip over plain pip etc.

One significant change is the removal of sleeps from python macros,
this could affect packages that use python macros to build for Python 2
while also using python3 macros to build for Python 3.
In reality, I consider that unlikely. The sleep in python2 macros stays.

The --strip-file-prefix option was already removed from %pyX_install_wheel
but we forgot to remove it from %py_install_wheel.
2020-07-16 18:45:25 +02:00
Miro Hrončok 59abe832d4 Adapt %%py_dist_name to keep square brackets
So %{py3_dist foo[bar]} works as expected.

Add tests.
2020-07-10 15:58:00 +02:00
Miro Hrončok 763d24cc5c Add %python_extras_subpkg
See https://fedoraproject.org/wiki/Changes/PythonExtras
2020-07-09 00:49:15 +02:00
Miro Hrončok 985a80572f Allow to combine %pycached with other macros (e.g. %exclude or %ghost)
Previous implementation allowed for only one argument to be passed to
the %pycached macro, which made it impossible to combine it with other macros.

Current implementation allows to pass other macros as arguments to
%pycached.

Example:

    %pycached %exclude /path/to/foo.py

For macro expansion limitations, the opposite order is not possible.
That is to be documented in the guidelines:
https://pagure.io/packaging-committee/pull-request/986

Added some tests.

Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1838992

Co-authored-by: Marcel Plch <mplch@redhat.com>
2020-06-11 20:51:34 +02:00
Miro Hrončok 72371929c5 Implement %pyX_shebang_fix
See https://lists.fedoraproject.org/archives/list/python-devel@lists.fedoraproject.org/thread/UGCMDDG3S32U7JJK36OEZNHLUVQQRG3M/
2020-05-18 18:58:39 +02:00
Miro Hrončok 4569c61d8d Strip tildes from %version in %pypi_source by default, add tests 2020-05-12 11:05:30 +02:00
Miro Hrončok 0d3f1e6b74 Implement %pytest
See https://lists.fedoraproject.org/archives/list/python-devel@lists.fedoraproject.org/thread/XLPDSH362PJKMJCAYOXNJNV53Y66EF6B/
2020-05-11 19:04:28 +02:00
Miro Hrončok 5f3e4d6300 Change %__default_python3_pkgversion from 38 to 3.8
See https://lists.fedoraproject.org/archives/list/python-devel@lists.fedoraproject.org/message/VIUS7WMQMDX6H2WEIH7TVTMBB6SUHY7E/
2020-05-07 21:47:38 +02:00
Miro Hrončok f5bea8c7b7 Fedora CI: Add eval tests for %python_provide and %py_provides 2020-05-05 13:54:28 +02:00