How can I rewrite python __version__ with git?

前端 未结 5 869
日久生厌
日久生厌 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 17:03

    For those finding this question in 2018 you can also use Versioneer. Once enabled, it automatically sets version in setup.py and __version__ in your module based on the latest Git tag at time of build.

    For example, if you build your project at tag 1.0.0, Versioneer will set the project's version to 1.0.0. If you do two more commits, edit some without checking in, and build, Versioneer will set the version to something like 1.0.0+2.g1076c97.dirty.

    Of course you can customize which tags Versioneer recognizes as version tags.

    This is also how larger projects like pandas and matplotlib handle their versioning.

提交回复
热议问题