问题
In the Python package I'm putting together I'm using the following setup.cfg
file:
[egg_info]
tag_build = dev
tag_date = 1
tag_svn_revision = 1
However when I run python setup.py sdist
the SVN revision appears as -r0
. This is likely because there is no .svn
directory where I run the setup script; in fact my tree is
main_dir/
.svn/
branches/
trunk/
setup.py
setup.cfg
How can I tell setuptools
to go find the SVN revision number in a parent directory? I still want to keep using my package version number.
回答1:
You can solve the -r0
problem in a different way if you're willing to install another package. Setuptools does not support the SVN metadata since version 10. The functionality has been moved to the setuptools_svn package.
回答2:
My solution at the moment is to combine this answer and build the version manually like this (minus the shell=True
option):
# Hat tip: https://stackoverflow.com/a/1501219/204634
import subprocess
def svnversion():
p = subprocess.Popen("svnversion", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate()
return stdout
_version = '{}-{}'.format(my_pkg_version, svnversion())
Whilst the setup.cfg
file contains:
[egg_info]
tag_build = dev
tag_date = 1
来源:https://stackoverflow.com/questions/37157271/setuptools-find-svn-revision-from-a-parent-directory