Commit Graph

145 Commits

Author SHA1 Message Date
Miro Hrončok
b2f798fc81 %py3_test_envvars: Only set $PYTEST_XDIST_AUTO_NUM_WORKERS if not already set 2024-01-25 20:28:23 +01:00
Fedora Release Engineering
d1c3ea93f8 Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild 2024-01-22 06:41:47 +00:00
5eec3f7602 Fix python macro memoizing to account for changing %__python3
This adds a new `%_python_memoize` macro that caches the values of
various python macros in a lua table based on the current value of
`%__python` / `%__python3`. The Python macros are adjusted to use this
macro for memoization instead of the current approach. This way,  the
macros will return values that apply to the _current_ `%__python3` value
when packagers create multi-python specfiles that toggle the value of
`%python3_pkgversion`.

Relates: https://bugzilla.redhat.com/2209055

Co-Authored-By: Miro Hrončok <miro@hroncok.cz>
2023-12-11 12:32:26 +01:00
Karolina Surma
c765382ec8 Fix the changelog entries 2023-09-06 00:23:13 +02:00
d4a26d93d0
Remove %py3_build_egg and %py3_install_egg macros.
%py3_install_egg is nonfunctional; setuptools removed the easy_install
entrypoint years ago.
%py3_build_egg is technically functional but has been superseded by
newer macros. Calling setup.py directly is deprecated, and
building/installing eggs to begin with is deprecated.

The macros are not used in any Fedora packages and are broken.
It's time to remove them.
2023-09-05 05:42:43 +00:00
Karolina Surma
933da64fe6 Declare the license as an SPDX expression 2023-08-09 11:08:17 +02:00
Fedora Release Engineering
f6368ebcaa Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2023-07-21 13:45:20 +00:00
Tomáš Hrnčiar
3c21a3a258 Python 3.12
https://fedoraproject.org/wiki/Changes/Python3.12
2023-06-13 14:43:51 +02:00
Miro Hrončok
10e0e5309d Don't assume %_smp_mflags only ever contains -jX, use -j%_smp_build_ncpus directly
When we added %_smp_mflags here, Petr Viktorin asked the question:
https://src.fedoraproject.org/rpms/python-rpm-macros/pull-request/154#comment-124613

> I couldn't find docs for %_smp_mflags.
> How much of a guarantee is there that it contains no other flags than -j?

My answer was:

> %_smp_mflags is documented in https://rpm-packaging-guide.github.io/
> and used in many other RPM macros in Fedora and upstream everywhere.
> There is no official guarantee that it will never contain anything else,
> but if it does, I assume multiple things would burn.
> I am willing to take that risk.

Turns out, the world did not burn, but packagers do set %_smp_mflags to -lX,
which does not work with compileall.

Fixes https://bugzilla.redhat.com/2179149
2023-03-16 19:45:39 +01:00
Miro Hrončok
3ca74ad94c Memoize values of macros that execute python to get their value
Macros like %{python3_sitelib} were evaluated at every instance in the spec
(each time, Python was started, sysconfig was imported...).
When there were many instances (40+), it might have taken more than a minute to parse the spec file.

This way, the macros are defined via %global on first usage.
Every repetitive usage reuses the actual value.
2023-01-20 21:55:30 +01:00
Fedora Release Engineering
9a36534a95 Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2023-01-20 17:04:00 +00:00
Miro Hrončok
a3ea23bd5e Bytecompilation: Compile Python files in parallel, according to %_smp_mflags 2022-12-21 12:18:48 +01:00
Miro Hrončok
77912c744d Add a script to clamp source mtimes, invoke it from the bytecompilation BRP/macro
https://fedoraproject.org/wiki/Changes/ReproducibleBuildsClampMtimes
2022-12-21 12:18:48 +01:00
Miro Hrončok
e4baf5ab7e Bytecompilation: Pass --invalidation-mode=timestamp to compileall
(Only on Python 3.7+, where it exists and matters.)

This will replace patch 328 in Python and fix https://bugzilla.redhat.com/2133850
2022-12-19 14:27:49 +01:00
Miro Hrončok
eb7a4fda28 Bytecompilation: Unset $SOURCE_DATE_EPOCH when %clamp_mtime_to_source_date_epoch is not set
https://fedoraproject.org/wiki/Changes/ReproducibleBuildsClampMtimes#Python_bytecode
2022-12-19 14:25:52 +01:00
Miro Hrončok
b647925300 Expose the environment variables used by %pytest via %{py3_test_envvars}
This way, we will be able to reuse them in %tox from pyproject-rpm-macros.
Packagers will be able to use them in their spec files.

See https://lists.fedoraproject.org/archives/list/python-devel@lists.fedoraproject.org/thread/A3QQSHP5OSLIVMCL52AR2GRBRXYQHU6B/
2022-12-14 15:52:40 +01:00
Miro Hrončok
86c391c493 Set PYTEST_XDIST_AUTO_NUM_WORKERS=%{_smp_build_ncpus} from %pytest
pytest-xdist 3+ respects this value when -n auto is used.

See https://lists.fedoraproject.org/archives/list/python-devel@lists.fedoraproject.org/thread/FQUUM3SZLRY3UUQJ355H4IJS2GRGIEVI/
2022-12-14 15:48:39 +01:00
Lumir Balhar
bb334db9f3 Include pathfix.py in this package 2022-10-26 13:22:34 +02:00
Fedora Release Engineering
8847b3750a Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2022-07-22 22:07:20 +00: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
Tomáš Hrnčiar
b8b5cb92da Python 3.11
https://fedoraproject.org/wiki/Changes/Python3.11
2022-06-13 11:23:37 +02:00
Miro Hrončok
d174f03f62 Merge f36 and rawhide
A change was accidentaly merged to f36 only
2022-06-09 13:48:28 +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
Miro Hrončok
9102e29afc Don't use ! ... as a check
See https://lists.fedoraproject.org/archives/list/packaging@lists.fedoraproject.org/thread/TFQGD7CSTD5WVKVT3WDIGF5D6DID5NK6/
2022-04-06 19:08:32 +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
99e7d8694c Explicitly opt-out from Python name-based provides and obsoletes generators
In Koji, python3-rpm-generators are not installed during the build.
However, packagers can have them installed locally, in mock or in Copr.
This way, we make sure the automatic provides (and obsoletes)
do not magically appear only in some environments.

Since python3-rpm-macros actually requires python-rpm-macros,
the requirement is self-satisfied when the automatic provides are generated.
2022-01-31 12:05:30 +01:00
Tomas Orsava
5d7727c2aa Add lua helper functions to make it possible to automatically generate Obsoletes tags 2022-01-20 18:57:25 +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
9eae0ccaf1 Move import_all_modules out of python-srpm-macros
There's no need for it in the default buildroot.
2021-11-02 16:05:11 +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
Lumir Balhar
7b546cae36 Non-existing path in py_reproducible_pyc_path causes build to fail 2021-10-12 15:50:50 +02:00
Miro Hrončok
5b578a851f Set $RPM_BUILD_ROOT in %{python3_...} macros, for alternate sysconfig install scheme
Our Pythons currently patches distutils to install packages to
/usr/lib(64)/pythonX.Y/site-packages when the $RPM_BUILD_ROOT environment
variable is set (and to /usr/local/lib(64)/pythonX.Y/site-packages otherwise).
With the deprecation of distutils [1] we want to change the patch to create
and use a different sysconfig install scheme [2].

However, we have realized that macros defined as %(%{__python3} ...) don't
"see" the environment variables set by rpmbuild because they are expanded earlier
and hence e.g. %{python3_sitelib} evaluates to
/usr/local/lib/python3.X/site-packages -- which is not desired.
To be able to reliably detect an RPM build environment by checking
the presence of the $RPM_BUILD_ROOT environment variable,
we manually set it in the macro definitions.

Since %{buildroot} in not fully populated
(e.g. it can expand literally to
/home/anna/rpmbuild/BUILDROOT/%{NAME}-%{VERSION}-%{RELEASE}.x86_64),
we don't use it here.
The variable simply needs to present in the environment.

See also the analysis of the build failures when this is not done [3].

[1] https://www.python.org/dev/peps/pep-0632/
[2] https://bugs.python.org/issue43976
[3] https://src.fedoraproject.org/rpms/python3.10/pull-request/63#comment-79042
2021-09-17 16:56:20 +02:00
Petr Viktorin
dd8caa5aa3 Use --hardlink-dupes for Python 3.4+ as well 2021-09-10 16:14:28 +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
Fedora Release Engineering
b1488aa40c - Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2021-07-23 09:18:36 +00:00
Miro Hrončok
fd3dc4c5dc Move Python related BuildRoot Policy scripts from redhat-rpm-config to python-srpm-macros
This allows us to maintain our own BuildRoot Policy scripts in an easier way.

This change needs to be coordinated with the removal of the files from redhat-rpm-config.

redhat-rpm-config requires python-srpm-macros, so no change is expected for the packagers.
2021-07-08 12:58:05 +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
bc2b51d6d3 Include brp-python-hardlink in python-srpm-macros since it is no longer in RPM 4.17+
See def9a339d2
2021-06-30 18:13:53 +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
9dff7fbf6a Fix %python_provide when fed python3.10-foo to obsolete python-foo instead of python--foo
This has unlikely broken anything in practice,
no packages in Fedora use %python_provide with major.minor-version-prefixed names.
2021-06-15 16:15:45 +02:00
Petr Viktorin
370b825e45 Add the project's canonical URL 2021-06-03 11:44:21 +02:00
Miro Hrončok
3a654e3bed Python 3.10
https://fedoraproject.org/wiki/Changes/Python3.10
2021-06-01 15:58:40 +02:00
Miro Hrončok
03a1e3ba65 Escape % symbols in macro files comments
This is most likely not neccessary but can prevent serious problems like:

https://bugzilla.redhat.com/show_bug.cgi?id=1953910
2021-04-27 12:36:11 +02:00
Miro Hrončok
cad73c2159 Be more careful when loading the macros from sources
The %{?load:%{SOURCE102}} construct no longer works in RPM 4.17+

Currently, we:

1. Load %{SOURCE102} if it exists.
   This should always be the case when actually building the RPM or SRPM package.

2. Else, load macros.python-srpm if it exists.
   This is the case when something parses the spec from dist-git without setting
   %_sourcedir to the current working directory. E.g. rpmdev-bumpspec does this.

3. Else, don't load anything, get %{__default_python3_version} from the environment.
   This is the case when something parses the spec in isolation.
   Getting the version from sources is impossible, because the sources are missing.
   So we get the installed version instead. Note that this will blow up on Fedora < 33,
   but it already did before.
2021-04-27 11:58:15 +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