Commit Graph

163 Commits

Author SHA1 Message Date
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 77cc1a43a2 Test bytecompilation & hardlinking with 3.8 and 2.7 2021-09-10 17:50:49 +02:00
Petr Viktorin 0044db1e8a Remove unneeded arguments from the python_bytecompile function
- For depth, use sys.getrecursionlimit()
  - the default from bytecompile2
  - we'll get a RecursionError before it's exceeded, anyway
- Set real_libdir locally
2021-09-10 17:50:49 +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
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
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
Ben Burton c487f82ef7 Adapt macros and BRP scripts for %topdir with spaces
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1947416
2021-06-28 11:33:07 +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 2b43f896af Update %python3_pkgversion comment 2021-04-27 16:04:58 +02:00
Miro Hrončok 14e4c04a42 Remove EPEL 7 compatibility macros that were actually not defined at all
The %{? in the comment made the entire block of macros not work.

Since nobody actually used those on Fedora, because they did not exist,
we can safely remove them. No need to document this in the %changelog.
2021-04-27 15:49:21 +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
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 bd4c3de20c Make the spec file parseable when %_sourcedir is not .
This happens e.g. with:

 - rpmlint python-rpm-macros.spec
 - rpmdev-bumpspec python-rpm-macros.spec
2021-04-07 12:48:38 +02:00
Miro Hrončok dcb4422895 Escape a macro in an old %changelog entry 2021-04-07 12:48:38 +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
Kalev Lember 4805d44fa0 BRP Python Bytecompile: Avoid hardcoding /usr/bin prefix for python
Avoid using the full path and instead rely on PATH being correctly set
up to find the executable.

This fixes byte compilation for python2.7 when doing flatpak module
builds where python2.7 can be in either /usr/bin or /app/bin, depending
on how it's compiled.
2021-03-10 21:30:12 +01:00
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