Commit Graph

17 Commits

Author SHA1 Message Date
Miro Hrončok cfa45dfdf3 Add a note: Python 3.11+ no longer needs PYTHONHASHSEED=0
Implemented in:  https://github.com/python/cpython/pull/27926

We keep using it thou, because this is Python version agnostic.

Once we drop support for anything older than 3.11, we can remove it.
That'll be around ~2030. Assuming the world still exists by then.
2022-05-12 11:43:00 +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 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
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
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 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
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 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
Tomas Orsava 229fd899ac brp-python-bytecompile: Prepare for 2 digit minor versions (e.g. 3.10) 2020-02-14 12:35:17 +00:00
Lumir Balhar fa7d708e3c Use `-B` flag for Python when using compileall2 to not write pyc files
The Python compileall2 module in /usr/lib/rpm/redhat/
can be executed by various different Python interpreters.
We don't want to write several different `*.pyc` files
to this location - in most cases, that's not possible,
but somebody might run this as root.
2020-01-27 15:32:07 +00:00
Lumir Balhar 8f6bc2fd6c Fix brp-python-bytecompile with the new features from compileall2
Resolves: rhbz#1595265

The problem this change is intended to solve is with how `real_libdir`
is calculated. Let's assume we want to recursively byte-compile all
`*.py` files in
`/builddir/build/BUILDROOT/python-scales-1.0.9-250.fc32.x86_64/usr/lib/python3.8`.
Then, `real_libdir` is this path without `$RPM_BUILD_ROOT` with
the filename at the end which displays in the error message like this:

```
Bytecompiling .py files below /builddir/build/BUILDROOT/python-scales-1.0.9-250.fc32.x86_64/usr/lib/python3.8 using /usr/bin/python3.8
*** Error compiling '/builddir/build/BUILDROOT/python-scales-1.0.9-250.fc32.x86_64/usr/lib/python3.8/site-packages/greplin/bar.py'...
  File "/usr/lib/python3.8/bar.py", line 1
    import sin from math
               ^
SyntaxError: invalid syntax
```

`/usr/lib/python3.8/bar.py` is obviously wrong.

One of the new features of the `compileall2` module (which will
be available in stdlib in Python 3.9) is that the path byte-compiled to
`*.pyc` files is calculated for each file. This means that by using
`-s` and `-p` we can strip `$RPM_BUILD_ROOT` and prepend `/` for each
file individually which will fix the problem.

```
Bytecompiling .py files below /builddir/build/BUILDROOT/python-scales-1.0.9-250.fc32.x86_64/usr/lib/python3.8 using /usr/bin/python3.8
*** Error compiling '/builddir/build/BUILDROOT/python-scales-1.0.9-250.fc32.x86_64/usr/lib/python3.8/site-packages/greplin/bar.py'...
  File "/usr/lib/python3.8/site-packages/greplin/bar.py", line 1
    import sin from math
               ^
SyntaxError: invalid syntax
```

This change has an effect only for Python >= 3.4.
2019-12-02 16:39:32 +01:00
Lumir Balhar e64ffd7f26 Use compileall2 Python module for byte-compilation in brp-python-bytecompile 2019-07-20 08:08:26 +02:00
Miro Hrončok e1bd214d25 Move brp-python-bytecompile from rpm, so we can easily adapt it 2019-07-20 08:07:57 +02:00