forked from lordgrilo/Holes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.py
239 lines (191 loc) · 7.84 KB
/
release.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
"""Release data for Holes.
When Holes is imported a number of steps are followed to determine
the version information.
1) If the release is not a development release (dev=False), then version
information is read from version.py, a file containing statically
defined version information. This file should exist on every
downloadable release of Holes since setup.py creates it during
packaging/installation. However, version.py might not exist if one
is running Holes from the mercurial repository. In the event that
version.py does not exist, then no vcs information will be available.
2) If the release is a development release, then version information
is read dynamically, when possible. If no dynamic information can be
read, then an attempt is made to read the information from version.py.
If version.py does not exist, then no vcs information will be available.
Clarification:
version.py is created only by setup.py
"""
# Copyright (C) 2012-2020 by
# Giovanni Petri <[email protected]>
# All rights reserved.
# BSD license.
from __future__ import absolute_import
import os
import sys
import time
import datetime
import subprocess
basedir = os.path.abspath(os.path.split(__file__)[0])
def write_versionfile():
"""Creates a static file containing version information."""
versionfile = os.path.join(basedir, 'version.py')
text = '''"""
Version information for NetworkX, created during installation.
Do not add this file to the repository.
"""
import datetime
version = %(version)r
date = %(date)r
# Was NetworkX built from a development version? If so, remember that the major
# and minor versions reference the "target" (rather than "current") release.
dev = %(dev)r
# Format: (name, major, min, revision)
version_info = %(version_info)r
# Format: a 'datetime.datetime' instance
date_info = %(date_info)r
# Format: (vcs, vcs_tuple)
vcs_info = %(vcs_info)r
'''
# Try to update all information
date, date_info, version, version_info, vcs_info = get_info(dynamic=True)
def writefile():
fh = open(versionfile, 'w')
subs = {
'dev' : dev,
'version': version,
'version_info': version_info,
'date': date,
'date_info': date_info,
'vcs_info': vcs_info
}
fh.write(text % subs)
fh.close()
if vcs_info[0] == 'mercurial':
# Then, we want to update version.py.
writefile()
else:
if os.path.isfile(versionfile):
# This is *good*, and the most likely place users will be when
# running setup.py. We do not want to overwrite version.py.
# Grab the version so that setup can use it.
sys.path.insert(0, basedir)
from version import version
del sys.path[0]
else:
# This is *bad*. It means the user might have a tarball that
# does not include version.py. Let this error raise so we can
# fix the tarball.
##raise Exception('version.py not found!')
# We no longer require that prepared tarballs include a version.py
# So we use the possibly trunctated value from get_info()
# Then we write a new file.
writefile()
return version
def get_revision():
"""Returns revision and vcs information, dynamically obtained."""
vcs, revision, tag = None, None, None
hgdir = os.path.join(basedir, '..', '.hg')
gitdir = os.path.join(basedir, '..', '.git')
if os.path.isdir(hgdir):
vcs = 'mercurial'
try:
p = subprocess.Popen(['hg', 'id'],
cwd=basedir,
stdout=subprocess.PIPE)
except OSError:
# Could not run hg, even though this is a mercurial repository.
pass
else:
stdout = p.communicate()[0]
# Force strings instead of unicode.
x = list(map(str, stdout.decode().strip().split()))
if len(x) == 0:
# Somehow stdout was empty. This can happen, for example,
# if you're running in a terminal which has redirected stdout.
# In this case, we do not use any revision/tag info.
pass
elif len(x) == 1:
# We don't have 'tip' or anything similar...so no tag.
revision = str(x[0])
else:
revision = str(x[0])
tag = str(x[1])
elif os.path.isdir(gitdir):
vcs = 'git'
# For now, we are not bothering with revision and tag.
vcs_info = (vcs, (revision, tag))
return revision, vcs_info
def get_info(dynamic=True):
## Date information
date_info = datetime.datetime.now()
date = time.asctime(date_info.timetuple())
revision, version, version_info, vcs_info = None, None, None, None
import_failed = False
dynamic_failed = False
if dynamic:
revision, vcs_info = get_revision()
if revision is None:
dynamic_failed = True
if dynamic_failed or not dynamic:
# This is where most final releases of NetworkX will be.
# All info should come from version.py. If it does not exist, then
# no vcs information will be provided.
sys.path.insert(0, basedir)
try:
from version import date, date_info, version, version_info, vcs_info
except ImportError:
import_failed = True
vcs_info = (None, (None, None))
else:
revision = vcs_info[1][0]
del sys.path[0]
if import_failed or (dynamic and not dynamic_failed):
# We are here if:
# we failed to determine static versioning info, or
# we successfully obtained dynamic revision info
version = ''.join([str(major), '.', str(minor)])
if dev:
version += '.dev_' + date_info.strftime("%Y%m%d%H%M%S")
version_info = (name, major, minor, revision)
return date, date_info, version, version_info, vcs_info
## Version information
name = 'ho'
major = 1
minor = 7
## Declare current release as a development release.
## Change to False before tagging a release; then change back.
dev = False
description = "Python package for the analysis and study of the homological structure of complex networks."
long_description = \
"""
ho (AY) is a Python package for the pre-processing, manipulation, and
study of the structure, dynamics, and functions of the homological structure of
complex networks.
"""
license = 'BSD'
authors = {'Petri' : ('Giovanni Petri','[email protected]'),
}
maintainer = "Giovanni Petri"
maintainer_email = "[email protected]"
url = 'http://lordgrilo.github.com/'
download_url="http://lordgrilo.github.com/"
platforms = ['Linux','Mac OSX','Windows','Unix']
keywords = ['Networks', 'Homology', 'Mathematics', 'network', 'Graph', 'discrete mathematics', 'math','complex networks','computational topology']
classifiers = [
'Development Status :: 1 - Alpha',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Topic :: Software Development :: Libraries :: Python modules',
'Topic :: Scientific/Engineering :: Bio-Informatics',
'Topic :: Scientific/Engineering :: Information Analysis',
'Topic :: Scientific/Engineering :: Mathematics',
'Topic :: Scientific/Engineering :: Physics']
date, date_info, version, version_info, vcs_info = get_info()
if __name__ == '__main__':
# Write versionfile for nightly snapshots.
write_versionfile()