Search code examples
pythonpipsetuptoolssetuptools-scm

How to configure setuptools_scm to always generate timestamp and git hash


The setuptools_scm package by default could generate 4 different version messages.

no distance and clean: {tag}
distance and clean: {next_version}.dev{distance}+{scm letter}{revision hash}
no distance and not clean: {tag}+dYYYYMMDD
distance and not clean: {next_version}.dev{distance}+{scm letter}{revision hash}.dYYYYMMDD

In my usecase, I don't want to use its version message. Instead, I want to use it and retrive git hash and timestamp information.

from setuptools_scm import get_version
my_version = get_version()

According to its documentation, there is a get_version() function. But if the current repo has no distance and clean, it only generates tag which is not enough.

My question is how to configure get_version() function to let it always generate git hash and timestamp. So I can parse it and create my own version message.


Solution

  • Based on this issue, the author suggests a way to do it. More examples would be added later.