Skip to content

Commit 28624cf

Browse files
committed
Fix up version approach
1 parent 68d2130 commit 28624cf

File tree

3 files changed

+7
-76
lines changed

3 files changed

+7
-76
lines changed

python/MANIFEST.IN

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ include *.txt
77
include .coveragerc
88
include .gitignore
99
include LICENSE
10-
include RELEASE-VERSION
1110
include tox.ini
1211
recursive-include sbp/ *.py
1312
prune docs/_build

python/sbp/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def get_git_version():
7575
version = call_git_describe()
7676

7777
# Take off the leading if present.
78-
if version[0] == 'v':
78+
if version is not None and version[0] == 'v':
7979
version = version[1:]
8080

8181
#adapt to PEP 386 compatible versioning scheme

python/setup.py

Lines changed: 6 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,8 @@
11
#!/usr/bin/env python
22

33
from setuptools import setup
4-
from subprocess import Popen, PIPE
54
import os
6-
7-
def call_git_describe():
8-
try:
9-
p = Popen(['git', 'describe', '--tags', '--dirty', '--always'],
10-
stdout=PIPE, stderr=PIPE)
11-
p.stderr.close()
12-
line = p.stdout.readlines()[0]
13-
return line.strip()
14-
except:
15-
return None
16-
17-
def read_release_version():
18-
try:
19-
f = open(os.path.join(os.path.dirname(__file__), 'RELEASE-VERSION'), "r")
20-
try:
21-
version = f.readlines()[0]
22-
return version.strip()
23-
finally:
24-
f.close()
25-
except:
26-
return None
27-
28-
def write_release_version(version):
29-
f = open(os.path.join(os.path.dirname(__file__), 'RELEASE-VERSION'), "w")
30-
f.write("%s\n" % version)
31-
f.close()
32-
33-
def pep386adapt(version):
34-
if version is not None and '-' in version:
35-
# adapt git-describe version to be in line with PEP 386
36-
# Break PEP 386 a bit here and append the Git hash
37-
parts = version.split('-')
38-
if len(parts) > 2:
39-
version = '%s.post%s-%s' % (
40-
parts[0], parts[1],
41-
'-'.join(parts[2:])
42-
)
43-
return version
44-
else:
45-
return version
46-
47-
def get_git_version():
48-
# Read in the version that's currently in RELEASE-VERSION.
49-
release_version = read_release_version()
50-
51-
# First try to get the current version using 'git describe'.
52-
version = call_git_describe()
53-
54-
# Take off the leading if present.
55-
if version[0] == 'v':
56-
version = version[1:]
57-
58-
#adapt to PEP 386 compatible versioning scheme
59-
version = pep386adapt(version)
60-
61-
# If that doesn't work, fall back on the value that's in
62-
# RELEASE-VERSION.
63-
if version is None:
64-
version = release_version
65-
66-
# If we still don't have anything, that's an error.
67-
if version is None:
68-
raise ValueError("Cannot find the version number!")
69-
70-
# If the current version is different from what's in the
71-
# RELEASE-VERSION file, update the file to be current.
72-
if version != release_version:
73-
write_release_version(version)
74-
75-
# Finally, return the current version.
76-
return version
77-
78-
VERSION = get_git_version()
5+
from sbp.version import VERSION
796

807
CLASSIFIERS = [
818
'Intended Audience :: Developers',
@@ -102,6 +29,10 @@ def get_git_version():
10229
'win32',
10330
]
10431

32+
PACKAGE_DATA = { 'sbp' : [
33+
'RELEASE-VERSION',
34+
] }
35+
10536
cwd = os.path.abspath(os.path.dirname(__file__))
10637
with open(cwd + '/README.rst') as f:
10738
readme = f.read()
@@ -119,6 +50,7 @@ def get_git_version():
11950
classifiers=CLASSIFIERS,
12051
packages=PACKAGES,
12152
platforms=PLATFORMS,
53+
package_data=PACKAGE_DATA,
12254
install_requires=INSTALL_REQUIRES,
12355
use_2to3=False,
12456
zip_safe=False)

0 commit comments

Comments
 (0)