With distutils
, setuptools
, etc. a package version is specified in setup.py
:
# file: setup.py
...
setup(
name=\'foobar
The accepted answer requires that the package has been installed. In my case, I needed to extract the installation params (including __version__
) from the source setup.py
. I found a direct and simple solution while looking through the tests of the setuptools package. Looking for more info on the _setup_stop_after
attribute lead me to an old mailing list post which mentioned distutils.core.run_setup
, which lead me to the actual docs needed. After all that, here's the simple solution:
file setup.py
:
from setuptools import setup
setup(name='funniest',
version='0.1',
description='The funniest joke in the world',
url='http://github.com/storborg/funniest',
author='Flying Circus',
author_email='flyingcircus@example.com',
license='MIT',
packages=['funniest'],
zip_safe=False)
file extract.py
:
from distutils.core import run_setup
dist = run_setup('./setup.py', stop_after='init')
dist.get_version()