-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
111 lines (93 loc) · 3.46 KB
/
setup.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
#!/usr/bin/env python
import os
from distutils.core import setup
# Create list of all sub-directories with
# __init__.py files...
packages = []
for subdir, dirs, files in os.walk('sp2graph'):
if '__init__.py' in files:
packages.append(subdir.replace(os.sep, '.'))
def git_version():
# Default release info
MAJOR = 0
MINOR = 0
MICRO = 1
VERSION = [MAJOR, MINOR, MICRO]
# Git revision prior to release:
GIT_REVISION = "0434304ad39d4101d5c8761f1a485dfacd8b59d8"
GIT_LABEL = '.'.join(map(str, [MAJOR, MINOR, MICRO]))
def _minimal_ext_cmd(cmd):
# construct minimal environment
env = {}
for k in ['SYSTEMROOT', 'PATH']:
v = os.environ.get(k)
if v is not None:
env[k] = v
# LANGUAGE is used on win32
env['LANGUAGE'] = 'C'
env['LANG'] = 'C'
env['LC_ALL'] = 'C'
out = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, env=env).communicate()[0]
return out.strip().decode('ascii')
current_path = os.path.dirname(os.path.realpath(__file__))
try:
# Get top-level directory
git_dir = _minimal_ext_cmd(['git', 'rev-parse', '--show-toplevel'])
# Assert that the git-directory is consistent with this setup.py script
if git_dir != current_path:
raise ValueError('Not executing the top-setup.py script')
# Get latest revision tag
rev = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
if len(rev) > 7:
GIT_REVISION = rev
# Get latest tag
tag = _minimal_ext_cmd(['git', 'describe', '--abbrev=0', '--tags'])
if len(tag) > 4:
VERSION = tag[1:].split('.')
# Get complete "git describe" string
label = _minimal_ext_cmd(['git', 'describe', '--tags'])
if len(label) > 7:
GIT_LABEL = label
# Get number of commits since tag
count = _minimal_ext_cmd(['git', 'rev-list', tag + '..', '--count'])
if len(count) == 0:
count = '1'
except Exception as e:
count = '0'
return GIT_REVISION, VERSION, int(count), GIT_LABEL
def write_version(filename='sp2graph/info.py'):
version_str = """# This file is automatically generated from sp2graph setup.py
# Git information (specific commit, etc.)
git_revision = '{git}'
git_revision_short = git_revision[:7]
git_count = {count}
# Version information
major = {version[0]}
minor = {version[1]}
micro = {version[2]}
# Release tag
release = 'v'+'.'.join(map(str,[major, minor, micro]))
# Version (release + count)
version = release
if git_count > 0:
# Add git-revision to the version string
version += '+' + str(git_count)
# Extensive version description
label = '{description}'
"""
# If we are in git we try and fetch the git version as well
GIT_REV, GIT_VER, GIT_COUNT, GIT_LAB = git_version()
with open(filename, 'w') as fh:
fh.write(version_str.format(version=GIT_VER,
count=GIT_COUNT,
git=GIT_REV,
description=GIT_LAB))
write_version()
# Main setup of python modules
setup(name='sp2graph',
description='Bond-order graph analysis of sp2 carbon nanostructures',
url='https://github.com/dipc-cc/sp2graph',
license='GPL-3.0',
requires=['python (>=3.6)', 'numpy (>=1.13.3)', 'matplotlib (>=2.2.2)'],
packages=packages)