Commit Graph

185 Commits

Author SHA1 Message Date
Miro Hrončok 1edfea6956 Update comment for python_altnames() to reflect the reality 2021-02-24 13:06:35 +01:00
Miro Hrončok 8a1e9e0953 Set Version: %{__default_python3_version} to remove one place to bump
Since Fedora 33, the package version always == %{__default_python3_version}.
When we update Python to 3.X+1, we update the version and the macro.

When the macro is not updated confusing things happen.
See for example https://bugzilla.redhat.com/show_bug.cgi?id=1931421#c4

We could assert the versions match in %check instead,
but this way a temporary pull request for a new Python version, such as
https://src.fedoraproject.org/rpms/python-rpm-macros/pull-request/50
https://src.fedoraproject.org/rpms/python-rpm-macros/pull-request/84
can be kept rebased via the git forge UI.

Note that the value of %{__default_python3_version} is loaded from sources in
dist git, otherwise it would be defined by the previous build of this package.

As a result, the spec file is no longer parsable on it's own, but IMHO that's OK.
2021-02-24 13:05:56 +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 626168789c Remove python2-rpm-macros
https://fedoraproject.org/wiki/Changes/Disable_Python_2_Dist_RPM_Generators_and_Freeze_Python_2_Macros

This is to be shipped together with an upgrade of python2.7:
The python2.7 RPM package will contain the removed macros instead.

The release is intentionally over-bumped to allow some changes of
python-rpm-macros in lower versions of Fedora without the need to bump
the version-release of python2-rpm-macros obsoleted by python2.7.
2021-02-08 12:11:39 +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
Fedora Release Engineering 5b5cc39d89 - Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild
Signed-off-by: Fedora Release Engineering <releng@fedoraproject.org>
2021-01-27 13:13:29 +00:00
Miro Hrončok e5429a7a48 Support defining %py3_shebang_flags to %nil 2020-12-09 11:39:08 +01:00
Miro Hrončok a27bc6cc24 BRP Python Bytecompile: Also detect Python files in /app/lib/pythonX.Y
This is needed for flatpaks.

Alternatively, we could pass %{_prefix} as an argument to this script,
but that could make things a tad more complicated.

This solution is less general, but more pragmatic.

See https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/thread/4FBBB3C5E63VDNGUJRLLW27LPZ74SEJH/
2020-11-29 17:44:37 +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 0eae1d90da Disable Python hash seed randomization in %py_byte_compile
This change should help with byte-compilation reproducibility: https://bugzilla.redhat.com/show_bug.cgi?id=1686078
2020-07-24 07:35:07 +02:00
Lumir Balhar 71c410dfa9 Disable Python hash seed randomization in brp-python-bytecompile
This change should help with byte-compilation reproducibility: https://bugzilla.redhat.com/show_bug.cgi?id=1686078
2020-07-23 12:37:34 +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
Lumir Balhar b983c2118b New opt-in possibility to fix byte-compilation reproducibility
A new script brp-fix-pyc-reproducibility creates an opt-in way of how to fix
problems with the reproducibility of byte-compiled Python files. The script
uses marshalparser [0] which currently doesn't provide solutions for all issues
but can fix at least problems with reference flags. For more info see
this Bugzilla [1].

If you want to use this new feature, you need to define
`%py_reproducible_pyc_path` to specify a path you want to fix `.pyc`
files in (recursively) and build-require /usr/bin/marshalparser.

if you forget to build-require the parser. The error message is:
```
+ /usr/lib/rpm/redhat/brp-python-bytecompile '' 1 0
Bytecompiling .py files below /builddir/build/BUILDROOT/tldr-0.5-2.fc33.x86_64/usr/lib/python3.9 using /usr/bin/python3.9
+ /usr/lib/rpm/redhat/brp-fix-pyc-reproducibility /builddir/build/BUILDROOT/tldr-0.5-2.fc33.x86_64
ERROR: If %py_reproducible_pyc_path is defined, you have to also BuildRequire: /usr/bin/marshalparser !
error: Bad exit status from /var/tmp/rpm-tmp.UUJr4v (%install)
```

A build fails if the parser is not able to parse any of the `.pyc` files.

And finally, if a build is properly configured it produces fixed `.pyc` files.

Currently, `.pyc` files in the tldr package contain a lot of unused reference flags:
```
$ dnf install -y tldr
$ marshalparser --unused /usr/lib/python3.9/site-packages/__pycache__/tldr.cpython-39.pyc
… long output …
190 - Flag_ref(byte=9610, type='TYPE_SHORT_ASCII_INTERNED', content=b'init', usages=0)
191 - Flag_ref(byte=9633, type='TYPE_SHORT_ASCII_INTERNED', content=b'source', usages=0)
192 - Flag_ref(byte=9651, type='TYPE_SHORT_ASCII_INTERNED', content=b'argv', usages=0)
193 - Flag_ref(byte=9657, type='TYPE_SHORT_ASCII_INTERNED', content=b'print_help', usages=0)
194 - Flag_ref(byte=9669, type='TYPE_SHORT_ASCII_INTERNED', content=b'stderr', usages=0)
195 - Flag_ref(byte=9682, type='TYPE_SHORT_ASCII_INTERNED', content=b'parse_args', usages=0)
196 - Flag_ref(byte=9737, type='TYPE_SHORT_ASCII_INTERNED', content=b'encode', usages=0)
197 - Flag_ref(byte=9782, type='TYPE_SHORT_ASCII_INTERNED', content=b'parser', usages=0)
198 - Flag_ref(byte=9790, type='TYPE_SHORT_ASCII_INTERNED', content=b'options', usages=0)
199 - Flag_ref(byte=9799, type='TYPE_SHORT_ASCII_INTERNED', content=b'rest', usages=0)
200 - Flag_ref(byte=9821, type='TYPE_SHORT_ASCII_INTERNED', content=b'result', usages=0)
202 - Flag_ref(byte=10022, type='TYPE_SHORT_ASCII_INTERNED', content=b'__main__', usages=0)
203 - Flag_ref(byte=10102, type='TYPE_SHORT_ASCII_INTERNED', content=b'argparse', usages=0)
204 - Flag_ref(byte=10433, type='TYPE_SHORT_ASCII_INTERNED', content=b'__name__', usages=0)
205 - Flag_ref(byte=10463, type='TYPE_SHORT_ASCII_INTERNED', content=b'<module>', usages=0)
```

This new feature fixes them:

```
$ marshalparser --unused /usr/lib/python3.9/site-packages/__pycache__/tldr.cpython-39.pyc
<empty output>
```

[0] https://github.com/fedora-python/marshalparser
[1] https://bugzilla.redhat.com/show_bug.cgi?id=1686078
2020-07-21 11:42:54 +00:00
Miro Hrončok 06ee391993 Add --no-index --no-warn-script-location pip options to %pyX_install_wheel
--no-index saves a ~1 minute timeout of pip possibly checking if there is
a newer pip version (in mock with disabled network).

--no-warn-script-location removes a bogus warning that says:

    WARNING: The scripts easy_install and easy_install-3.9 are installed in
    '/builddir/build/BUILDROOT/python-setuptools-49.2.0-1.fc33.x86_64/usr/bin'
    which is not on PATH.
    Consider adding this directory to PATH or, if you prefer to suppress this warning,
    use --no-warn-script-location.
2020-07-20 18:13:49 +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
Lumir Balhar 3a211cc91b Use compileall from stdlib for Python >= 3.9 2020-06-16 13:57:38 +02:00
Lumir Balhar 8e9c3d8bbe Use compileall from stdlib for Python >= 3.9
All enhancements from compileall2 are merged in Python 3.9.
2020-06-16 13:54:43 +02:00
Lumir Balhar 437166cca7 Remove trailing whitespace 2020-06-15 16:20:07 +02:00
Lumir Balhar f77cb3e9dd No more automagic Python bytecompilation (phase 3) 2020-06-15 16:20:05 +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 bae52eafbe Require the exact same version-release of other subpackages of this package
To avoid mock using a local copy of python-srpm-macros from the buildroot cache
and having Python version defined to 3.8 until the cache expires.

Also, other surprises happened in the past, so we stop playing it cool and
actually follow the guidelines here.
2020-05-31 00:28:19 +02:00
Miro Hrončok 5919708f6c https://fedoraproject.org/wiki/Changes/Python3.9
Also switch to PEP 503 based %py_dist_name (see rhbz#1791530)
2020-05-21 17:39:01 +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 76aecd9ad7 Require recent enough SRPM macros from RPM macros, to prevent missing Lua files
%pyhon_provide in python-rpm-macros uses new Lua functions from python-srpm-macros

People have python-srpm-macros pre-installed, and it is not autoupdated,
hence they can have older versions installed and it blows up.
2020-05-06 01:31:46 +02:00
Miro Hrončok 25355e4a16 Reuse python.python_altprovides in %python_provide
This way, the generator won't re-add the same provide again,
keeping rpmlint happy even with the old macro.
2020-05-05 13:54:28 +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
Miro Hrončok 5fe974759a Make %py_provides work repeatedly 2020-05-05 13:54:28 +02:00
Miro Hrončok 8fea79b1ec Implement %py_provides 2020-05-05 13:54:26 +02:00
Miro Hrončok 125134cf84 Add functions to be used in %py_provides and the provides generator 2020-05-05 13:53:46 +02:00
Miro Hrončok a5778bf4f2 Reorganize the spec 2020-05-05 13:53:46 +02:00
Miro Hrončok b314efc5a7 Add common Lua functions, use a Lua function in %python_provide 2020-05-05 13:53:46 +02:00
Tomas Hrnciar daf7d32612 remove direct_url.json file and sed it out from RECORD
With PEP 610 there is created new file direct_url.json since is not
useful for us, it will be removed using py3_install_wheel macro.

See: https://discuss.python.org/t/pep-610-usage-guidelines-for-linux-distributions/4012
2020-05-05 09:18:16 +02:00
Miro Hrončok fed99a0478 Make pythonX-rpm-macros depend on python-rpm-macros
%pyX_(build|install) uses %py_setup from python-rpm-macros

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1827811
2020-04-27 10:40:14 +02:00
Lumir Balhar 15e32a3005 Update of bundled compileall2 module to 0.7.1 (bugfix release) 2020-03-31 14:24:09 +02:00
Miro Hrončok 1b3e731dc6 Brand as "3.8", rework %python_provide
- Hardcode the default Python 3 version in the SRPM macros
- Provide python38-foo for python3-foo and the other way around (future RHEL compatibility)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1812087

    $ rpm --eval '%python_provide python38-setuptools'
    Provides: python-setuptools = %{version}-%{release}
    Provides: python3-setuptools = %{version}-%{release}
    Obsoletes: python-setuptools < %{version}-%{release}

    $ rpm --eval '%python_provide python3-setuptools'
    Provides: python-setuptools = %{version}-%{release}
    Provides: python38-setuptools = %{version}-%{release}
    Obsoletes: python-setuptools < %{version}-%{release}

    $ rpm --eval '%python_provide python39-setuptools'

    $ rpm --define 'python3_pkgversion 39' --eval '%python_provide python%{python3_pkgversion}-setuptools'

To make the implementation of %python_provide easier,
any names starting with "python" or "pypy" are recognized as valid arguments.

Previously, this was an ERROR:

    $ rpm --eval '%python_provide pythonista'
    %python_provide: ERROR: pythonista not recognized.

Now it is a no-op. The behavior was never documented and the change is
backwards compatible for working spec files.
2020-03-25 17:27:06 +01:00
Tomas Orsava 229fd899ac brp-python-bytecompile: Prepare for 2 digit minor versions (e.g. 3.10) 2020-02-14 12:35:17 +00:00
Miro Hrončok 456f3ecffb Update of bundled compileall2 module to 0.7.0
Adds the optional --hardlink-dupes flag for compileall2 for pyc deduplication

This is explained in https://discuss.python.org/t/3014
                 and https://github.com/fedora-python/compileall2/issues/16

This option is not yet used anywhere. That allows us to backport this to all
Fedoras but only use --hardlink-dupes on rawhide first.
2020-02-10 23:58:33 +01:00
Miro Hrončok e9f07b72aa Define %py(2|3)?_shbang_opts_nodash to be used with pathfix.py -a 2020-02-06 10:26:04 +01:00