What is the correct way to share package version with setup.py and the package?

后端 未结 7 1753
盖世英雄少女心
盖世英雄少女心 2020-12-07 08:42

With distutils, setuptools, etc. a package version is specified in setup.py:

# file: setup.py
...
setup(
name=\'foobar         


        
相关标签:
7条回答
  • 2020-12-07 09:08

    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()
    
    0 讨论(0)
提交回复
热议问题