forked from SciTools/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
89 lines (65 loc) · 2.37 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
import os
import sys
from setuptools import Command, setup
from setuptools.command.build_py import build_py
from setuptools.command.develop import develop
class BaseCommand(Command):
"""A minimal no-op setuptools command."""
description: str = "A no-op command."
user_options: list = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
pass
def custom_command(cmd, help=""):
"""
Factory function to generate a custom command that adds additional
behaviour to build the CF standard names module.
"""
class CustomCommand(cmd):
description = help or cmd.description
def _build_std_names(self, directory):
# Call out to tools/generate_std_names.py to build std_names module.
script_path = os.path.join("tools", "generate_std_names.py")
xml_path = os.path.join("etc", "cf-standard-name-table.xml")
module_path = os.path.join(directory, "iris", "std_names.py")
args = (sys.executable, script_path, xml_path, module_path)
self.spawn(args)
def finalize_options(self):
# Execute the parent "cmd" class method.
cmd.finalize_options(self)
if (
not hasattr(self, "editable_mode")
or self.editable_mode is None
):
# Default to editable i.e., applicable to "std_names" and
# and "develop" commands.
self.editable_mode = True
def run(self):
# Execute the parent "cmd" class method.
cmd.run(self)
# Determine the target root directory
if self.editable_mode:
# Pick the source dir instead (currently in the sub-dir "lib").
target = "lib"
msg = "in-place"
else:
# Not editable - must be building.
target = self.build_lib
msg = "as-build"
print(f"\n[Running {msg}]")
# Build the CF standard names.
self._build_std_names(target)
return CustomCommand
custom_commands = {
"develop": custom_command(develop),
"build_py": custom_command(build_py),
"std_names": custom_command(
BaseCommand, help="generate CF standard names"
),
}
setup(
cmdclass=custom_commands,
)