-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathsetup.py
More file actions
119 lines (91 loc) · 3.5 KB
/
setup.py
File metadata and controls
119 lines (91 loc) · 3.5 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
import os
import pathlib
import sys
import importlib.util
from setuptools import setup
from setuptools.command.build_py import build_py
from setuptools.command.develop import develop
from setuptools.command.install import install
sys.path.append(str(pathlib.Path(__file__).parent.resolve()))
current_directory = pathlib.Path(__file__).parent.resolve()
class ResourceGeneratorMixin:
"""
Mixin class that provides common resource generation functionality for
setuptools commands.
"""
def _should_build_docs(self):
"""Determine if documentation should be built based on environment variable."""
# Set this environment variable to build docs:
# IMAS_BUILD_DOCS=1 pip install .
build_docs_flag = os.getenv("IMAS_BUILD_DOCS", "").strip().lower()
build_docs = build_docs_flag in ("1", "true", "yes")
if build_docs:
print("[IMAS-DD] Documentation build enabled via IMAS_BUILD_DOCS")
return build_docs
def generate_resources(self, include_docs=False):
"""Generate all necessary resources for the data dictionary package."""
from generate import (
generate_dd_data_dictionary,
generate_dd_data_dictionary_validation,
generate_idsnames,
)
from install import install_dd_files, install_identifiers_files
# Generate the data dictionary files
generate_dd_data_dictionary()
generate_idsnames()
generate_dd_data_dictionary_validation()
# Generate documentation if requested
if include_docs:
from generate import (
generate_html_documentation,
generate_ids_cocos_transformations_symbolic_table,
generate_idsdef_js,
)
from install import (
install_html_docs,
)
generate_html_documentation()
generate_ids_cocos_transformations_symbolic_table()
generate_idsdef_js()
install_html_docs()
# Create the resources directory in the package
install_dd_files()
install_identifiers_files()
class CustomInstallCommand(install, ResourceGeneratorMixin):
"""Custom install command that handles DD files generation and installation."""
description = "DD files generation"
paths = []
def run(self):
from install import (
install_identifiers_files,
)
# Determine if docs should be built
include_docs = self._should_build_docs()
# Generate resources using mixin
self.generate_resources(include_docs=include_docs)
# Additional install steps specific to full installation
install_identifiers_files()
super().run()
class BuildPyCommand(build_py, ResourceGeneratorMixin):
"""Custom build command that generates resources before building."""
def run(self):
include_docs = self._should_build_docs()
self.generate_resources(include_docs=include_docs)
super().run()
class DevelopCommand(develop, ResourceGeneratorMixin):
"""
Custom develop command that generates resources before installing in
development mode.
"""
def run(self):
include_docs = self._should_build_docs()
self.generate_resources(include_docs=include_docs)
super().run()
if __name__ == "__main__":
setup(
cmdclass={
"install": CustomInstallCommand,
"build_py": BuildPyCommand,
"develop": DevelopCommand,
},
)