-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
245 lines (200 loc) · 6.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
242
243
244
245
#!/usr/bin/env python
# SPDX-FileCopyrightText: Copyright 2021, Siavash Ameli <sameli@berkeley.edu>
# SPDX-License-Identifier: BSD-3-Clause
# SPDX-FileType: SOURCE
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the license found in the LICENSE.txt file in the root
# directory of this source tree.
# =======
# Imports
# =======
from __future__ import print_function
import os
from os.path import join
import sys
import subprocess
import codecs
import errno
# ===============
# install package
# ===============
def install_package(package):
"""
Installs packages using pip.
Example:
.. code-block:: python
>>> install_package('numpy>1.11')
:param package: Name of package with or without its version pin.
:type package: string
"""
subprocess.check_call([sys.executable, "-m", "pip", "install",
"--prefer-binary", package])
# =====================
# Import Setup Packages
# =====================
# Import setuptools
try:
import setuptools
except ImportError:
# Install setuptools
install_package('setuptools')
import setuptools
# =========
# Read File
# =========
def read_file(filename):
"""
Reads a file with Latin codec.
"""
with codecs.open(filename, 'r', 'latin') as file_obj:
return file_obj.read()
# ================
# Read File to RST
# ================
def read_file_to_rst(filename):
"""
Reads a markdown text file and converts it to RST file using pandas.
"""
try:
import pypandoc
rstname = "{}.{}".format(os.path.splitext(filename)[0], 'rst')
pypandoc.convert(
filename,
'rst',
format='markdown',
outputfile=rstname)
with open(rstname, 'r') as f:
rststr = f.read()
return rststr
except ImportError:
return read_file(filename)
# ================
# get requirements
# ================
def get_requirements(directory, subdirectory="", filename='requirements',
ignore=False):
"""
Returns a list containing the package requirements given in a file named
"requirements.txt" in a subdirectory.
If `ignore` is `True` and the file was not found, it passes without raising
error. This is useful when the package is build without
`docs/requirements.txt` and `tests/requirements.txt`, such as in the docker
where the folders `docs` and `tests` are not copied to the docker image.
See `.dockerignore` file.
"""
requirements_filename = join(directory, subdirectory, filename + ".txt")
# Check file exists
if os.path.exists(requirements_filename):
requirements_file = open(requirements_filename, 'r')
requirements = [i.strip() for i in requirements_file.readlines()]
else:
# Ignore if file was not found.
if ignore:
requirements = ''
else:
raise FileNotFoundError(
errno.ENOENT, os.strerror(errno.ENOENT), requirements_filename)
return requirements
# ====
# main
# ====
def main(argv):
directory = os.path.dirname(os.path.realpath(__file__))
package_name = "restoreio"
# Version
version_dummy = {}
version_file = join(directory, package_name, '__version__.py')
exec(open(version_file, 'r').read(), version_dummy)
version = version_dummy['__version__']
del version_dummy
# Author
author_file = join(directory, 'AUTHORS.txt')
author = open(author_file, 'r').read().rstrip()
# Requirements
requirements = get_requirements(directory)
test_requirements = get_requirements(directory, subdirectory="tests",
ignore=True)
docs_requirements = get_requirements(directory, subdirectory="docs",
ignore=True)
# ReadMe
readme_file = join(directory, 'README.rst')
long_description = open(readme_file, 'r').read()
# Description
description = 'Reconstruct incomplete oceanographic dataset'
# URLs
url = 'https://github.com/ameli/restoreio'
download_url = url + '/archive/main.zip'
documentation_url = url + '/blob/main/README.rst'
tracker_url = url + '/issues'
# Inputs to setup
metadata = dict(
name=package_name,
version=version,
author=author,
author_email='sameli@berkeley.edu',
description=description,
long_description=long_description,
long_description_content_type='text/x-rst',
keywords="""reconstruct-data oceanographic-data hf-radar""",
url=url,
download_url=download_url,
project_urls={
"Documentation": documentation_url,
"Source": url,
"Tracker": tracker_url,
},
platforms=['Linux', 'OSX', 'Windows'],
packages=setuptools.find_packages(exclude=[
'tests.*',
'tests',
'examples.*',
'docs.*',
'docs']
),
install_requires=requirements,
python_requires='>=3.9',
setup_requires=[
'setuptools',
'wheel'],
tests_require=[
'pytest',
'pytest-cov'],
include_package_data=True,
zip_safe=False, # False: package can be "cimported" by another package
extras_require={
'test': test_requirements,
'docs': docs_requirements,
},
entry_points={
"console_scripts": [
"restore = restoreio.__main__:main",
"restore-scan = restoreio._scripts.scan:main"
]
},
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: Implementation :: CPython',
'License :: OSI Approved :: BSD License',
'Operating System :: POSIX :: Linux',
'Operating System :: Microsoft :: Windows',
'Operating System :: MacOS',
'Natural Language :: English',
'Intended Audience :: Science/Research',
'Intended Audience :: Developers',
'Topic :: Software Development',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Scientific/Engineering',
],
)
# Setup
setuptools.setup(**metadata)
# =============
# script's main
# =============
if __name__ == "__main__":
main(sys.argv)