setup.py
to manage everything, it'd be much easier to maintain everything at the same level, I decided to address a couple of long-standing problems with my distribution.Essentially the problem boils down to one thing: I want to be able to place libraries in the python
site-pacakges
directory but, due to local conventions, I need to be able to put scripts into separate bin
, sbin
, and libexec
directories in a non-standard and completely different directory tree to the interpreter.To do this, I created subclasses of the standard python install and build distutils for each of the various activities and added them into a custom subclass of
Distribution
, and used this in setup.py
. This worked up to a point, but failed to include the files listed in the sbin
and libexec
keywords in source distributions unless the files were added to the MANIFEST.in
, and the standard setup.py install
failed to include options to allow the target directories to be altered, even though I'd added new install commands for each of the targets.I realised I needed to tackle each problem with a different subclass.
I altered the base
sdist
class with a trivial addition to the add_defaults()
method which check whether there are libexec and/or sbin files and uses the relevant build method to add them to the internal FileList
instance. This solved the first problem.I also created a subclass of install to add my two additional command line options —
install-sbin
and install-libexec
. I immediately found that I was able to specify the options on the command line and in setup.cfg
, but I couldn't persuade my two install classes to pick them up. After a certain amount of puzzling, I realised the answer was obvious: I needed to add each option to the set_undefined_options()
call in the class's finalize_options()
method to explicitly copy the value from install
into the class's option, if it is unset.Unfortunately none of this is terribly clear from the documentation, but there are plenty of examples in the
distutils
directory of the interpreter and distutils.cmd.Command
has docstrings which explain how the various methods work and how they should be used.