forked from zerothi/sisl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
265 lines (222 loc) · 7.61 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
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/usr/bin/env python
"""
Library to create/handle geometries and tight-binding parameters in Python. Made with DFT in mind.
"""
from __future__ import print_function
if __doc__ is None:
__doc__ = """sisl: Generic library for manipulating DFT output, geometries and tight-binding parameter sets"""
DOCLINES = __doc__.split("\n")
import sys
import subprocess
import os
import os.path as osp
CLASSIFIERS = """\
Development Status :: 5 - Production/Stable
Intended Audience :: Science/Research
Intended Audience :: Developers
License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Topic :: Software Development
Topic :: Scientific/Engineering
Topic :: Scientific/Engineering :: Physics
Topic :: Utilities
"""
MAJOR = 0
MINOR = 9
MICRO = 4
ISRELEASED = False
VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO)
GIT_REVISION = "56550eb5924245b9908963ba07a67d8f34108599"
# The MANIFEST should be updated (which it only is
# if it does not exist...)
# So we try and delete it...
if osp.exists('MANIFEST'):
os.remove('MANIFEST')
# The install_requires should also be the
# requirements for the actual running of sisl
install_requires = [
'six',
'setuptools',
'numpy>=1.10',
'scipy>=0.18',
'netCDF4',
'pyparsing',
]
# Create list of all sub-directories with
# __init__.py files...
packages = ['sisl']
for subdir, dirs, files in os.walk('sisl'):
if '__init__.py' in files:
packages.append(subdir.replace(os.sep, '.'))
if 'tests' in 'dirs':
packages.append(subdir.replace(os.sep, '.') + '.tests')
def readme():
if not osp.exists('README.md'):
return ""
return open('README.md', 'r').read()
metadata = dict(
name='sisl',
maintainer="Nick R. Papior",
maintainer_email="[email protected]",
description="Python interface for tight-binding model creation and analysis of DFT output. Input mechanism for large scale transport calculations using NEGF TBtrans (TranSiesta)",
long_description=readme(),
long_description_content_type="text/markdown",
url="http://github.com/zerothi/sisl",
download_url="http://github.com/zerothi/sisl/releases",
license='LGPLv3',
packages=packages,
entry_points={
'console_scripts':
['sgeom = sisl.geometry:sgeom',
'sgrid = sisl.grid:sgrid',
'sdata = sisl.utils.sdata:sdata']
},
classifiers=[_f.strip() for _f in CLASSIFIERS.split('\n') if _f],
platforms=['Unix', 'Linux', 'Mac OS-X', 'Windows'],
install_requires=install_requires,
tests_require=['pytest'],
zip_safe=False,
extras_require={
# We currently use xarray for additional data-analysis
# And tqdm for progressbars
'analysis': ['xarray>=0.10.0', 'tqdm'],
},
)
# If pytest is installed, add it to setup_requires
try:
import pytest
metadata['setup_requires'] = ['pytest-runner']
except:
pass
cwd = osp.abspath(osp.dirname(__file__))
if not osp.exists(osp.join(cwd, 'PKG-INFO')):
# Generate Cython sources, unless building from source release
# generate_cython()
pass
# Generate configuration
def configuration(parent_package='', top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration(None, parent_package, top_path)
config.set_options(ignore_setup_xxx_py=True,
assume_default_configuration=True,
delegate_options_to_subpackages=True,
quiet=True)
config.add_subpackage('sisl')
config.get_version('sisl/info.py')
return config
# With credits from NUMPY developers we use this
# routine to get the git-tag
def git_version():
global GIT_REVISION
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 = osp.dirname(osp.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'])
# Get latest tag
tag = _minimal_ext_cmd(['git', 'describe', '--abbrev=0'])
# Get number of commits since tag
count = _minimal_ext_cmd(['git', 'rev-list', tag + '..', '--count'])
if len(count) == 0:
count = '1'
except:
# Retain the revision name
rev = GIT_REVISION
# Assume it is on tag
count = '0'
return rev, int(count)
def write_version(filename='sisl/info.py'):
version_str = """# This file is automatically generated from sisl setup.py
released = {released}
# 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]}
version = '.'.join(map(str,[major, minor, micro]))
release = version
if git_count > 2 and not released:
# Add git-revision to the version string
version += '+' + str(git_count)
# BibTeX information if people wish to cite
bibtex = '''@misc{{{{zerothi_sisl,
author = {{{{Papior, Nick R.}}}},
title = {{{{sisl: v{{0}}}}}},
doi = {{{{10.5281/zenodo.597181}}}},
url = {{{{https://doi.org/10.5281/zenodo.597181}}}},
}}}}'''.format(version)
def cite():
return bibtex
"""
# If we are in git we try and fetch the
# git version as well
GIT_REV, GIT_COUNT = git_version()
with open(filename, 'w') as fh:
fh.write(version_str.format(version=[MAJOR, MINOR, MICRO],
released=ISRELEASED,
count=GIT_COUNT,
git=GIT_REV))
if __name__ == '__main__':
# First figure out if we should define the
# version file
try:
only_idx = sys.argv.index('only-version')
except:
only_idx = 0
if only_idx > 0:
# Figure out if we should write a specific file
print("Only creating the version file")
if len(sys.argv) > only_idx + 1:
vF = sys.argv[only_idx+1]
write_version(vF)
else:
write_version()
sys.exit(0)
try:
# Create version file
# if allowed
write_version()
except Exception as e:
print('Could not write sisl/info.py:')
print(str(e))
# Be sure to import this before numpy setup
from setuptools import setup
try:
# Now we import numpy distutils for installation.
# Note that this should work, also when
from numpy.distutils.core import setup
metadata['configuration'] = configuration
except:
if ISRELEASED:
metadata['version'] = VERSION
else:
metadata['version'] = VERSION + '-dev'
if 'sdist' in sys.argv:
from distutils.command.sdist import sdist
metadata['cmdclass'] = {'sdist': sdist}
# Main setup of python modules
setup(**metadata)