Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python package: how to avoid redefining author version etc?

I would like to distribute a Python package (I would like to use setuptools and I already have a working setup.py file), and the related documentation (produced using Sphinx).

I find myself a bit confused by the fact that I have to specify the authors names, maintainers, version, release, date, emails etc in different parts.

I was wondering if there is some way to define this kind of common information only once for the package and then use it both in the setup.py script and in .rst files and so on.

What are the possible approaches to this problem?

like image 736
lucacerone Avatar asked May 09 '13 15:05

lucacerone


1 Answers

If you are invoking sphinx using distutils, your case is covered. The answer is in the documentation in sphinx/setup_command.py. From that example, your setup.py should have a part that looks somewhat like this:

   # this is only necessary when not using setuptools/distribute
   from sphinx.setup_command import BuildDoc
   cmdclass = {'build_sphinx': BuildDoc}

   name = 'My project'
   version = '1.2'
   release = '1.2.0'
   setup(
       name=name,
       author='Bernard Montgomery',
       version=release,
       cmdclass=cmdclass,
       # these are optional and override conf.py settings
       command_options={
           'build_sphinx': {
               'project': ('setup.py', name),
               'version': ('setup.py', version),
               'release': ('setup.py', release)}},
   )

After that, calling python setup.py build_sphinx will build the documentation, having a single point of truth for those shared values. Well done.

Works for me. Hope it helps!

like image 132
salicideblock Avatar answered Oct 25 '22 06:10

salicideblock