Skip to content

Commit

Permalink
Fixing #16
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Masfaraud committed Jan 31, 2019
1 parent 023f67b commit 4a4b5b1
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,54 @@
"""

from setuptools import setup

from os.path import dirname, isdir, join
import re
from subprocess import CalledProcessError, check_output

def readme():
with open('README.rst') as f:
return f.read()

tag_re = re.compile(r'\btag: %s([0-9][^,]*)\b')
version_re = re.compile('^Version: (.+)$', re.M)

def get_version():
# Return the version if it has been injected into the file by git-archive
version = tag_re.search('$Format:%D$')
if version:
return version.group(1)

d = dirname(__file__)

if isdir(join(d, '.git')):
cmd = 'git describe --tags --dirty'
try:
version = check_output(cmd.split()).decode().strip()[:]
except CalledProcessError:
raise RuntimeError('Unable to get version number from git tags')
if version[0]=='v':
version = version[1:]
# print(version)
# PEP 440 compatibility
if '-' in version:
if version.endswith('-dirty'):
version = '.dev'.join(version.split('-')[:-1][:2])+'-dirty'
else:
version = '.dev'.join(version.split('-')[:2])

else:
# Extract the version from the PKG-INFO file.
with open(join(d, 'PKG-INFO')) as f:
version = version_re.search(f.read()).group(1)

# # Writing to file
# with open('powertransmission/version.py', 'w+') as vf:
# vf.write("# -*- coding: utf-8 -*-\nversion = '{}'".format(version))

return version

setup(name='bms',
use_scm_version = True,
setup_requires = ['setuptools_scm'],
version = get_version(),
description = 'Block-Model Simulator for python',
long_description = readme(),
keywords = 'block model simulation simulator time',
Expand Down

0 comments on commit 4a4b5b1

Please sign in to comment.