-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·216 lines (189 loc) · 6.45 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
#!/usr/bin/env python
"""BGCVal2 installation script."""
# This script only installs dependencies available on PyPI
import json
import os
import re
import sys
from pathlib import Path
from setuptools import Command, setup
sys.path.insert(0, os.path.dirname(__file__))
PACKAGES = [
'bgcval2',
]
REQUIREMENTS = {
# Installation script (this file) dependencies
'setup': [
'setuptools_scm',
],
# Installation dependencies
# Use with pip install . to install from source
'install': [
'basemap>=1.3.6',
'cartopy',
'jsondiff',
'matplotlib',
'nctoolkit>=0.8.7', # use linux64 build
'netcdf4',
'numpy>1.24.3,<2.0',
'pip!=21.3',
'pyyaml',
'scikit-learn',
'scipy>=1.6',
],
# Test dependencies
# Execute 'python setup.py test' to run tests
'test': [
'flake8',
'scitools-iris>=3.4.0',
'pytest>=3.9,!=6.0.0rc1,!=6.0.0',
'pytest-cov>=2.10.1',
'pytest-env',
'pytest-html!=2.1.0',
'pytest-metadata>=1.5.1',
'pytest-mypy',
'pytest-mock',
'pytest-xdist',
],
# Development dependencies
# Use pip install -e .[develop] to install in development mode
'develop': [
'autodocsumm',
'codespell',
'docformatter',
'isort',
'pre-commit',
'prospector[with_pyroma,with_mypy]>=1.9.0',
'sphinx>=5',
'sphinx_rtd_theme',
'vprof',
'yamllint',
'yapf',
],
}
def discover_python_files(paths, ignore):
"""Discover Python files."""
def _ignore(path):
"""Return True if `path` should be ignored, False otherwise."""
return any(re.match(pattern, path) for pattern in ignore)
for path in sorted(set(paths)):
for root, _, files in os.walk(path):
if _ignore(path):
continue
for filename in files:
filename = os.path.join(root, filename)
if (filename.lower().endswith('.py')
and not _ignore(filename)):
yield filename
class CustomCommand(Command):
"""Custom Command class."""
def install_deps_temp(self):
"""Try to temporarily install packages needed to run the command."""
if self.distribution.install_requires:
self.distribution.fetch_build_eggs(
self.distribution.install_requires)
if self.distribution.tests_require:
self.distribution.fetch_build_eggs(self.distribution.tests_require)
class RunLinter(CustomCommand):
"""Class to run a linter and generate reports."""
user_options: list = []
def initialize_options(self):
"""Do nothing."""
def finalize_options(self):
"""Do nothing."""
def run(self):
"""Run prospector and generate a report."""
check_paths = PACKAGES + [
'setup.py',
'tests',
]
ignore = [
'doc/',
]
# try to install missing dependencies and import prospector
try:
from prospector.run import main
except ImportError:
# try to install and then import
self.distribution.fetch_build_eggs(['prospector[with_pyroma]'])
from prospector.run import main
self.install_deps_temp()
# run linter
# change working directory to package root
package_root = os.path.abspath(os.path.dirname(__file__))
os.chdir(package_root)
# write command line
files = discover_python_files(check_paths, ignore)
sys.argv = ['prospector']
sys.argv.extend(files)
# run prospector
errno = main()
sys.exit(errno)
def read_authors(filename):
"""Read the list of authors from .zenodo.json file."""
with Path(filename).open() as file:
info = json.load(file)
authors = []
for author in info['creators']:
name = ' '.join(author['name'].split(',')[::-1]).strip()
authors.append(name)
return ', '.join(authors)
setup(
name='BGCVal2',
version="1.0",
author=read_authors(".zenodo.json"),
description="BGCVal2: modernized version of BGCVal",
long_description=Path('README.md').read_text(),
long_description_content_type='text/markdown',
url='https://github.com/valeriupredoi/bgcval2',
download_url='https://github.com/valeriupredoi/bgcval2',
license='probably GPL',
classifiers=[
'Development Status :: 0 - initial',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: probably GPL',
'Natural Language :: English',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Atmospheric Science',
'Topic :: Scientific/Engineering :: GIS',
'Topic :: Scientific/Engineering :: Hydrology',
'Topic :: Scientific/Engineering :: Physics',
],
packages=PACKAGES,
# Include all version controlled files
include_package_data=True,
setup_requires=REQUIREMENTS['setup'],
install_requires=REQUIREMENTS['install'],
tests_require=REQUIREMENTS['test'],
extras_require={
'develop': REQUIREMENTS['develop'] + REQUIREMENTS['test'],
'test': REQUIREMENTS['test'],
},
entry_points={
'console_scripts': [
'analysis_compare = bgcval2.analysis_compare:main',
'analysis_level3_amoc = bgcval2.analysis_level3_amoc:main',
'analysis_level3_dms = bgcval2.analysis_level3_dms:main',
'analysis_level3_omz = bgcval2.analysis_level3_omz:main',
'analysis_level3_sameYear = bgcval2.analysis_level3_sameYear:main',
'analysis_p2p = bgcval2.analysis_p2p:run',
'analysis_timeseries = bgcval2.analysis_timeseries:main',
'batch_timeseries = bgcval2.batch_timeseries:main',
'download_from_mass = bgcval2.download_from_mass:main',
'bgcval2_make_report = bgcval2.bgcval2_make_report:main',
],
},
cmdclass={
# 'test': RunTests,
'lint': RunLinter,
},
zip_safe=False,
)