Python package: how to avoid redefining author version etc?
Question: 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?


Answer: If you are invoking sphinx using distutils, your case is covered. The answer
is in the documentation in
[sphinx/setup_command.py](https://bitbucket.org/birkenfeld/sphinx/src/72dceb35264e9429c8d9bb1a249a638ac21f0524/sphinx/setup_command.py?at=default#cl-35).
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!

