Setuptools: find SVN revision from a parent directory

我是研究僧i 提交于 2019-12-24 15:37:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!