I have my own package I would like to be able to have the git hash for logging purposes when outside the repo e.g. when calling the package on a remote server or keeping track of frequent updates and distributed servers to see which version of the code ran what.
I know I can get the git hash as such however if I call this outside the repo I get an error InvalidGitRepositoryError:
I tried setting the version in my setup.py
as: '1.0-{}'.format(GIT_REVISION)
using the gitpython package however when I build using pip
it falls back to setuptools
instead of using a wheel
because of the following:
WARNING: Built wheel for mypackage is invalid: Metadata 1.2 mandates PEP 440 version, but '1.0-d180ffe3fc30a3920edfcbace5ab00e934f15e3b' is not
Failed to build mypackage
Installing collected packages: mypackage
Running setup.py install for mypackage ... done
DEPRECATION: mypackage was installed using the legacy 'setup.py install' method, because a wheel could not be built for it. A possible replacement is to fix the wheel build issue reported above. Discussion can be found at https://github.com/pypa/pip/issues/8368
setuptools
doe not provide a mypackage.__version__
to obtain the git hash.
Is there a way I can get the githash within the mypackage module or version while outside the repo?