Skip to content

Commit 1ea0e32

Browse files
committed
Modify to call _safe_get_version() instead of pythonect.__version__
1 parent cb1f605 commit 1ea0e32

2 files changed

Lines changed: 72 additions & 16 deletions

File tree

‎pythonect/__init__.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
"""Parse and execute Pythonect code"""
3030

31-
import sys
3231

3332
__version__ = '0.0.0dev0'
3433

@@ -42,8 +41,7 @@
4241

4342
__version__ = get_version()
4443

45-
if (sys.argv[0] != 'setup.py') or (sys.argv[0] == 'setup.py' and sys.argv[1] in ['test', 'nosetests']):
4644

47-
# API
45+
# API
4846

49-
from internal.eval import eval, parse
47+
from internal.eval import eval, parse

‎setup.py‎

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,8 @@
4343
import sys
4444
import distutils.core
4545
import distutils.command.build
46-
47-
48-
# Local imports
49-
50-
import pythonect
46+
import subprocess
47+
import re
5148

5249

5350
# Functions
@@ -56,7 +53,69 @@ def _mk_versiondotpy():
5653

5754
with open('pythonect/_version.py', 'wt') as f:
5855

59-
f.write('# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN.\n__version__ = \'' + pythonect.__version__ + '\'\n')
56+
f.write('# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN.\n__version__ = \'' + _safe_get_version() + '\'\n')
57+
58+
59+
def __get_git_version():
60+
61+
version = "0.0.0.dev0"
62+
63+
try:
64+
65+
git = subprocess.Popen(['git', 'describe'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
66+
67+
git.stderr.close()
68+
69+
git_output = git.stdout.readlines()[0]
70+
71+
git_ver = re.match('^\w+(?P<MAJOR>\d+)\.(?P<MINOR>\d+)(\.(?P<MICRO>\d+)(\-(?P<DEV>\d+))?)?', git_output)
72+
73+
if git_ver is not None:
74+
75+
# MAJOR.MINOR
76+
77+
version = git_ver.group('MAJOR') + '.' + git_ver.group('MINOR')
78+
79+
if git_ver.groupdict('MICRO') is not None:
80+
81+
# MAJOR.MINOR.MICRO
82+
83+
version = version + '.' + git_ver.group('MICRO')
84+
85+
if git_ver.groupdict('DEV') is not None:
86+
87+
# MAJOR.MINOR.MICRO-DEV
88+
89+
version = version + '.dev' + git_ver.group('DEV')
90+
91+
except Exception as e:
92+
93+
pass
94+
95+
return version
96+
97+
98+
def _safe_get_version():
99+
100+
version = '0.0.0dev0'
101+
102+
try:
103+
104+
tmp_globals = {}
105+
106+
# Tarball?
107+
108+
execfile('pythonect/_version.py', tmp_globals)
109+
110+
version = tmp_globals['__version__']
111+
112+
except Exception:
113+
114+
# Git repository?
115+
116+
version = __get_git_version()
117+
118+
return version
60119

61120

62121
# Classes
@@ -66,20 +125,19 @@ class Version(distutils.core.Command):
66125
description = ""
67126
user_options = []
68127

69-
def initialize_options (self):
128+
def initialize_options(self):
70129
pass
71130

72-
73-
def finalize_options (self):
131+
def finalize_options(self):
74132
pass
75133

76-
def run (self):
134+
def run(self):
77135

78136
# Generate `_version.py`
79137

80138
_mk_versiondotpy()
81139

82-
print "*** Pythonect Version %s ***" % (pythonect.__version__)
140+
print "*** Pythonect Version %s ***" % (_safe_get_version())
83141

84142

85143
# Entry Point
@@ -102,7 +160,7 @@ def run (self):
102160

103161
setupconf = dict(
104162
name='Pythonect',
105-
version=pythonect.__version__,
163+
version=_safe_get_version(),
106164
author='Itzik Kotler',
107165
author_email='xorninja@gmail.com',
108166
url='http://www.pythonect.org/',

0 commit comments

Comments
 (0)