With distutils
, setuptools
, etc. a package version is specified in setup.py
:
# file: setup.py
...
setup(
name=\'foobar
Based on the accepted answer and comments, this is what I ended up doing:
file: setup.py
setup(
name='foobar',
version='1.0.0',
# other attributes
)
file: __init__.py
from pkg_resources import get_distribution, DistributionNotFound
__project__ = 'foobar'
__version__ = None # required for initial installation
try:
__version__ = get_distribution(__project__).version
except DistributionNotFound:
VERSION = __project__ + '-' + '(local)'
else:
VERSION = __project__ + '-' + __version__
from foobar import foo
from foobar.bar import Bar
Explanation:
__project__
is the name of the project to install which may be
different than the name of the package
VERSION
is what I display in my command-line interfaces when
--version
is requested
the additional imports (for the simplified package interface) only occur if the project has actually been installed