Hello Pythonistas,
the pyproject-rpm-macros-0-51 update (available in Rawhide+ELN and updates ready for 33 and 34) introduces a new provisional %{pyproject_build_lib} macro.

The intended use case will remain the same, but it might yet change its behavior slightly. Here is the snippet from pyproject-rpm-macros README, better viewed at https://src.fedoraproject.org/rpms/pyproject-rpm-macros/blob/rawhide/f/README.md


PROVISIONAL: Importing just-built (extension) modules in %build
---------------------------------------------------------------

Sometimes, it is desired to be able to import the *just-built* extension modules
in the `%build` section, e.g. to build the documentation with Sphinx.

    %build
    %pyproject_wheel
    ... build the docs here ...

With pure Python packages, it might be possible to set `PYTHONPATH=${PWD}` or `PYTHONPATH=${PWD}/src`.
However, it is a bit more complicated with extension modules.

The location of just-built modules might differ depending on Python version, architecture, pip version.
Hence, the macro `%{pyproject_build_lib}` exists to be used like this:

    %build
    %pyproject_wheel
    PYTHONPATH=%{pyproject_build_lib} ... build the docs here ...

This macro is currently **provisional** and the behavior might change.

The `%{pyproject_build_lib}` macro expands to an Shell `$(...)` expression and does not work when put into single quotes (`'`).

Depending on the pip version, the expanded value will differ:


### New pip 21.3+ with in-tree-build (Fedora 36+)

Always use the macro from the same directory where you called `%pyproject_wheel` from.
The value will expand to something like:

* `/builddir/build/BUILD/%{name}-%{version}/build/lib.linux-x86_64-3.10` for wheels with extension modules
* `/builddir/build/BUILD/%{name}-%{version}/build/lib` for pure Python wheels

If multiple wheels were built from the same directory,
some pure Python and some with extension modules,
the expanded value will be combined with `:`:

* `/builddir/build/BUILD/%{name}-%{version}/build/lib.linux-x86_64-3.10:/builddir/build/BUILD/%{name}-%{version}/build/lib`

If multiple wheels were built from different directories,
the value will differ depending on the current directory.


### Older pip with out-of-tree-build (Fedora 34, 35, and EL 9)

The value will expand to something like:

* `/builddir/build/BUILD/%{name}-%{version}/.pyproject-builddir/pip-req-build-xxxxxxxx/build/lib.linux-x86_64-3.10` for wheels with extension modules * `/builddir/build/BUILD/%{name}-%{version}/.pyproject-builddir/pip-req-build-xxxxxxxx/build/lib` for pure Python wheels

Note that the exact value is **not stable** between builds
(the `xxxxxxxx` part is randomly generated,
neither you should consider the `.pyproject-builddir` directory to remain 
stable).

If multiple wheels are built,
the expanded value will always be combined with `:` regardless of the current directory, e.g.:

* `/builddir/build/BUILD/%{name}-%{version}/.pyproject-builddir/pip-req-build-xxxxxxxx/build/lib.linux-x86_64-3.10:/builddir/build/BUILD/%{name}-%{version}/.pyproject-builddir/pip-req-build-yyyyyyyy/build/lib.linux-x86_64-3.10:/builddir/build/BUILD/%{name}-%{version}/.pyproject-builddir/pip-req-build-zzzzzzzz/build/lib`

**Note:** If you manage to build some wheels with in-tree-build and some with out-of-tree-build option,
the expanded value will contain all relevant directories.

--
Miro Hrončok
--
Phone: +420777974800
IRC: mhroncok
_______________________________________________
python-devel mailing list -- python-devel@lists.fedoraproject.org
To unsubscribe send an email to python-devel-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/python-devel@lists.fedoraproject.org
Do not reply to spam on the list, report it: 
https://pagure.io/fedora-infrastructure

Reply via email to