Commit Graph

43 Commits

Author SHA1 Message Date
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
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 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
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
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 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
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 e5429a7a48 Support defining %py3_shebang_flags to %nil 2020-12-09 11:39:08 +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
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 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
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 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 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 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 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
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 e9f07b72aa Define %py(2|3)?_shbang_opts_nodash to be used with pathfix.py -a 2020-02-06 10:26:04 +01:00
Anna Khaitovich 2314fd928a Remove stray __pycache__ directory from /usr/bin when running %py_install, %py_install_wheel and %py_install_egg macros
Solves bz#1739848
2019-12-28 19:16:16 +01:00
Miro Hrončok 6c63a5b7f4 Add the %pycached macro
Usage:

  %files
  ...
  %pycached %{python3_sitelib}/foo.py

This will list:

  /usr/lib/python3.8/site-packages/foo.py
  /usr/lib/python3.8/site-packages/__pycache__/foo.cpython-38{,.opt-?}.pyc

Assuming the Python 3 version is 3.8.
The bytecode files are globbed, their presence is not checked.

This will fail:

  %pycached %{python3_sitelib}/foo

error: %pycached can only be used with paths explicitly ending with .py

And so will any of this:

  %pycached %{python3_sitelib}/*
  %pycached %{python3_sitelib}/foo.*
  %pycached %{python3_sitelib}/foo.p?
  %pycached %{python3_sitelib}/foo.?y
  %pycached %{python3_sitelib}/foo.??

But this will work:

  %pycached %{python3_sitelib}/foo*.py

And it will generate the following globs:

  /usr/lib/python3.8/site-packages/foo*.py
  /usr/lib/python3.8/site-packages/__pycache__/foo*.cpython-38{,.opt-?}.pyc

When used with paths that include Python 3 version, it globs with the version:

  %pycached /opt/python3.10/foo.py

Generates:

  /opt/python3.10/foo.py
  /opt/python3.10/__pycache__/foo.cpython-310{,.opt-?}.pyc

While paths without version have less strict globs:

  %pycached /custom/foo.py
  /custom/foo.py
  /custom/__pycache__/foo.cpython-3*{,.opt-?}.pyc

This will generate a warning in RPM build:

warning: File listed twice: /custom/__pycache__/foo.cpython-38.opt-1.pyc

However it ensures the optimized bytecode is there.
2019-12-28 19:12:37 +01:00
Miro Hrončok f09ccd21f5 Drop --strip-file-prefix option from %pyX_install_wheel macros, it is not needed
A custom pip patch was needed for this option, but the RECORD files are
relative, so no stripping is needed. We will eventually drop the patch.
2019-08-26 15:33:41 +00:00
Miro Hrončok 84ed1ab69d Fix %python3_version macros for Python 3.10
No need to bump the release, 3.10 is far from now.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1745601
2019-08-26 15:24:23 +02:00
Petr Viktorin c8932dcbef Move "sleep 1" workaround from py3_build to py2_build
https://bugzilla.redhat.com/show_bug.cgi?id=1644923
2018-11-01 11:06:22 +01:00
Tomas Orsava beaa2eec4f Move the __python2/3 macros to the python-srpm-macros subpackage
This facilitates using the %%{__python2/3} in Build/Requires
2018-09-20 13:36:47 +02:00
Miro Hrončok 1ea9947b6f Add %python3_platform useful for PYTHONPATH on arched builds
This is mostly used when building Sphinx docs on arched build.

Previously:

  PLATFORM=$(python3 -c "import sysconfig; print(sysconfig.get_platform())")
  export PYTHONPATH=../build/lib.${PLATFORM}-%{python3_version}
  make man

Or:

  PYTHONPATH=`realpath ../build/lib.linux*` make

Or:

  PYTHONPATH=$(echo $PWD/build/lib.linux-*) make html

Now:

  PYTHONPATH=../build/lib.%{python3_platform}-%{python3_version}
2018-07-03 14:21:49 +02:00
Jan Pokorný 4904408b2f macros.python*: make LDFLAGS propagated whenever CFLAGS are
This is to ensure the right linker flags get propagated into binaries
accompanying python packages whenever distutils (or similar, env.
variables provided build flags aware) module is delegated to build them
(e.g. https://bugzilla.redhat.com/show_bug.cgi?id=1541106).  Instead of
using "%{__global_ldflags}" as the seed for the respective env. variable
one-off application, which would be a direct parallel to "%{optflags}"
seeding CFLAGS, use rather "${RPM_LD_FLAGS}" and "${RPM_OPT_FLAGS}",
as these are not directly bound to macros out of rpm proper (like
it would have been, e.g., on redhat-rpm-config package otherwise).

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2018-03-23 13:33:48 +01:00
Ville Skyttä 8d3d1dde64 macros.python*: Use -Es/-I to invoke macro scriptlets
To avoid environment and user dir influence.

https://bugzilla.redhat.com/show_bug.cgi?id=1506355
2017-10-26 13:31:35 +03:00
Michal Cyprian a59818afd0 Revert "Switch %%__python3 to /usr/libexec/system-python"
- The Fedora Change https://fedoraproject.org/wiki/Changes/Making_sudo_pip_safe
  was postponed
- This reverts commit d019d2fd4d
2017-03-03 13:52:35 +01:00
Michal Cyprian d019d2fd4d Switch %%__python3 to /usr/libexec/system-python 2017-02-20 13:41:26 +01:00
Michal Cyprian d0fdb0d759 Add --no-deps option to py_install_wheel macros 2017-01-23 18:52:17 +01:00
Orion Poplawski 5ca1f525e5 Make expaned macros start on the same line as the macro 2016-11-24 07:53:47 -07:00
Orion Poplawski a73eb24716 Fix %py3_install_wheel (bug #1395953) 2016-11-16 21:32:46 -07:00
Orion Poplawski e7af332922 Add missing sleeps to other build macros
- Fix build_egg macros
- Add %py_build_wheel and %py_install_wheel macros
2016-11-16 16:28:31 -07:00
Orion Poplawski f798c43354 Add %py_build_egg and %py_install_egg macros 2016-11-15 16:23:27 -07:00
Orion Poplawski 6ce524f21d Allow multiple args to %py_build/install macros 2016-11-15 16:18:39 -07:00
Orion Poplawski 29e6636ccd Tidy up macro formatting 2016-11-15 16:16:16 -07:00
Jason Tibbitts af37c22835 Add single-second sleeps to work around setuptools bug. 2016-05-12 13:28:05 -05:00
Orion Poplawski ec28c775cd Initial import 2016-01-12 16:52:28 -07:00