Patchwork Properly initialize version string in python-hglib setup.py

login
register
mail settings
Submitter Peter Elmers
Date July 21, 2015, 9:09 p.m.
Message ID <1270482731.2157013.1437512960875.JavaMail.yahoo@mail.yahoo.com>
Download mbox | patch
Permalink /patch/10051/
State Changes Requested
Delegated to: Matt Mackall
Headers show

Comments

Peter Elmers - July 21, 2015, 9:09 p.m.
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@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.




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

 On Mon, 20 Jul 2015 23:27:02 +0000 (UTC), Peter Elmers wrote:
> # HG changeset patch
> # User Peter Elmers <peter.elmers@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.
Yuya Nishihara - July 23, 2015, 1:12 p.m.
On Tue, 21 Jul 2015 21:09:20 +0000 (UTC), Peter Elmers wrote:
> # HG changeset patch
> # User Peter Elmers <peter.elmers@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.

We prefer "topic: summary (issueXXXX)", for example,

setup: parse PKG-INFO for version information (issue3924)

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

> +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)

The patch looks good to me, but it can't be applied because all
whitespaces are damaged. Please consider using the patchbomb extension.

https://mercurial.selenic.com/wiki/PatchbombExtension

Patch

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@gmail.com',
     url='http://selenic.com/repo/python-hglib',
     description='Mercurial Python library',