Add a section of examples of how to write the %files section to Packaging/Python/Eggs
How to Write %files
Writing the %files section can be a bit tricky due to the fact that distutils in Fedora < 9 did not generate egg-info files. This section let's you know what to look out for and some examples of how to work around the gotchas.
A python package can have up to three different names that show up in the %files
section. For instance, in the python-sqlalchemy package we have:
- Package Name: python-sqlalchemy -- This is the name we give it according to the naming guidelines. This is used when a user installs the package via
yum install python-sqlalchemy
. - Module Name: sqlalchemy -- This is what is used in python's
import
statement. The module is stored in a directory with this name:%{python_sitelib}/sqlalchemy
- Egg Name: SQLAlchemy -- This is the name given to the python module in the setup.py file. The egg info is stored in a normalized form of this (spaces and "-" turned into "_"). For instance:
%{python_sitelib}/SQLAlchemy-0.3.10-py2.5.egg-info
Whether you have to worry about all these names depends on a number of factors.
1. Is setuptools being used (this includes setting this up in the spec file as in [#head-4ac98208bf2f5a13b9cd997c91e2e424f67a7e35 Providing Eggs for non-setuptools packages] )? If so, the egginfo will exist on all versions of Fedora as a directory.
1. Is distutils being used? If so, the egginfo will be present on F9+ as a file and non-existent on F8 or less.
1. Is everything in %{buildroot}%{python_sitelib}
to be included in your package? If so it's easy to wildcard the files you need to install.
1. If you aren't including everything (for instance you might have multiple subpackages that include different modules inside %{buildroot}%{python_sitelib}
or the module you're packaging is a plugin for another module) then you'll have to get more creative to include just what you want.
Let's take the simplest case first. If you are using setuptools or you want to include everything inside of %{python_sitelib}
then you can use a very simple wildcard to get the desired effect:
%files [...] %{python_sitelib}/*
The wildcard catches both the module directory and the egg-info if it exists so it will be the same for Fedora >= 9 and Fedora < 9.
Now let's suppose that you have a module created by distutils that installs into a plugin directory of another package. In this case we don't want to include the plugin directories and we need to do something different for Fedora 9 than for Fedora 8:
%{python_sitelib}/bzrlib/plugins/* %if 0%{?fedora} >= 9 %{python_sitelib}/*.egg-info %endif
This includes only the plugin that resides in the plugins subdirectory and only looks for an egg-info file on Fedora 9 and above.
One more example that's hopefully more complex than anything you have to deal with: Your package contains multiple modules with multiple egg-info files. The main package you generate is python-foobar-1.0 and the subpackage with a second module is python-foobar-baz-1.0. The module name's are foobar and baz. The upstream decided to name the modules !FooBar and !FooBar-Baz in setup.py, therefore the egg-info names are !FooBar-1.0-py[PYTHONVERSION] .egg-info and !FooBar_Baz-1.0-py[PYTHONVERSION] .egg-info:
%files %{python_sitelib}/foobar %if 0%{?fedora} >= 9 %{python_sitelib}/FooBar-*.egg-info %endif %files baz %{python_sitelib}/baz %if 0%{?fedora} >= 9 %{python_sitelib}/FooBar_Baz-*.egg-info %endif
In this case we have to be careful that we only pick up the egg-info files that we're interested in and not ones for other modules. However, we can still wildcard the version and python version to make it easier when we update the package.