view setup.py @ 226:7b6ea46ea111

setup.py: clean up use of os.popen
author Mathias De Mare <mathias.de_mare@nokia.com>
date Tue, 14 Mar 2023 10:23:08 +0100
parents 3f9dd44be8c2
children
line wrap: on
line source

import os, time, subprocess
from distutils.core import setup

# query Mercurial for version number, or pull from PKG-INFO
version = 'unknown'
if os.path.isdir('.hg'):
    cmd = ["hg", "id", "-i", "-t"]
    l = subprocess.check_output(cmd, universal_newlines=True).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]
        if l[0].endswith('+'): # propagate the dirty status to the tag
            version += '+'
    elif len(l) == 1: # no tag found
        cmd1 = ['hg', 'parents', '--template', '{latesttag}']
        cmd2 = ['hg', 'parents', '--template', '{latesttagdistance}']
        version = "%s.dev%s" % (
            subprocess.check_output(cmd1, universal_newlines=True),
            subprocess.check_output(cmd2, universal_newlines=True)
        )
    if version.endswith('+'):
        version += time.strftime('%Y%m%d')
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='https://www.mercurial-scm.org/wiki/PythonHglibs',
    description='Mercurial Python library',
    long_description=open(os.path.join(os.path.dirname(__file__),
                                       'README')).read(),
    classifiers=[
        'Programming Language :: Python',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
        'Programming Language :: Python :: 3.8',
        'Programming Language :: Python :: 3.9',
        'Programming Language :: Python :: 3.10',
        'Programming Language :: Python :: 3.11',

    ],
    license='MIT',
    packages=['hglib'])