Commit graph

229 commits

Author SHA1 Message Date
Miro Hrončok
0d417402db %python_extras_subpkg: Only %ghost the egg-info/dist-info directory, not the content
That way, accidentally unpackaged files within are reported as errors.

Currently, when %python_extras_subpkg is used, the egg-info/dist-info directory
is packaged as %ghost. When the main package does not have it,
the RPM build would succeed. The extras packages would have the python3dist()
requires and provides, but the main package would not.

By adding %dir after %ghost, we only package the directory
(which is enough for python3-rpm-generators to process it),
but the files in the directory are not included.
When not packaged in the main package, the RPM build fails.

This is a safeguard against packaging mistakes.

The visible difference is that rpm -ql/repoquery -l would only return the metadata directory.
And the RPM build would fail if .egg-info is a file,
which is only possible with Python < 3.12 for packages using distutils (no extras anyway).
2025-10-22 22:44:06 +02:00
Miro Hrončok
9e5c1461f2 %python_extras_subpkg: Add -v option to specify the required version(-release)
This is useful when the extras are built from a different specfile
(e.g. in EPEL for a RHEL base package).
2025-09-09 15:02:10 +02:00
Miro Hrončok
47de23b3c0 %python_wheel_inject_sbom: Don't accidentally alter nested .dist-infos
In python-setuptools-wheel, the macro was confused by
setuptools/_vendor/autocommand-2.2.2.dist-info/RECORD (or other vendored RECORDs)
2025-08-29 13:46:23 +02:00
Miro Hrončok
7d4cb5437d Introduce %python_wheel_inject_sbom
See https://discuss.python.org/t/encoding-origin-in-wheel-and-dist-info-metadata-for-downstream-security-backports/97436
2025-08-27 16:13:40 +02:00
Lumir Balhar
364d99f4e1 import_all_modules: Add error handling for import failures
Continue checking all modules when imports fail and provide detailed
error reporting. Exit with proper status code when failures occur.
2025-08-11 12:56:05 +02:00
Lukáš Zachar
bfd1bc9738 Drop STI and use tmt instead
Resolves: rhbz#2383044
2025-08-04 22:49:08 +00:00
Fedora Release Engineering
066459f836 Rebuilt for https://fedoraproject.org/wiki/Fedora_43_Mass_Rebuild 2025-07-25 10:14:58 +00:00
Íñigo Huguet
5cdc4d85a7 pathfix.py: Don't fail on symbolic links
The script ignores symlinks for obvious reasons. Don't return an error
code in that case, though, as it makes the rpm builds fail if there
are symlinks in /usr/bin and `pathfix.py ... /usr/bin/*` is used
(e.g. via %pyproject_install from pyproject-rpm-macros).
2025-07-21 10:07:51 +02:00
Miro Hrončok
b8a5807572 Deprecate %py3_build, %py3_build_wheel, and %py3_install
...as well as their %py_... counterparts.

https://fedoraproject.org/wiki/Changes/DeprecateSetuppyMacros
2025-06-29 15:36:51 +02:00
Gordon Messmer
6b1cf3771c The "exclude" variable in python_bytecompile is no longer used,
so remove it.

This resolves ShellCheck SC2089 and SC2090 warnings.
2025-06-29 13:32:22 +00:00
Gordon Messmer
a74d2bb5c9 Minor style fixes suggested by ShellCheck. Mostly, these consist
of preferring '[[' to '[' in bash scripts.  Other changes include
quoting unquoted variables, and explicitly specifying bash as the
interpreter for scripts that use features not defined in POSIX sh

Fixes SC2046, SC3001, and SC2292
2025-06-29 13:32:22 +00:00
Karolina Surma
888775f1c5 Switch default Python version to 3.14 2025-06-02 09:22:57 +02:00
Pavlina Moravcova Varekova
4ddd2ea298 Eliminate use of ambiguous logical operators in script conditionals
Prefer '[] && []' to '[ -a ]' and '[] || []' to '[ -o ]' in tests.
-a and -o to mean AND and OR in a [ .. ] test expression is not well
defined, and can cause incorrect results when arguments start with
dashes or contain !. Moreover binary -a and -o are inherently
ambiguous. test(1) man page recommends to use
'test EXPR1 && test EXPR2' or 'test EXPR1 || test EXPR2' instead.

It corrects warnings [SC2166] spotted by covscan.
2025-05-16 21:26:40 -07:00
Tomáš Hrnčiar
a3ba11ea64 Add BuildRoot Policy script to modify the content of .dist-info/INSTALLER file
Fixes: rhbz#2345186
2025-03-24 09:11:31 +01:00
Fedora Release Engineering
2c230bfcac Rebuilt for https://fedoraproject.org/wiki/Fedora_42_Mass_Rebuild 2025-01-18 19:00:07 +00:00
Miro Hrončok
ef26565647 Stop testing Python 2.7 on the CI, we don't have it any more 2024-09-23 17:43:22 +02:00
Fedora Release Engineering
d9e31f7897 Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild 2024-07-19 15:32:23 +00:00
Cristian Le
840a26c515 Add option -a to include BuilArch: noarch
Option -A disables that (the default, does nothing at the moment)

Co-Authored-By: Miro Hrončok <miro@hroncok.cz>
2024-06-25 12:50:16 +02:00
Miro Hrončok
d430201e60 CI tests fix for Python 3.13
We should not unimport pathlib when we use pathlib.
This was always fragile. Choose a module we don't use:

The failure:

    ______________________ test_modules_from_files_are_found _______________________

    tmp_path = PosixPath('/tmp/pytest-of-root/pytest-0/test_modules_from_files_are_fo0')

        def test_modules_from_files_are_found(tmp_path):
            test_file_1 = tmp_path / 'this_is_a_file_in_tmp_path_1.txt'
            test_file_2 = tmp_path / 'this_is_a_file_in_tmp_path_2.txt'
            test_file_3 = tmp_path / 'this_is_a_file_in_tmp_path_3.txt'

            test_file_1.write_text('math\nwave\n')
            test_file_2.write_text('csv\npathlib\n')
            test_file_3.write_text('logging\ncsv\n')

            # Make sure the tested modules are not already in sys.modules
            for m in ('math', 'wave', 'csv', 'pathlib', 'logging'):
                sys.modules.pop(m, None)

    >       modules_main(['-f', str(test_file_1), '-f', str(test_file_2), '-f', str(test_file_3), ])

    test_import_all_modules.py:170:
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    /usr/lib/rpm/redhat/import_all_modules.py:167: in main
        import_modules(modules)
    /usr/lib/rpm/redhat/import_all_modules.py💯 in import_modules
        importlib.import_module(module)
    /usr/lib64/python3.13/importlib/__init__.py:88: in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
    <frozen importlib._bootstrap>:1387: in _gcd_import
        ???
    <frozen importlib._bootstrap>:1360: in _find_and_load
        ???
    <frozen importlib._bootstrap>:1331: in _find_and_load_unlocked
        ???
    <frozen importlib._bootstrap>:935: in _load_unlocked
        ???
    <frozen importlib._bootstrap_external>:1022: in exec_module
        ???
    <frozen importlib._bootstrap>:488: in _call_with_frames_removed
        ???
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

        """Object-oriented filesystem paths.

        This module provides classes to represent abstract paths and concrete
        paths with operations that have semantics appropriate for different
        operating systems.
        """

        from ._abc import *
        from ._local import *

    >   __all__ = (_abc.__all__ +
                   _local.__all__)
    E   NameError: name '_abc' is not defined. Did you forget to import '_abc'?

    /usr/lib64/python3.13/pathlib/__init__.py:11: NameError
    ----------------------------- Captured stderr call -----------------------------
    Check import: math
    Check import: wave
    Check import: csv
    Check import: pathlib
2024-06-25 12:34:11 +02:00
Karolina Surma
a389cc4674 Update main Python to 3.13 2024-06-06 15:52:49 +02:00
Zbigniew Jędrzejewski-Szmek
d211646a5e brp-fix-pyc-reproducibility: use more strict shell style
1. Error out on unset variables.
2. Implement suggestion made by shellcheck: use "||" instead of "-o"" in test.
Shellcheck also suggested -print0 to avoid ambiguity with filenames with
embedded newlines, but instead use '-exec {} +', which doesn't need xargs but
still passes multiple arguments to a single marshalparser invocation.

(Those issues are unlikely to cause problems in the rpm environment, but it's
nice to be shellcheck-clean to use shellcheck during development.)

Co-Authored-By: Benjamin A. Beasley <code@musicinmybrain.net>
2024-03-28 11:58:53 +01:00
Lumir Balhar
2acd7cb9b3 Update bundled compileall2 to version 0.8.0 2024-03-22 11:01:55 +01:00
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
Maxwell G
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
Maxwell G
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
13c1c0c519 CI tests: Assert rpmlint's python-bytecode-inconsistent-mtime is not happening 2022-12-21 12:18:48 +01:00
Miro Hrončok
18ceb6caef CI tests: Build pythontest.spec with and without %clamp_mtime_to_source_date_epoch 2022-12-21 12:18:48 +01:00
Miro Hrončok
cb1dbcc44b Add Python 2.7 support to clamp_source_mtime.py
This script is also invoked with Python 2
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
Karolina Surma
e3494799f8 Test data: use csv which will not be removed from stdlib soon 2022-12-15 14:08:24 +00: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
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
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