Deluge develop source packaging: version.get_version issue

Suggestions and discussion of future versions
Post Reply
alllexx
Member
Member
Posts: 30
Joined: Sat May 23, 2015 1:30 pm

Deluge develop source packaging: version.get_version issue

Post by alllexx »

Hi,

`setup.py install` uses get_version function from version.py, which makes use of `git describe`, to generate version string. While this works OK in development environment, this is not an option in my case, where I first fetch a certain commit, then archive it without the '.git' directory (to save space), and then use the archive to cross-compile packages for various ARCHs. If left this way, the version is always '0.0.0', since `git describe` obviously fails here. After I looked into the sourcecode, I found out that 'RELEASE-VERSION' file (if available) is supposed to be used when `git describe` fails. However, running this before packaging sourcecode doesn't work:

Code: Select all

python -c 'from version import get_version; print get_version(prefix="deluge-", suffix=".dev0")' > RELEASE-VERSION
For some reason this function of version.py:

Code: Select all

def call_git_describe(prefix="", suffix=""):
    cmd = "git describe --tags --match %s[0-9]*" % prefix
    try:
        version = Popen(cmd.split(), stdout=PIPE).communicate()[0]
        version = version.strip().replace(prefix, "")
        if "-" in version:
            version = ".dev".join(version.replace(suffix, "").split("-")[:2])
        return version
    except:
        return None
Does not return "None", but rather empty string. Thus, even when RELEASE-VERSION (e.g., contains line '2.0.0.dev403') exists, I get this output:

Code: Select all

alex@Ubuntu:~/optware/buildroot-i686/builds/deluge-develop$ python -c 'from version import get_version; print get_version(prefix="deluge-", suffix=".dev0")'
fatal: Not a git repository (or any parent up to mount point /home/alex/optware/buildroot-i686)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

alex@Ubuntu:~/optware/buildroot-i686/builds/deluge-develop$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from version import get_version
>>> get_version(prefix="deluge-", suffix=".dev0")
fatal: Not a git repository (or any parent up to mount point /home/alex/optware/buildroot-i686)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
''
and, additionally, RELEASE-VERSION file is emptied.

I'm not really familiar with Python, but obviously this line:

Code: Select all

        version = Popen(cmd.split(), stdout=PIPE).communicate()[0]
doesn't throw an exception when `git describe` fails.

For now I use a hack as a workaround:

Code: Select all

VERSION=`python -c 'from version import get_version; print get_version(prefix="deluge-", suffix=".dev0")'`; \
sed -i -e "/^    version=.*,$/s/=.*/=\"${VERSION}\",/" setup.py
It would be nice if you could fix this. Also, a simple (python) script using version.py would be nice to avoid using ugly `python -c ...`.

Thanks :)
Cas
Top Bloke
Top Bloke
Posts: 3679
Joined: Mon Dec 07, 2009 6:04 am
Location: Scotland

Re: Deluge develop source packaging: version.get_version iss

Post by Cas »

This should fix it:

Code: Select all

diff --git a/version.py b/version.py
index 276b5c5..40ecc20 100644
--- a/version.py
+++ b/version.py
@@ -40,7 +40,7 @@
 def call_git_describe(prefix="", suffix=""):
     cmd = "git describe --tags --match %s[0-9]*" % prefix
     try:
-        version = Popen(cmd.split(), stdout=PIPE).communicate()[0]
+        version = Popen(cmd.split(), stdout=PIPE, stderr=PIPE).communicate()[0]
         version = version.strip().replace(prefix, "")
         if "-" in version:
             version = ".dev".join(version.replace(suffix, "").split("-")[:2])
@@ -58,9 +58,9 @@ def get_version(prefix="", suffix=""):
 
     version = call_git_describe(prefix, suffix)
 
-    if version is None:
+    if not version:
         version = release_version
-    if version is None:
+    if not version:
         raise ValueError("Cannot find the version number!")
 
     if version != release_version:
Just to mention if you use `python setup.py sdist` it will create a tarball with RELEASE_VERSION included.
alllexx
Member
Member
Posts: 30
Joined: Sat May 23, 2015 1:30 pm

Re: Deluge develop source packaging: version.get_version iss

Post by alllexx »

That indeed fixes it, thanks! And for the sdist tip too :)
Post Reply