PythonTips

Install Path

Python's Distutils setup.py script accepts several options for setting the install path. These are:

  • --prefix to set the install path for everything

  • --install-libs to set the install path for libraries only

  • --install-scripts to set the install path for scripts only

  • --install-data to set the install path for data files only

If your setup.py script sets file paths appropriately, then you'll be able to install your Python package in /opt with a few quick changes in the debian/rules file. You can use a prefix to install everything under /opt, such as:

override_dh_auto_install:
        dh_auto_install -- --prefix=/opt/extras.ubuntu.com/myappname/

Or, you can choose specific types of files to install in /opt, with the other install options:

PKGDIR=/opt/extras.ubuntu.com/myappname/
[...]
override_dh_auto_install:
        dh_auto_install -- --install-lib=$(PKGDIR) --install-scripts=$(PKGDIR) --install-data=$(PKGDIR)

You don't have to use all three options together, you could choose just libraries, just scripts, just data, or some other combination of the options.

Example setup.py

For the install options to work, you need to use file paths correctly in setup.py. Specifically, executable scripts should be listed under 'scripts', and any data files like icons should be listed under 'data_files'. You can also use 'data_files' to install the few files that never install under /opt, like the extras-myapp.desktop file, apparmor profiles, and lenses and scopes. Here is one complete working setup.py script as an example.

#
from distutils.core import setup
from DistUtilsExtra.command import *

import glob

setup(name="myapp-packagename",
      version="0.1",
      author="My Name",
      author_email="my.name@example.com",
      url="https://launchpad.net/~myname",
      license="GNU General Public License Version 2 (GPLv2)",
      scripts=['bin/myapp-scriptname'],
      data_files=[
          ('icons', glob.glob('icons/*.png')),
          ('/usr/share/applications', ['extras-myapp-packagename.desktop']),
          ('/etc/apparmor.d', [
              'etc/opt.extras.ubuntu.com.myapp-packagename.myapp-scriptname',
              'etc/opt.extras.ubuntu.com.myapp-packagename.myapp-someotherscript']),
          
      ],
      cmdclass={"build":  build_extra.build_extra, }
)

We strongly encourage you not to include arbitrary code in your setup.py script (and may set policy disallowing it in the future).

AppReviewBoard/Submissions/PythonTips (last edited 2012-05-25 18:17:38 by allison)