-
Notifications
You must be signed in to change notification settings - Fork 12
/
setup.py
138 lines (118 loc) · 4.08 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
#!/usr/bin/env python3
import subprocess
import sys
from setuptools import setup
from setuptools.command.develop import develop
from setuptools.command.install import install
from pathlib import Path
# python root namespace package
# this namespace package follows PEP420
# https://packaging.python.org/guides/packaging-namespace-packages/#native-namespace-packages
# This namespace package structure and configuration follows a pattern
# presented here:
# https://medium.com/@jherreras/python-microlibs-5be9461ad979
NAMESPACE_PACKAGE_NAME = "evaluation_tools"
# Package author information
AUTHOR = "Jason Regina"
AUTHOR_EMAIL = "jason.regina@noaa.gov"
MAINTAINER = "Austin Raney"
MAINTAINER_EMAIL = "arthur.raney@noaa.gov"
# Namespace package version
VERSION = "1.3.5+1"
URL = "https://github.com/NOAA-OWP/evaluation_tools"
# Map subpackage namespace to relative location
# key: Subpackage slug, value: subpackage relative location
SUBPACKAGES = {
"evaluation_tools.nwis_client": "python/nwis_client",
"evaluation_tools._restclient": "python/_restclient",
"evaluation_tools.gcp_client": "python/gcp_client",
"evaluation_tools.events": "python/events",
"evaluation_tools.metrics": "python/metrics",
}
# Short sub-package description
DESCRIPTION = (
"Suite of tools for retrieving USGS NWIS observations and evaluating "
"National Water Model (NWM) data."
)
# Read information from relevant package files
LONG_DESCRIPTION = Path("README.md").read_text()
LICENSE = Path("LICENSE").read_text()
# Package dependency requirements
REQUIREMENTS = []
# Development requirements
DEVELOPMENT_REQUIREMENTS = ["pytest"]
def install_subpackages(sources: dict, develop_flag: bool = False) -> None:
"""Install all subpackages in a namespace package
Parameters
----------
sources : dict
key: subpackage slug, value: subpackage relative location
develop_flag : bool, optional
Install in normal or development mode, by default normal
"""
# absolute path
ROOT_DIR = Path(__file__).resolve().parent
for k, v in sources.items():
try:
subpackage_dir = str(ROOT_DIR / v)
if develop_flag:
subprocess.check_call(
[
sys.executable,
"-m",
"pip",
"install",
"-e",
subpackage_dir,
]
)
else:
subprocess.check_call(
[
sys.executable,
"-m",
"pip",
"install",
subpackage_dir,
]
)
except Exception as e:
error_message = "An error occurred when installing %s" % (k,)
raise Exception(error_message) from e
# Normal installation
class Install(install):
def run(self):
install_subpackages(SUBPACKAGES, develop_flag=False)
super().run()
# Development installation
class Develop(develop):
def run(self):
install_subpackages(SUBPACKAGES, develop_flag=True)
# Install development requirements
for dev_requirement in DEVELOPMENT_REQUIREMENTS:
subprocess.check_call(
[sys.executable, "-m", "pip", "install", dev_requirement]
)
setup(
name=NAMESPACE_PACKAGE_NAME,
version=VERSION,
author=AUTHOR,
author_email=AUTHOR_EMAIL,
maintainer=MAINTAINER,
maintainer_email=MAINTAINER_EMAIL,
classifiers=[
"Private :: Do Not Upload to pypi server",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
url=URL,
license=LICENSE,
install_requires=REQUIREMENTS,
extras_require={"test": DEVELOPMENT_REQUIREMENTS},
python_requires=">=3.7",
cmdclass={"install": Install, "develop": Develop},
)