Churchyard (talk | contribs) (init) |
Churchyard (talk | contribs) (python 3 only) |
||
Line 4: | Line 4: | ||
== Python Version Support == | == Python Version Support == | ||
In Fedora we have multiple Python runtimes, one for each supported major Python release. At this point that's one for python3.x and one for python2.7 However | In Fedora we have multiple Python runtimes, one for each supported major Python release. At this point that's one for python3.x and one for python2.7 However the python2 stack will be removed from Fedora and is deprecated. Upstream support for the python2 interpreter officially ends in 2020. If a piece of software supports python3, it MUST be packaged for python3. Software using python2 MUST NOT be packaged. | ||
For guidelines on maintaining already existing python2 packages, see the [[Packaging:Python_Appendix|appendix]]. | |||
== Multiple Python Runtimes == | == Multiple Python Runtimes == | ||
For backwards compatibility, <code>/usr/bin/python</code> is a symbolic link to <code>/usr/bin/python2</code> (which itself is a link to <code>/usr/bin/python2.7</code>). | |||
However, packages in Fedora MUST NOT | However, packages in Fedora MUST NOT use <code>/usr/bin/python</code> but instead they MUST call <code>/usr/bin/python3</code> (even if upstream supports both versions). As a result of that <code>/usr/bin/python</code> (as well as <code>/usr/bin/env python</code> and similar) MUST NOT be used in shebang lines or as a dependency of a package. As of Fedora 30, all uses of unversioned python executables in shebang lines will fail the build. | ||
These shebnags MUST be fixed manually. If it is necessary to disable the checks, please see the information in [[Packaging:Guidelines#Shebang_lines]]. | |||
These MUST be fixed manually | |||
All python runtimes have a virtual provide for <code>python(abi) = $MAJOR-$MINOR</code>. For example, the | All python runtimes have a virtual provide for <code>python(abi) = $MAJOR-$MINOR</code>. For example, the Python 3.7 runtime package has: | ||
$ rpm -q --provides python3 |grep -i abi | $ rpm -q --provides python3 |grep -i abi | ||
python(abi) = 3. | python(abi) = 3.7 | ||
python modules using these runtimes should have a corresponding "Requires" line on the python runtime that they are used with. This is done automatically for files below <code>/usr/lib[^/]*/python${PYVER}</code> | python modules using these runtimes should have a corresponding "Requires" line on the python runtime that they are used with. This is done automatically for files below <code>/usr/lib[^/]*/python${PYVER}</code> | ||
Mirroring the policy for regular packages, the Python-version-specific subpackages of your package MUST NOT be removed in a release branch of Fedora. | Mirroring the policy for regular packages, the Python-version-specific subpackages of your package MUST NOT be removed in a release branch of Fedora. | ||
== Naming == | |||
The source package with a Python library MUST be named with the <code>python-</code> prefix. A built package however must include the Python major version in the name, using the <code>python3-</code> prefix. This is accomplished by adding a subpackage. See example bellow. | |||
This rule does not apply to applications. | |||
== Dependencies == | == Dependencies == | ||
Packages building for | Packages building for Python 3 will need <code>BuildRequires: python3-devel</code>. | ||
Packages MUST NOT have dependencies (either build-time or runtime) on packages named with the unversioned <code>python-</code> prefix | Packages MUST NOT have dependencies (either build-time or runtime) on packages named with the unversioned <code>python-</code> prefix. Dependencies on Python packages instead MUST use names beginning with <code>python3-</code>. | ||
== Provides == | == Provides == | ||
Using a fictional module named "example", the subpackage containing the | Using a fictional module named "example", the subpackage containing the python3 version '''must''' provide <code>python3-example</code>. This is of course always the case if the subpackage is named <code>python3-example</code> (as in the examples below). If the subpackage has some other name then then <code>Provides: python3-example</code> must be added explicitly (but see the <code>%python_provide</code> macro below). | ||
=== The %python_provide macro === | === The %python_provide macro === | ||
It is desired that a package with a python module provides <code>Provides: python-example</code>. However, in order to be able to globally redefine if this is provided by the python3 or python2 package without having to alter every python module package when a change in this behavior happens, and to allow the same spec to build for releases with different behavior, a convenient <code>%python_provide</code> macro is provided. When given (as an argument) the name of the current (sub)package, it will evaluate to either the proper <code>Provide:</code> line or nothing at all as appropriate depending on the version. Thus if the package follows the suggested subpackage naming scheme as shown in the below example, placing this macro in the definition of each subpackage will guarantee that the necessary <code>Provide:</code> line appears where it should, and does not appear where it shouldn't. | |||
TODO: We might use this macro to something a bit different. | |||
== Automatic Provides with a standardized name == | == Automatic Provides with a standardized name == | ||
Line 51: | Line 48: | ||
<pre> | <pre> | ||
Provides: | Provides: python3.Ydist(CANONICAL_STANDARDIZED_NAME) | ||
Provides: | Provides: python3dist(CANONICAL_STANDARDIZED_NAME) | ||
</pre> | </pre> | ||
The <code> | The <code>3.Y</code> is the Python version used (usually 3.6 and higher), and between the parentheses is the name of the software in a '''canonical format''' used by Python tools and services such as setuptools, pip and PyPI. The canonical name is obtained by switching the standardized name to lower case and converting all runs of non-alphanumeric characters to single “-” characters. Example: “The $$$ Tree” becomes “the-tree”. | ||
=== Requires and BuildRequires with standardized names === | === Requires and BuildRequires with standardized names === | ||
These Provides tags can be used to list Requires and BuildRequires of a package using the ''standardized names'' (i.e. dist name, name on PyPI) of Python modules. To make it easier, you can use the <code>%{py3_dist}</code> macro that accept one or more parameters: the ''standardized name(s)'' of the desired Python software. It will convert the name(s) to the ''canonical format'' and create the proper <code>python3dist(...)</code> tag(s). | |||
In addition, you can use the %{py_dist_name} macro that simply transforms any ''standardized name'' to the ''canonical format''. | In addition, you can use the %{py_dist_name} macro that simply transforms any ''standardized name'' to the ''canonical format''. | ||
Line 66: | Line 63: | ||
<pre> | <pre> | ||
BuildRequires: %{ | BuildRequires: %{py3_dist PyMySQL} >= 0.7.5 | ||
# => BuildRequires: | # => BuildRequires: python3dist(pymysql) >= 0.7.5 | ||
Requires: %{py3_dist virtualenv pyPEG2} | Requires: %{py3_dist virtualenv pyPEG2} | ||
Line 91: | Line 88: | ||
|- | |- | ||
|__python||/usr/bin/python||Prohibited (see note below) | |__python||/usr/bin/python||Prohibited (see note below) | ||
|- | |- | ||
|__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 | |python_provide|| (Lua script) ||Given a package name, evaluates to either <code>Provides: python-example</code> or nothing at all depending on the Python version. See [[Packaging:Python#The_.25python_provide_macro|here]] for an example. | ||
|- | |- | ||
|python3_sitelib||/usr/lib/python3.X/site-packages||Where pure python3 modules are installed | |python3_sitelib||/usr/lib/python3.X/site-packages||Where pure python3 modules are installed | ||
Line 115: | Line 104: | ||
|- | |- | ||
|python3_version_nodots|| 3X ||Defined in python3-devel. Useful when listing files explicitly in %files section , such as %{python3_sitelib}/foo/*.cpython-%{python3_version_nodots}.pyo | |python3_version_nodots|| 3X ||Defined in python3-devel. Useful when listing files explicitly in %files section , such as %{python3_sitelib}/foo/*.cpython-%{python3_version_nodots}.pyo | ||
|- | |- | ||
|py3_build|| %{__python3} setup.py build ... || Various flags are added, see /usr/lib/rpm/macros.d/macros.python3 for details and similar macros. Define %py_setup_args to pass custom command line arguments to setup.py. | |py3_build|| %{__python3} setup.py build ... || Various flags are added, see /usr/lib/rpm/macros.d/macros.python3 for details and similar macros. Define %py_setup_args to pass custom command line arguments to setup.py. | ||
Line 131: | Line 116: | ||
{{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 point to or use <code>/usr/bin/python</code>. Since <code>/usr/bin/python</code> invocation is prohibited, you MUST NOT use these macros without manually setting <code>%{__python}</code> to either | 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, you MUST NOT use these macros without manually setting <code>%{__python}</code> to either <code>%{__python3}</code>. | ||
}} | }} | ||
During <code>%install</code> or when listing <code>%files</code> you can use the <code> | During <code>%install</code> or when listing <code>%files</code> you can use the <code>python3_sitearch</code> and <code>python3_sitelib</code> macros to specify where the installed modules are to be found. For instance: | ||
<pre> | <pre> | ||
%files | %files | ||
# A pure | # A pure python3 module | ||
%{ | %{python3_sitelib}/foomodule/ | ||
# A compiled python3 extension module | # A compiled python3 extension module | ||
%{python3_sitearch}/ | %{python3_sitearch}/barmodule/ | ||
</pre> | </pre> | ||
Use of the macros has several benefits: | Use of the macros has several benefits: | ||
* It ensures that the packages are installed correctly on multilib architectures. | * 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 <code> | * 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 <code>python3_sitelib</code> moves into <code>%{_datadir}</code>). | ||
== Files to include == | == Files to include == | ||
When packaging python modules, several types of files are included: | When packaging python modules, several types of files are included: | ||
* *.py source files because they are used when generating tracebacks. | * *.py source files because they are used when generating tracebacks. | ||
* *.pyc | * *.pyc byte compiled files (and, if present, the enclosing __pycache__ directory in most cases). | ||
** Python will try to create them at runtime if they don't exist which leads to spurious SELinux AVC denials in the logs. | ** Python will try to create them at runtime if they don't exist which leads to spurious SELinux AVC denials in the logs. | ||
** If the system administrator invokes python with -OO, | ** If the system administrator invokes python with -OO, they will be created with no docstrings. This can break some programs. | ||
* *.egg-info files or directories. If these are generated by the module's build scripts they must be included in the package because they might be needed by other applications and modules at runtime. | * *.egg-info files or directories. If these are generated by the module's build scripts they must be included in the package because they might be needed by other applications and modules at runtime. | ||
Line 164: | Line 145: | ||
== Byte compiling == | == Byte compiling == | ||
Python will automatically try to byte compile files when it runs in order to speed up startup the next time it is run. These files are saved in files with the extension of .pyc (compiled python) | Python will automatically try to byte compile files when it runs in order to speed up startup the next time it is run. These files are saved in files with the extension of .pyc (compiled python). These files will be located inside a directory named <code>__pycache__</code>. | ||
The .pyc | The .pyc files contain byte code that is portable across OSes. If you do not include them in your packages, python will try (and generally fail) to create them when the user runs the program. If the system administrator runs the program, then the files will be successfully written, causing stray .pyc files which will not be removed when the package is removed. To prevent that the byte compiled files need to be compiled and included in the <code>%files</code> section. Normally, byte compilation is done for you by the <code>brp-python-bytecompile</code> script. This script runs after the <code>%install</code> section of the spec file has been processed and byte compiles any .py files that it finds in <code>%{python3_sitelib}</code> or <code>%{python3_sitearch}</code> (this recompilation puts the proper filesystem paths into the modules otherwise tracebacks would include the <code>%{buildroot}</code> in them). | ||
You must include | You must include the .pyc files in your package. If the build process creates a __pycache__ directory in a subdirectory of %{python3_sitearch} or %{python3_sitelib}, you must also include all items in the __pycache__ directory. You MUST NOT include the directories %{python3_sitearch}/__pycache__ or %{python3_sitelib}/__pycache__ because they are already owned by the python3-libs package. | ||
All that you need to do is include the files in the <code>%files</code> section (replacing %{python3_sitelib} with the appropriate macro for your package): | All that you need to do is include the files in the <code>%files</code> section (replacing %{python3_sitelib} with the appropriate macro for your package): | ||
Line 185: | Line 166: | ||
</pre> | </pre> | ||
{{admon/warning|Avoid INSTALLED_FILES|python's distutils has an <code>INSTALLED_FILES</code> feature that lists which files are installed when you run <code>% | {{admon/warning|Avoid INSTALLED_FILES|python's distutils has an <code>INSTALLED_FILES</code> feature that lists which files are installed when you run <code>%py3_install</code>. Do not use it for packaging as that will not list the directories which need to be specified in the <code>%files</code> section as well. Using globs in the <code>%files</code> section is simpler and safer.}} | ||
{{admon/warning|Including egg info|When you run <code>%py3_install</code> in any current Fedora, distutils generates a <code>.egg-info</code> file or directory with metadata about the python module that is installed. These files need to be included as well. (See [[#Packaging_eggs_and_setuptools_concerns|Packaging:Python_Eggs]] )}} | |||
=== Manual byte compilation === | === Manual byte compilation === | ||
For more details on the internals of byte compilation, please see [[Packaging:Python_Appendix#Manual_byte_compilation|the appendix]]. | For more details on the internals of byte compilation, please see [[Packaging:Python_Appendix#Manual_byte_compilation|the appendix]]. | ||
== | == Example Python spec file == | ||
The following is a very simple spec file for a Python module. | |||
The following is a very simple spec file for a module | |||
<pre> | <pre> | ||
Line 234: | Line 190: | ||
BuildArch: noarch | BuildArch: noarch | ||
BuildRequires: | BuildRequires: python3-devel | ||
%description | %description | ||
An python module which provides a convenient example. | An python module which provides a convenient example. | ||
Line 259: | Line 208: | ||
%build | %build | ||
%py3_build | %py3_build | ||
%install | %install | ||
%py3_install | %py3_install | ||
%check | %check | ||
%{__python3} setup.py test | %{__python3} setup.py test | ||
# Note that there is no %%files section for the unversioned python module | # Note that there is no %%files section for the unversioned python module | ||
%files -n python3-%{srcname} | %files -n python3-%{srcname} | ||
%license COPYING | %license COPYING | ||
%doc README.rst | %doc README.rst | ||
%{python3_sitelib}/* | %{python3_sitelib}/%{srcname}/ | ||
%{python3_sitelib}/%{srcname}-*.egg-info/ | |||
%{_bindir}/sample-exec | %{_bindir}/sample-exec | ||
%changelog | %changelog | ||
</pre> | </pre> | ||
== Packaging eggs == | == Packaging eggs == | ||
Line 349: | Line 232: | ||
== Reviewer checklist == | == Reviewer checklist == | ||
The following briefly summarizes the guidelines for reviewers to go over: | The following briefly summarizes the guidelines for reviewers to go over: | ||
* '''Must''': If you build | * '''Must''': If you build a python module you must use the <code>%python_provide</code> macro. | ||
* '''Must''': Python modules must be built from source. They cannot simply drop an egg or whl from upstream into the proper directory. (See [[Packaging:Guidelines#No_inclusion_of_pre-built_binaries_or_libraries| prebuilt binaries Guidelines]] for details) | |||
* '''Must''': Python modules must be built from source. They cannot simply drop an egg from upstream into the proper directory. (See [[Packaging:Guidelines#No_inclusion_of_pre-built_binaries_or_libraries| prebuilt binaries Guidelines]] for details) | |||
* '''Must''': Python modules must not download any dependencies during the build process. | * '''Must''': Python modules must not download any dependencies during the build process. | ||
* '''Must''': When building a compat package, it must install using easy_install -m so it won't conflict with the main package. | * '''Must''': When building a compat package, it must install using easy_install -m so it won't conflict with the main package. |
Revision as of 16:25, 6 September 2018
Python Version Support
In Fedora we have multiple Python runtimes, one for each supported major Python release. At this point that's one for python3.x and one for python2.7 However the python2 stack will be removed from Fedora and is deprecated. Upstream support for the python2 interpreter officially ends in 2020. If a piece of software supports python3, it MUST be packaged for python3. Software using python2 MUST NOT be packaged.
For guidelines on maintaining already existing python2 packages, see the appendix.
Multiple Python Runtimes
For backwards compatibility, /usr/bin/python
is a symbolic link to /usr/bin/python2
(which itself is a link to /usr/bin/python2.7
).
However, packages in Fedora MUST NOT use /usr/bin/python
but instead they MUST call /usr/bin/python3
(even if upstream supports both versions). As a result of that /usr/bin/python
(as well as /usr/bin/env python
and similar) MUST NOT be used in shebang lines or as a dependency of a package. As of Fedora 30, all uses of unversioned python executables in shebang lines will fail the build.
These shebnags MUST be fixed manually. If it is necessary to disable the checks, please see the information in Packaging:Guidelines#Shebang_lines.
All python runtimes have a virtual provide for python(abi) = $MAJOR-$MINOR
. For example, the Python 3.7 runtime package has:
$ rpm -q --provides python3 |grep -i abi python(abi) = 3.7
python modules using these runtimes should have a corresponding "Requires" line on the python runtime that they are used with. This is done automatically for files below /usr/lib[^/]*/python${PYVER}
Mirroring the policy for regular packages, the Python-version-specific subpackages of your package MUST NOT be removed in a release branch of Fedora.
Naming
The source package with a Python library MUST be named with the python-
prefix. A built package however must include the Python major version in the name, using the python3-
prefix. This is accomplished by adding a subpackage. See example bellow.
This rule does not apply to applications.
Dependencies
Packages building for Python 3 will need BuildRequires: python3-devel
.
Packages MUST NOT have dependencies (either build-time or runtime) on packages named with the unversioned python-
prefix. Dependencies on Python packages instead MUST use names beginning with python3-
.
Provides
Using a fictional module named "example", the subpackage containing the python3 version must provide python3-example
. This is of course always the case if the subpackage is named python3-example
(as in the examples below). If the subpackage has some other name then then Provides: python3-example
must be added explicitly (but see the %python_provide
macro below).
The %python_provide macro
It is desired that a package with a python module provides Provides: python-example
. However, in order to be able to globally redefine if this is provided by the python3 or python2 package without having to alter every python module package when a change in this behavior happens, and to allow the same spec to build for releases with different behavior, a convenient %python_provide
macro is provided. When given (as an argument) the name of the current (sub)package, it will evaluate to either the proper Provide:
line or nothing at all as appropriate depending on the version. Thus if the package follows the suggested subpackage naming scheme as shown in the below example, placing this macro in the definition of each subpackage will guarantee that the necessary Provide:
line appears where it should, and does not appear where it shouldn't.
TODO: We might use this macro to something a bit different.
Automatic Provides with a standardized name
When building a Python package, RPM looks for .dist-info
and .egg-info
files or directories in the %files
sections of all packages. If one or more are found, RPM parses them to find the standardized name (i.e. dist name, name on PyPI) of the packaged software, and then automatically creates two Provides:
tags in the following format:
Provides: python3.Ydist(CANONICAL_STANDARDIZED_NAME) Provides: python3dist(CANONICAL_STANDARDIZED_NAME)
The 3.Y
is the Python version used (usually 3.6 and higher), and between the parentheses is the name of the software in a canonical format used by Python tools and services such as setuptools, pip and PyPI. The canonical name is obtained by switching the standardized name to lower case and converting all runs of non-alphanumeric characters to single “-” characters. Example: “The $$$ Tree” becomes “the-tree”.
Requires and BuildRequires with standardized names
These Provides tags can be used to list Requires and BuildRequires of a package using the standardized names (i.e. dist name, name on PyPI) of Python modules. To make it easier, you can use the %{py3_dist}
macro that accept one or more parameters: the standardized name(s) of the desired Python software. It will convert the name(s) to the canonical format and create the proper python3dist(...)
tag(s).
In addition, you can use the %{py_dist_name} macro that simply transforms any standardized name to the canonical format.
For example:
BuildRequires: %{py3_dist PyMySQL} >= 0.7.5 # => BuildRequires: python3dist(pymysql) >= 0.7.5 Requires: %{py3_dist virtualenv pyPEG2} # => Requires: python3dist(virtualenv) python3dist(pypeg2) %{py_dist_name 0-._.-._.-._.-._.-._.-._.-0} # => 0-0
Source Files from PyPI
When packaging software which is available from PyPI, you can make use of the %pypi_source
macro. This macro accepts from zero to three arguments and evaluates to an appropriate URL for the source file on PyPI. The arguments are:
- The name of the PyPI project. Defaults to
%srcname
if defined, or to%pypi_name
if defined, or to%name
(the package name). - The version of the PyPI project. Defaults to
%version
(the package version). - The file extension to use. Defaults to
tar.gz
.
In most cases it is not necessary to specify any arguments.
Macros
The following macros are defined for you in all supported Fedora and EPEL releases:
Macro | Normal Definition | Notes |
---|---|---|
__python | /usr/bin/python | Prohibited (see note below) |
__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 Python version. See here for an example.
|
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) | 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. Useful when listing files explicitly in %files section , such as %{python3_sitelib}/foo/*.cpython-%{python3_version_nodots}.pyo |
py3_build | %{__python3} setup.py build ... | Various flags are added, see /usr/lib/rpm/macros.d/macros.python3 for details and similar macros. Define %py_setup_args to pass custom command line arguments to setup.py. |
py3_install | %{__python3} setup.py install --skip-build ... | |
py_dist_name | (Lua script) | 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. |
pypi_source | (Lua script) | Evaluates to the appropriate URL for the package. See above for more information. |
During %install
or when listing %files
you can use the python3_sitearch
and python3_sitelib
macros to specify where the installed modules are to be found. For instance:
%files # A pure python3 module %{python3_sitelib}/foomodule/ # A compiled python3 extension module %{python3_sitearch}/barmodule/
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
python3_sitelib
moves into%{_datadir}
).
Files to include
When packaging python modules, several types of files are included:
- *.py source files because they are used when generating tracebacks.
- *.pyc byte compiled files (and, if present, the enclosing __pycache__ directory in most cases).
- Python will try to create them at runtime if they don't exist which leads to spurious SELinux AVC denials in the logs.
- If the system administrator invokes python with -OO, they will be created with no docstrings. This can break some programs.
- *.egg-info files or directories. If these are generated by the module's build scripts they must be included in the package because they might be needed by other applications and modules at runtime.
The source files must be included in the same package as the byte compiled versions.
Byte compiling
Python will automatically try to byte compile files when it runs in order to speed up startup the next time it is run. These files are saved in files with the extension of .pyc (compiled python). These files will be located inside a directory named __pycache__
.
The .pyc files contain byte code that is portable across OSes. If you do not include them in your packages, python will try (and generally fail) to create them when the user runs the program. If the system administrator runs the program, then the files will be successfully written, causing stray .pyc files which will not be removed when the package is removed. To prevent that the byte compiled files need to be compiled and included in the %files
section. Normally, byte compilation is done for you by the brp-python-bytecompile
script. This script runs after the %install
section of the spec file has been processed and byte compiles any .py files that it finds in %{python3_sitelib}
or %{python3_sitearch}
(this recompilation puts the proper filesystem paths into the modules otherwise tracebacks would include the %{buildroot}
in them).
You must include the .pyc files in your package. If the build process creates a __pycache__ directory in a subdirectory of %{python3_sitearch} or %{python3_sitelib}, you must also include all items in the __pycache__ directory. You MUST NOT include the directories %{python3_sitearch}/__pycache__ or %{python3_sitelib}/__pycache__ because they are already owned by the python3-libs package.
All that you need to do is include the files in the %files
section (replacing %{python3_sitelib} with the appropriate macro for your package):
%files %{python3_sitelib}/foo/
or, if the python code installs directly into %{python3_sitelib}:
%files %{python3_sitelib}/foo.py %{python3_sitelib}/__pycache__/*
Manual byte compilation
For more details on the internals of byte compilation, please see the appendix.
Example Python spec file
The following is a very simple spec file for a Python module.
%global srcname example Name: python-%{srcname} Version: 1.2.3 Release: 1%{?dist} Summary: An example python module License: MIT URL: https://pypi.python.org/pypi/%{srcname} Source0: %pypi_source BuildArch: noarch BuildRequires: python3-devel %description An python module which provides a convenient example. %package -n python3-%{srcname} Summary: %{summary} %{?python_provide:%python_provide python3-%{srcname}} %description -n python3-%{srcname} An python module which provides a convenient example. %prep %autosetup -n %{srcname}-%{version} %build %py3_build %install %py3_install %check %{__python3} setup.py test # Note that there is no %%files section for the unversioned python module %files -n python3-%{srcname} %license COPYING %doc README.rst %{python3_sitelib}/%{srcname}/ %{python3_sitelib}/%{srcname}-*.egg-info/ %{_bindir}/sample-exec %changelog
Packaging eggs
Please see the Python eggs guidelines for information specific to Python eggs.
Reviewer checklist
The following briefly summarizes the guidelines for reviewers to go over:
- Must: If you build a python module you must use the
%python_provide
macro. - Must: Python modules must be built from source. They cannot simply drop an egg or whl from upstream into the proper directory. (See prebuilt binaries Guidelines for details)
- Must: Python modules must not download any dependencies during the build process.
- Must: When building a compat package, it must install using easy_install -m so it won't conflict with the main package.
- Must: When building multiple versions (for a compat package) one of the packages must contain a default version that is usable via "import MODULE" with no prior setup.
- Should: A package which is used by another package via an egg interface should provide egg info.