Search code examples
pythonnamespacesdebianpackagedeb

debhelper with python doesn't deploy namespaced packages


I'm updating a python package which is deployed via a private deb repo to use a namespaced name. (I've changed the specifics to make it generic)

The old names are:

  • old python package name: useful_thing
  • old python distribution name: myproject_useful_thing
  • old debian name: python-myproject-useful-thing

I've changed the naming thus:

  • new python package name: myorg.myproject.useful_thing
  • new python distribution name: myorg.myproject.useful_thing
  • new debian name: python-myorg-myproject-useful-thing

I made pkgutil style namespace packages for myorg and myorg/myproject and moved the package into that heirarchy. My first attempt seems to have worked, but the deb no longer contains the python files.

Is there something special about namespace packages that I'm missing?


Solution

  • In the file debian/rules make sure to set PYBUILD_NAME to the deb name minus python/python3

    PYBUILD_NAME=myorg.myproject.useful.thing
    

    In the first instance I has set it to myorg.myproject.useful_thing. The idea was about close, but the underscore was a problem(Underscores in debian package names are illegal). Debian policy recomends using the dotted python package name as the debian package name as well. (a little different than pip, which would swap the dots for dashes)

    see https://www.debian.org/doc/packaging-manuals/python-policy/#module-package-names

    additionally for python2.7, using a pkgutil style namespace, if you include the init.py files in more than one namespaced package (packaged with dh_python) the init.py files conflict, so it is important that only one base package contain the namespaced directories.

    In the child packages, make sure not to include the namespace packages. e.g :

    packages=['myorg.myproject.other_thing'],
    

    or

    packages=find_packages(exclude=['myorg', 'myorg.myproject']),