-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
190 lines (161 loc) · 5.86 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
"""
This is not your grannie's setup, mainly because of how we build documentation.
Documentation is built by Sphinx. Some of that documentation is in this repo,
and some is copied in from other repos (namely, PDP frontends in separate
projects). This is handled by the code in class ``ExtendedBuildDoc``, which
extends the Sphinx supplied command class ``BuildDoc``.
Also worth noting is the installation sequence that must be followed in order to
build documentation successfully. We must do the following double-install::
pip install .
python setup.py build_sphinx
pip install .
The first installation accomplishes two things:
* make project version number available to Sphinx
* install dependencies required by ``ExtendedBuildDoc``
The second installation makes the docs available.
These things could possibly be accomplished without a double installation,
but it's what we've got, and it works. Your grannie is not proud of this.
"""
import os
import sys
from warnings import warn
import re
from setuptools import setup
from setuptools.command.test import test as TestCommand
from git import Repo
from git.exc import InvalidGitRepositoryError
try:
from sphinx.setup_command import BuildDoc
except ImportError:
warn("Could not import sphinx. You won't be able to build the docs")
__version__ = "4.4.1"
class PyTest(TestCommand):
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = ["-v", "--tb=no", "tests"]
self.test_suite = True
def run_tests(self):
# import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(self.test_args)
sys.exit(errno)
class ExtendedBuildDoc(BuildDoc):
def run(self):
# Import here because deps cannot be ready first time setup.py is run.
# See note in docstring re. double installation.
try:
from pdp.doc_helpers import download_external_docs_from_github
except ImportError:
warn(
"Could not import doc_helpers. "
"You may have missed the pre-installation step. "
"Documents NOT BUILT."
)
return
def target_dir(subdir):
return os.path.join(self.source_dir, subdir)
#####
# Download external documentation.
# When an external portal is added, add its documentation download here.
####
download_external_docs_from_github(
project="station-data-portal",
branch="master",
target_dir=target_dir("mdp"),
)
# Build the documentation
BuildDoc.run(self)
def recursive_list(pkg_dir, basedir):
def find():
for dirname, dirnames, filenames in os.walk(basedir):
for filename in filenames:
yield os.path.join(dirname, filename).replace(pkg_dir, "", 1)
return [x for x in find()]
def get_commitish():
# The statement `Repo(...)` below raises `InvalidGitRepositoryError`
# when building in the Python CI workflow, specifically on the step
# `pip install .` (of course; that step runs this file). According to
# https://github.com/gitpython-developers/GitPython/issues/255,
# adding `search_parent_directories=True` should fix it, but it doesn't.
# Instead, we just bail out and return "unknown" in this case. That allows
# the test environment to build.
try:
repo = Repo(os.getcwd(), search_parent_directories=True)
except InvalidGitRepositoryError:
return "unknown"
sha = repo.head.object.hexsha
try:
branch = repo.active_branch.name
except TypeError:
branch = "detached.HEAD"
safe_branch = re.sub("[-/_]", ".", branch)
return "{}.{}".format(safe_branch, repo.git.rev_parse(sha, short=6))
__revision__ = get_commitish()
setup(
name="pdp",
description="PCIC's Data Portal (pdp): the server software to run the "
"entire web application",
keywords="opendap dods dap open data science climate meteorology "
"downscaling modelling",
packages=["pdp", "pdp.portals"],
version="%s+%s" % (__version__, __revision__),
url="http://www.pacificclimate.org/",
author="James Hiebert",
author_email="hiebert@uvic.ca",
install_requires=[
"flask",
"beaker",
"genshi",
"static",
"pdp-util >=1.2.1",
"modelmeta >=0.3.0",
"pydap.handlers.hdf5 >=0.5",
"pydap.responses.netcdf >=0.5",
"pydap.responses.xls",
"pydap.handlers.sql",
"ga-wsgi-client",
"slimit",
"netCDF4<1.5.6",
],
tests_require=[
"webob",
"pytest",
"xlrd",
"pillow",
"numpy",
"BeautifulSoup4",
],
scripts=["scripts/rast_serve.py"],
package_dir={"pdp": "pdp"},
package_data={
"pdp": [
"templates/*.html",
"resources/hydro_stn_cmip5.yaml",
]
+ recursive_list("pdp/", "pdp/static")
+ recursive_list("pdp/", "pdp/docs/html")
},
cmdclass={"test": PyTest, "build_sphinx": ExtendedBuildDoc},
command_options={"build_sphinx": {"build_dir": ("setup.py", "pdp/docs")}},
zip_safe=False,
classifiers="""Development Status :: 5 - Production/Stable
Environment :: Console
Environment :: Web Environment
Framework :: Flask
Natural Language :: English
Intended Audience :: Developers
Intended Audience :: Science/Research
License :: OSI Approved :: GNU General Public License (GPL)
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 2.7
Topic :: Internet
Topic :: Internet :: WWW/HTTP :: WSGI
Topic :: Internet :: WWW/HTTP :: WSGI :: Application
Topic :: Scientific/Engineering
Topic :: Scientific/Engineering :: Atmospheric Science
Topic :: Scientific/Engineering :: GIS
Topic :: Software Development :: Libraries :: Python Modules""".split(
"\n"
),
)