Skip to content

Commit 1d623a5

Browse files
committedSep 29, 2014
put version into its own file to make it importable even if the package is not installed yet
1 parent 624e23e commit 1d623a5

File tree

3 files changed

+52
-53
lines changed

3 files changed

+52
-53
lines changed
 

‎doc/source/conf.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,8 @@
1515
import sys
1616
import os
1717

18-
try:
19-
from khal import __version__
20-
except ImportError:
21-
raise ImportError(
22-
'Khal needs to be installed to correctly infer its version. '
23-
'Please run `python setup.py develop` before building docs. '
24-
)
18+
sys.path.append('../../')
19+
from version import VERSION
2520

2621
# If extensions (or modules to document with autodoc) are in another directory,
2722
# add these directories to sys.path here. If the directory is relative to the
@@ -64,9 +59,9 @@
6459
# built documents.
6560
#
6661
# The short X.Y version.
67-
version = str(__version__)
62+
version = str(VERSION)
6863
# The full version, including alpha/beta/rc tags.
69-
release = str(__version__)
64+
release = str(VERSION)
7065

7166
# The language for content autogenerated by Sphinx. Refer to documentation
7267
# for a list of supported languages.

‎setup.py

+1-44
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,9 @@
11
#!/usr/bin/env python2
22
# vim: set ts=4 sw=4 expandtab sts=4 fileencoding=utf-8:
33

4-
import os
5-
import string
6-
import subprocess
7-
import warnings
8-
94
from setuptools import setup
105

11-
MAJOR = 0
12-
MINOR = 4
13-
PATCH = 0
14-
15-
RELEASE = False
16-
17-
VERSION = "{0}.{1}.{2}".format(MAJOR, MINOR, PATCH)
18-
19-
if not RELEASE:
20-
try:
21-
try:
22-
pipe = subprocess.Popen(
23-
["git", "describe", "--always", "--dirty", "--tags"],
24-
stdout=subprocess.PIPE)
25-
except EnvironmentError:
26-
warnings.warn("WARNING: git not installed or failed to run")
27-
28-
revision = pipe.communicate()[0].strip().lstrip('v')
29-
if pipe.returncode != 0:
30-
warnings.warn("WARNING: couldn't get git revision")
31-
32-
if revision != VERSION:
33-
revision = revision.lstrip(string.digits + '.')
34-
VERSION += '.dev' + revision
35-
except:
36-
VERSION += '.dev'
37-
warnings.warn("WARNING: git not installed or failed to run")
38-
39-
40-
def write_version():
41-
"""writes the khal/version.py file"""
42-
template = """\
43-
__version__ = '{0}'
44-
"""
45-
filename = os.path.join(
46-
os.path.dirname(__file__), 'khal', 'version.py')
47-
with open(filename, 'w') as versionfile:
48-
versionfile.write(template.format(VERSION))
49-
print("wrote khal/version.py with version={0}".format(VERSION))
6+
from version import write_version, VERSION
507

518
write_version()
529

‎version.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python2
2+
# vim: set ts=4 sw=4 expandtab sts=4 fileencoding=utf-8:
3+
4+
import os
5+
import string
6+
import subprocess
7+
import warnings
8+
9+
MAJOR = 0
10+
MINOR = 4
11+
PATCH = 0
12+
13+
RELEASE = False
14+
15+
VERSION = "{0}.{1}.{2}".format(MAJOR, MINOR, PATCH)
16+
17+
if not RELEASE:
18+
try:
19+
try:
20+
pipe = subprocess.Popen(
21+
["git", "describe", "--always", "--dirty", "--tags"],
22+
stdout=subprocess.PIPE)
23+
except EnvironmentError:
24+
warnings.warn("WARNING: git not installed or failed to run")
25+
26+
revision = pipe.communicate()[0].strip().lstrip('v')
27+
if pipe.returncode != 0:
28+
warnings.warn("WARNING: couldn't get git revision")
29+
30+
if revision != VERSION:
31+
revision = revision.lstrip(string.digits + '.')
32+
VERSION += '.dev' + revision
33+
except:
34+
VERSION += '.dev'
35+
warnings.warn("WARNING: git not installed or failed to run")
36+
37+
38+
def write_version():
39+
"""writes the khal/version.py file"""
40+
template = """\
41+
__version__ = '{0}'
42+
"""
43+
filename = os.path.join(
44+
os.path.dirname(__file__), 'khal', 'version.py')
45+
with open(filename, 'w') as versionfile:
46+
versionfile.write(template.format(VERSION))
47+
print("wrote khal/version.py with version={0}".format(VERSION))

0 commit comments

Comments
 (0)