Statistics
| Branch: | Revision:

iof-tools / networkxMiCe / networkx-master / networkx / release.py @ 5cef0f13

History | View | Annotate | Download (7.67 KB)

1
"""Release data for NetworkX.
2

3
When NetworkX is imported a number of steps are followed to determine
4
the version information.
5

6
   1) If the release is not a development release (dev=False), then version
7
      information is read from version.py, a file containing statically
8
      defined version information.  This file should exist on every
9
      downloadable release of NetworkX since setup.py creates it during
10
      packaging/installation.  However, version.py might not exist if one
11
      is running NetworkX from the mercurial repository.  In the event that
12
      version.py does not exist, then no vcs information will be available.
13

14
   2) If the release is a development release, then version information
15
      is read dynamically, when possible.  If no dynamic information can be
16
      read, then an attempt is made to read the information from version.py.
17
      If version.py does not exist, then no vcs information will be available.
18

19
Clarification:
20
      version.py is created only by setup.py
21

22
When setup.py creates version.py, it does so before packaging/installation.
23
So the created file is included in the source distribution.  When a user
24
downloads a tar.gz file and extracts the files, the files will not be in a
25
live version control repository.  So when the user runs setup.py to install
26
NetworkX, we must make sure write_versionfile() does not overwrite the
27
revision information contained in the version.py that was included in the
28
tar.gz file. This is why write_versionfile() includes an early escape.
29

30
"""
31

    
32
#    Copyright (C) 2004-2019 by
33
#    Aric Hagberg <hagberg@lanl.gov>
34
#    Dan Schult <dschult@colgate.edu>
35
#    Pieter Swart <swart@lanl.gov>
36
#    All rights reserved.
37
#    BSD license.
38

    
39
from __future__ import absolute_import
40

    
41
import os
42
import sys
43
import time
44
import datetime
45

    
46
basedir = os.path.abspath(os.path.split(__file__)[0])
47

    
48

    
49
def write_versionfile():
50
    """Creates a static file containing version information."""
51
    versionfile = os.path.join(basedir, 'version.py')
52

    
53
    text = '''"""
54
Version information for NetworkX, created during installation.
55

56
Do not add this file to the repository.
57

58
"""
59

60
import datetime
61

62
version = %(version)r
63
date = %(date)r
64

65
# Was NetworkX built from a development version? If so, remember that the major
66
# and minor versions reference the "target" (rather than "current") release.
67
dev = %(dev)r
68

69
# Format: (name, major, min, revision)
70
version_info = %(version_info)r
71

72
# Format: a 'datetime.datetime' instance
73
date_info = %(date_info)r
74

75
# Format: (vcs, vcs_tuple)
76
vcs_info = %(vcs_info)r
77

78
'''
79

    
80
    # Try to update all information
81
    date, date_info, version, version_info, vcs_info = get_info(dynamic=True)
82

    
83
    def writefile():
84
        fh = open(versionfile, 'w')
85
        subs = {
86
            'dev': dev,
87
            'version': version,
88
            'version_info': version_info,
89
            'date': date,
90
            'date_info': date_info,
91
            'vcs_info': vcs_info
92
        }
93
        fh.write(text % subs)
94
        fh.close()
95

    
96
    if vcs_info[0] == 'mercurial':
97
        # Then, we want to update version.py.
98
        writefile()
99
    else:
100
        if os.path.isfile(versionfile):
101
            # This is *good*, and the most likely place users will be when
102
            # running setup.py. We do not want to overwrite version.py.
103
            # Grab the version so that setup can use it.
104
            # sys.path.insert(0, basedir)
105
            from version import version
106
            # del sys.path[0]
107
        else:
108
            # This is *bad*.  It means the user might have a tarball that
109
            # does not include version.py.  Let this error raise so we can
110
            # fix the tarball.
111
            # raise Exception('version.py not found!')
112

    
113
            # We no longer require that prepared tarballs include a version.py
114
            # So we use the possibly trunctated value from get_info()
115
            # Then we write a new file.
116
            writefile()
117

    
118
    return version
119

    
120

    
121
def get_revision():
122
    """Returns revision and vcs information, dynamically obtained."""
123
    vcs, revision, tag = None, None, None
124

    
125
    gitdir = os.path.join(basedir, '..', '.git')
126

    
127
    if os.path.isdir(gitdir):
128
        vcs = 'git'
129
        # For now, we are not bothering with revision and tag.
130

    
131
    vcs_info = (vcs, (revision, tag))
132

    
133
    return revision, vcs_info
134

    
135

    
136
def get_info(dynamic=True):
137
    # Date information
138
    date_info = datetime.datetime.utcfromtimestamp(int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))
139
    date = time.asctime(date_info.timetuple())
140

    
141
    revision, version, version_info, vcs_info = None, None, None, None
142

    
143
    import_failed = False
144
    dynamic_failed = False
145

    
146
    if dynamic:
147
        revision, vcs_info = get_revision()
148
        if revision is None:
149
            dynamic_failed = True
150

    
151
    if dynamic_failed or not dynamic:
152
        # This is where most final releases of NetworkX will be.
153
        # All info should come from version.py. If it does not exist, then
154
        # no vcs information will be provided.
155
        # sys.path.insert(0, basedir)
156
        try:
157
            from version import date, date_info, version, version_info, vcs_info
158
        except ImportError:
159
            import_failed = True
160
            vcs_info = (None, (None, None))
161
        else:
162
            revision = vcs_info[1][0]
163
        #del sys.path[0]
164

    
165
    if import_failed or (dynamic and not dynamic_failed):
166
        # We are here if:
167
        #   we failed to determine static versioning info, or
168
        #   we successfully obtained dynamic revision info
169
        version = ''.join([str(major), '.', str(minor)])
170
        if dev:
171
            version += '.dev_' + date_info.strftime("%Y%m%d%H%M%S")
172
        version_info = (name, major, minor, revision)
173

    
174
    return date, date_info, version, version_info, vcs_info
175

    
176

    
177
# Version information
178
name = 'networkx'
179
major = "2"
180
minor = "4rc1"
181

    
182

    
183
# Declare current release as a development release.
184
# Change to False before tagging a release; then change back.
185
dev = True
186

    
187

    
188
description = "Python package for creating and manipulating graphs and networks"
189

    
190
long_description = \
191
    """
192
NetworkX is a Python package for the creation, manipulation, and
193
study of the structure, dynamics, and functions of complex networks.
194

195
"""
196
license = 'BSD'
197
authors = {'Hagberg': ('Aric Hagberg', 'hagberg@lanl.gov'),
198
           'Schult': ('Dan Schult', 'dschult@colgate.edu'),
199
           'Swart': ('Pieter Swart', 'swart@lanl.gov')}
200
maintainer = "NetworkX Developers"
201
maintainer_email = "networkx-discuss@googlegroups.com"
202
url = 'http://networkx.github.io/'
203
project_urls={
204
    "Bug Tracker": "https://github.com/networkx/networkx/issues",
205
    "Documentation": "https://networkx.github.io/documentation/stable/",
206
    "Source Code": "https://github.com/networkx/networkx",
207
}
208
platforms = ['Linux', 'Mac OSX', 'Windows', 'Unix']
209
keywords = ['Networks', 'Graph Theory', 'Mathematics',
210
            'network', 'graph', 'discrete mathematics', 'math']
211
classifiers = [
212
    'Development Status :: 5 - Production/Stable',
213
    'Intended Audience :: Developers',
214
    'Intended Audience :: Science/Research',
215
    'License :: OSI Approved :: BSD License',
216
    'Operating System :: OS Independent',
217
    'Programming Language :: Python :: 3',
218
    'Programming Language :: Python :: 3.5',
219
    'Programming Language :: Python :: 3.6',
220
    'Programming Language :: Python :: 3.7',
221
    'Programming Language :: Python :: 3 :: Only',
222
    'Topic :: Software Development :: Libraries :: Python Modules',
223
    'Topic :: Scientific/Engineering :: Bio-Informatics',
224
    'Topic :: Scientific/Engineering :: Information Analysis',
225
    'Topic :: Scientific/Engineering :: Mathematics',
226
    'Topic :: Scientific/Engineering :: Physics']
227

    
228
date, date_info, version, version_info, vcs_info = get_info()
229

    
230
if __name__ == '__main__':
231
    # Write versionfile for nightly snapshots.
232
    write_versionfile()