From Fedora Project Wiki
(have macros only (original))
(proposed changes to macros)
Line 4: Line 4:
!Macro!!Normal Definition!!Notes
!Macro!!Normal Definition!!Notes
|-
|-
|__python||<code>%{__python2}</code>||Default Python interpreter. Currently links to Python2 interpreter
|__python||/usr/bin/python||Prohibited (see the note bellow this macro list)
|-
|-
|__python2||/usr/bin/python2||Python 2 interpreter.  Also the current default python interpreter
|__python2||/usr/bin/python2||Python 2 interpreter
|-
|-
|__python3||/usr/bin/python3||Python 3 interpreter
|__python3||/usr/bin/python3||Python 3 interpreter
|-
|-
|python_provide|| (Lua script) ||Given a package name, evaluates to either <code>Provides: python-example</code> or nothing at all depending on the version of the system runtime.  See [[Packaging:Python#The_.25python_provide_macro|here]] for an example.
|python_provide|| (Lua script) ||Given a package name, evaluates to either <code>Provides: python-example</code> or nothing at all depending on the version of the system runtime.  See [[Packaging:Python#The_.25python_provide_macro|here]] for an example.
|-
|python_sitelib||<code>%{python2_sitelib}</code>||Where pure python modules are installed for the default Python implementation
|-
|python_sitearch||<code>%{python2_sitearch}</code>||Where python extension modules that are compiled C are installed for the default Python implementation
|-
|-
|py2_dist|| (Lua script) ||Introduced in Fedora 25. Given a standardized name (i.e. dist name, name on PyPI) of Python software, it will convert it to a canonical format, and evaluates to <code>python2dist(CANONICAL_NAME)</code>, which is useful when listing dependencies. See [[Packaging:Python#Automatic_Provides_with_a_standardized_name|above]] for more information.
|py2_dist|| (Lua script) ||Introduced in Fedora 25. Given a standardized name (i.e. dist name, name on PyPI) of Python software, it will convert it to a canonical format, and evaluates to <code>python2dist(CANONICAL_NAME)</code>, which is useful when listing dependencies. See [[Packaging:Python#Automatic_Provides_with_a_standardized_name|above]] for more information.
Line 39: Line 35:


{{admon/note|The generic %{_python} macros|
{{admon/note|The generic %{_python} macros|
The unversioned macros, <code>%{__python}</code>, <code>%{python_sitelib}</code>, and <code>%{python_sitearch}</code> are generic macros that will always point to the default implementation.  You may only use them with applications that need to choose to use the system's default version of python.  (Currently this is the python2 interpreter.)
The unversioned macros, <code>%{__python}</code>, <code>%{python_sitelib}</code>, and <code>%{python_sitearch}</code> are generic macros that point to or use <code>/usr/bin/python</code>Since <code>/usr/bin/python</code> invocation is prohibited and deprecated in RPM build, you shall never use those macros unless you manually set <code>%{__python}</code> to either <code>%{__python2}</code> or <code>%{__python3}</code>.
This is future proofing for the time when things will be switched over to python3 by default instead of python2.
You should use <code>%{__python2}</code>, <code>%{python2_sitelib}</code>, and <code>%{python2_sitearch}</code> to explicitly reference the python2 interpreter instead.
You should use <code>%{__python2}</code>, <code>%{python2_sitelib}</code>, and <code>%{python2_sitearch}</code> to explicitly reference the python2 interpreter instead.
}}
}}

Revision as of 14:49, 23 January 2018

Macros

The following macros are defined for you:

Macro Normal Definition Notes
__python /usr/bin/python Prohibited (see the note bellow this macro list)
__python2 /usr/bin/python2 Python 2 interpreter
__python3 /usr/bin/python3 Python 3 interpreter
python_provide (Lua script) Given a package name, evaluates to either Provides: python-example or nothing at all depending on the version of the system runtime. See here for an example.
py2_dist (Lua script) Introduced in Fedora 25. Given a standardized name (i.e. dist name, name on PyPI) of Python software, it will convert it to a canonical format, and evaluates to python2dist(CANONICAL_NAME), which is useful when listing dependencies. See above for more information.
python2_sitelib /usr/lib/python2.X/site-packages Where pure python2 modules are installed
python2_sitearch /usr/lib64/python2.X/site-packages on x86_64
/usr/lib/python2.X/site-packages on x86
Where python2 extension modules that are compiled C are installed
python3_sitelib /usr/lib/python3.X/site-packages Where pure python3 modules are installed
python3_sitearch /usr/lib64/python3.X/site-packages on x86_64
/usr/lib/python3.X/site-packages on x86
Where python3 extension modules that are compiled C are installed
py3_dist (Lua script) Introduced in Fedora 25. Given a standardized name (i.e. dist name, name on PyPI) of Python software, it will convert it to a canonical format, and evaluates to python3dist(CANONICAL_NAME), which is useful when listing dependencies. See above for more information.
py_byte_compile (script) Defined in python3-devel. See the byte compiling section for usage
python3_version 3.X Defined in python3-devel. Useful when running programs with Python version in filename, such as nosetest-%{python3_version}
python3_version_nodots 3X Defined in python3-devel since Fedora 21 / Python 3.4. Useful when listing files explicitly in %files section , such as %{python3_sitelib}/foo/*.cpython-%{python3_version_nodots}.pyo
py_dist_name (Lua script) Introduced in Fedora 25. Given a standardized name (i.e. dist name, name on PyPI) of Python software, it will convert it to a canonical format. See above for more information.
Note.png
The generic %{_python} macros
The unversioned macros, %{__python}, %{python_sitelib}, and %{python_sitearch} are generic macros that point to or use /usr/bin/python. Since /usr/bin/python invocation is prohibited and deprecated in RPM build, you shall never use those macros unless you manually set %{__python} to either %{__python2} or %{__python3}. You should use %{__python2}, %{python2_sitelib}, and %{python2_sitearch} to explicitly reference the python2 interpreter instead.

During %install or when listing %files you can use the python2_sitearch and python2_sitelib macros to specify where the installed modules are to be found. For instance:

%files
# A pure python2 module
%{python2_sitelib}/foomodule/
# A compiled python2 extension module
%{python2_sitearch}/barmodule/
# A compiled python3 extension module
%{python3_sitearch}/bazmodule/

Use of the macros has several benefits:

  • It ensures that the packages are installed correctly on multilib architectures.
  • Using these macros instead of hardcoding the directory in the specfile ensures your spec remains compatible with the installed python version even if the directory structure changes radically (for instance, if python2_sitelib moves into %{_datadir}).