How can I rewrite python __version__ with git?

前端 未结 5 885
日久生厌
日久生厌 2020-12-12 16:40

I would like to define a __version__ variable in my module which should be automatically updated on git commit similarly to what SVN keywords do. Is there a way

5条回答
  •  隐瞒了意图╮
    2020-12-12 16:43

    Another possibility other than Versioneer is setuptools_scm.

    I have successfully implemented something very similar to the OP by adding the following to setup.py (or by modifying it accordingly):

    from setuptools import setup
    setup(
        ...,
        use_scm_version=True,
        setup_requires=['setuptools_scm'],
        ...,
    )
    

    and, in order to have __version__ updated automatically, added this to __init__.py of my package:

    from pkg_resources import get_distribution, DistributionNotFound
    try:
        __version__ = get_distribution(__name__).version
    except DistributionNotFound:
        # package is not installed
        pass
    

提交回复
热议问题