Properly initialize version string in python-hglib setup.py

Peter Elmers peter.elmers at yahoo.com
Tue Jul 21 16:09:20 CDT 2015


Hi Yuya,
Thanks for the feedback and clarifying the intention. They are good points; I have included revised patch below.


# HG changeset patch
# User Peter Elmers <peter.elmers at yahoo.com>
# Date 1437512568 25200
#      Tue Jul 21 14:02:48 2015 -0700
# Node ID 1b327fa07920e0717cf72438f07cb2afa985a833
# Parent  ec935041d1ff0fd2aa8cb666d79e6dcca398ddba
Issue 3924: parse PKG-INFO for version information.

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -1,12 +1,12 @@
 import os, time
 from distutils.core import setup
 
-# query Mercurial for version number
+# query Mercurial for version number, or pull from PKG-INFO
 version = 'unknown'
 if os.path.isdir('.hg'):
     cmd = "hg id -i -t"
     l = os.popen(cmd).read().split()
     while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags
         l.pop()
     if len(l) > 1: # tag found
         version = l[-1]
@@ -21,16 +21,20 @@ elif os.path.exists('.hg_archival.txt'):
     kw = dict([[t.strip() for t in l.split(':', 1)]
                for l in open('.hg_archival.txt')])
     if 'tag' in kw:
         version =  kw['tag']
     elif 'latesttag' in kw:
         version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw
     else:
         version = kw.get('node', '')[:12]
+elif os.path.exists('PKG-INFO'):
+    kw = dict([[t.strip() for t in l.split(':', 1)]
+               for l in open('PKG-INFO') if ':' in l])
+    version = kw.get('Version', version)
 
 setup(
     name='python-hglib',
     version=version,
     author='Idan Kamara',
     author_email='idankk86 at gmail.com',
     url='http://selenic.com/repo/python-hglib',
     description='Mercurial Python library',



     On Tuesday, July 21, 2015 8:40 AM, Yuya Nishihara <yuya at tcha.org> wrote:
   

 On Mon, 20 Jul 2015 23:27:02 +0000 (UTC), Peter Elmers wrote:
> # HG changeset patch
> # User Peter Elmers <peter.elmers at yahoo.com>
> # Date 1437434738 25200
> #      Mon Jul 20 16:25:38 2015 -0700
> # Node ID c0f73a10ceb96a60c178f6057ce90309d08d3974
> # Parent  ec935041d1ff0fd2aa8cb666d79e6dcca398ddba
> Issue 3924: default version to 1.6, parse PKG-INFO.

Thanks for the revised patch, but we prefer patch in body, not as an
attachment.

https://mercurial.selenic.com/wiki/ContributingChanges#Submission_checklist

Couple of comments follow...

> -# query Mercurial for version number
> -version = 'unknown'
> +version = '1.6'

Hmm, it must be updated per release? That is what we want to avoid.

>  elif os.path.exists('.hg_archival.txt'):
>      kw = dict([[t.strip() for t in l.split(':', 1)]
>                for l in open('.hg_archival.txt')])
>      if 'tag' in kw:
> -        version =  kw['tag']
> +        version = kw['tag']

Good catch, but whitespace cleanup should be a separate patch.

>      elif 'latesttag' in kw:
>          version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw
>      else:
>          version = kw.get('node', '')[:12]
> +elif os.path.exists('PKG-INFO'):
> +    with open('PKG-INFO') as pkginfo:
> +        kw = dict([[t.strip() for t in l.split(':', 1)]
> +                  for l in pkginfo if ':' in l])
> +        version = kw.get('Version', version)

Perhaps hglib should be compatible with ancient Python, so I think "with"
statement isn't allowed.


  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20150721/d890e41f/attachment.html>


More information about the Mercurial-devel mailing list