-
Notifications
You must be signed in to change notification settings - Fork 14
/
setup.py
241 lines (208 loc) · 8.6 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of SIFT.
#
# SIFT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# SIFT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SIFT. If not, see <http://www.gnu.org/licenses/>.
"""Setuptools installation script for the SIFT python package.
To install from source run the following command::
python setup.py install
To install for development replace 'install' with 'develop' in the above
command.
.. note::
PyQt5 is required for GUI operations, but must be install manually
since it is not 'pip' installable.
For Developers
--------------
To bump the version run:
python setup.py bump -b minor -d alpha
Or to tag and commit the new version:
python setup.py bump -b major -t -c
See the `-h` options for more info.
"""
import os
import re
from setuptools import Command, find_packages, setup
script_dir = os.path.dirname(os.path.realpath(__file__))
version_pathname = os.path.join(script_dir, "uwsift", "version.py")
version_str = open(version_pathname).readlines()[-1].split()[-1].strip("\"'")
version_regex = re.compile(
r"^(?P<major>\d+)\.(?P<minor>\d+)\.(?P<micro>\d+)(?:(?P<dev_level>(a|b|rc))(?P<dev_version>\d))?$"
)
version_match = version_regex.match(version_str)
assert version_match is not None, "Invalid version in version.py: {}".format(version_str) # nosec B101
version_info = version_match.groupdict()
version_info["major"] = int(version_info["major"])
version_info["minor"] = int(version_info["minor"])
version_info["micro"] = int(version_info["micro"])
version_info["dev_version"] = int(version_info["dev_version"] or 0)
extras_require = {
"docs": ["blockdiag", "sphinx", "sphinx_rtd_theme", "sphinxcontrib-seqdiag", "sphinxcontrib-blockdiag", "psutil"],
"profiling": ["psutil"],
}
class BumpCommand(Command):
description = "bump package version by one micro, minor, or major version number (major.minor.micro[a/b])"
user_options = [
("bump-level=", "b", "major, minor, micro (default: None)"),
("dev-level=", "d", "alpha, beta, rc (default: None)"),
("new-version=", "v", "specify exact new version number (default: None"),
("dry-run", "n", "dry run, don't change anything"),
("tag", "t", "add a git tag for this version (default: False)"),
("commit", "c", "Run the git commit command but do not push (default: False)"),
]
boolean_options = ["dry_run", "tag", "commit"]
def initialize_options(self):
self.bump_level = None
self.dev_level = None
self.new_version = None
self.dry_run = False
self.tag = False
self.commit = False
def finalize_options(self):
if self.bump_level not in ["major", "minor", "micro", None]:
raise ValueError("Bump level must be one of ['major', 'minor', 'micro', <unspecified>]")
if self.dev_level not in ["alpha", "beta", "rc", None]:
raise ValueError("Dev level must be one of ['alpha', 'beta', <unspecified>]")
def run(self):
current_version = version_info
new_version = current_version.copy()
if self.new_version is not None:
new_version_str = self.new_version
assert version_regex.match(new_version_str) is not None # nosec B101
else:
if self.bump_level == "micro":
new_version["micro"] += 1
elif self.bump_level == "minor":
new_version["minor"] += 1
new_version["micro"] = 0
elif self.bump_level == "major":
new_version["major"] += 1
new_version["minor"] = 0
new_version["micro"] = 0
new_version_str = "{major:d}.{minor:d}.{micro:d}".format(**new_version)
if self.dev_level:
short_level = {"alpha": "a", "beta": "b", "rc": "rc"}[self.dev_level]
if current_version["dev_level"] == short_level and self.bump_level is None:
new_dev_version = current_version["dev_version"] + 1
else:
new_dev_version = 0
new_version_str += "{:s}{:d}".format(short_level, new_dev_version)
# Update the version test in the version.py file
print("Old Version: {}".format(version_str))
print("New Version: {}".format(new_version_str))
if self.dry_run:
print("### Dry Run: No modifications ###")
return
# Update the version.py
print("Updating version.py...")
version_data = open(version_pathname, "r").read()
version_data = version_data.replace(
'__version__ = "{}"'.format(version_str), '__version__ = "{}"'.format(new_version_str)
)
open(version_pathname, "w").write(version_data)
# Updating Windows Inno Setup file
# XXX: Once PyInstaller executable is properly encoded with version this may be removed after proper fixes
print("Updating Inno Setup Version number...")
iss_pathname = os.path.join(script_dir, "sift.iss")
file_data = open(iss_pathname, "rb").read()
_old = "AppVersion={}".format(version_str).encode()
_new = "AppVersion={}".format(new_version_str).encode()
file_data = file_data.replace(_old, _new)
open(iss_pathname, "wb").write(file_data)
# Tag git repository commit
add_args = ["git", "add", version_pathname, iss_pathname]
commit_args = ["git", "commit", "-m", "Bump version from {} to {}".format(version_str, new_version_str)]
if self.commit:
import subprocess # nosec
print("Adding files to git staging area...")
subprocess.check_call(add_args) # nosec
print("Committing changes...")
subprocess.check_call(commit_args) # nosec
else:
commit_args[-1] = '"' + commit_args[-1] + '"'
print("To appropriate files:")
print(" ", " ".join(add_args))
print("To commit after run:")
print(" ", " ".join(commit_args))
tag_args = ["git", "tag", "-a", new_version_str, "-m", "Version {}".format(new_version_str)]
if self.tag:
print("Tagging commit...")
subprocess.check_call(tag_args) # nosec
else:
tag_args[-1] = '"' + tag_args[-1] + '"'
print("To tag:")
print(" ", " ".join(tag_args))
print("To push git changes to remote, run:\n git push --follow-tags")
readme = open(os.path.join(script_dir, "README.md")).read()
setup(
name="uwsift",
version=version_str,
description="Satellite Information Familiarization Tool",
long_description=readme,
long_description_content_type="text/markdown",
author="SIFT Developers",
author_email="rkgarcia@wisc.edu",
url="https://github.com/ssec/sift",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: GNU General Public License v3 " + "or later (GPLv3+)",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering",
],
zip_safe=False,
include_package_data=True,
install_requires=[
"appdirs",
"donfig>=0.8.1",
"h5py",
"imageio",
"av",
"matplotlib",
"netCDF4",
"numba",
"numpy",
"pillow",
"pyproj",
"pyqt5>=5.15",
"pyqtgraph",
"pyqtwebengine",
"pyshp",
"pyyaml",
"rasterio",
"satpy",
"scikit-image",
"shapely",
"sqlalchemy",
"trollsift",
"vispy>=0.10.0",
'pygrib;sys_platform=="linux" or sys_platform=="darwin"',
"ecmwflibs",
"eccodes",
"cfgrib",
],
tests_requires=["pytest", "pytest-qt", "pytest-mock"],
python_requires=">=3.8, <=3.11", # limiting to 3.11 until ecmwflibs is not available for 3.12
extras_require=extras_require,
packages=find_packages(),
entry_points={
"console_scripts": [
"SIFT = uwsift.__main__:main",
],
},
cmdclass={
"bump": BumpCommand,
},
)