-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathsetup.py
More file actions
123 lines (98 loc) · 2.99 KB
/
setup.py
File metadata and controls
123 lines (98 loc) · 2.99 KB
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
"""
FOREST - Forecast and Observation Research and Evaluation Survey Tool
"""
import platform
import os
import re
import subprocess
import setuptools
import setuptools.command.build_py
import setuptools.command.develop
import setuptools.command.install
NAME = "forest"
JS_DIR = os.path.join(os.path.dirname(__file__), NAME, r"js")
def cross_platform(cmd):
"""Support Windows
:param cmd: list of str
"""
if platform.system().lower() == "windows":
return subprocess.check_call(" ".join(cmd), shell=True)
else:
return subprocess.check_call(cmd)
def find_version():
"""locate package version from forest/__init__.py"""
path = os.path.join(os.path.dirname(__file__), NAME, "__init__.py")
with open(path) as stream:
contents = stream.read()
match = re.search(
r"^__version__ = ['\"']([0-9\.]*)['\"']", contents, re.MULTILINE
)
if match:
return match.group(1)
else:
raise RuntimeError("Unable to find version number")
def load(fname):
result = []
with open(fname, "r") as fi:
result = [package.strip() for package in fi.readlines()]
return result
def build_js(command_subclass):
"""Decorator to call npm install and npm run build"""
subclass_run = command_subclass.run
def run(self):
self.run_command("build_js")
subclass_run(self)
command_subclass.run = run
return command_subclass
@build_js
class InstallCommand(setuptools.command.install.install):
"""Python and JS code"""
@build_js
class DevelopCommand(setuptools.command.develop.develop):
"""Python and JS code"""
@build_js
class BuildPyCommand(setuptools.command.build_py.build_py):
"""Python and JS code"""
class BuildJSCommand(setuptools.command.build_py.build_py):
"""Use nodejs and npm commands to browserify forest.js
.. note:: Assume current working directory is package ROOT
"""
def run(self):
cwd = os.getcwd()
os.chdir(JS_DIR)
if not os.path.exists("node_modules"):
cross_platform(["npm", "install"])
cross_platform(["npm", "run", "build"])
os.chdir(cwd)
super().run()
setuptools.setup(
name=NAME,
version=find_version(),
author="Andrew Ryan",
author_email="andrew.ryan@metoffice.gov.uk",
cmdclass={
"install": InstallCommand,
"develop": DevelopCommand,
"build_py": BuildPyCommand,
"build_js": BuildJSCommand,
},
description="Forecast visualisation and survey tool",
packages=setuptools.find_packages(),
package_data={
"forest": [
"templates/index.html",
"static/*",
"tutorial/*.json",
"tutorial/*.nc",
"tutorial/NAME/*.txt",
]
},
test_suite="test",
tests_require=load("requirements-dev.txt"),
extras_require={':python_version == "3.6"': ["dataclasses"]},
entry_points={
"console_scripts": [
"forest=forest.cli.alternative:app",
]
},
)