Debian Codegraph @

externals/OPTIMADE/tests/makefiles/Makelocal-schemas

raw
1 #---*- Makefile -*-------------------------------------------------------
2
3 # Use "make schemas schemas_html_pretty=true" to apply OPTIMADE styling to the html pages
4
5 # Use "make schemas schemas_html_ext=true" to generate html files with .html extensions also for files meant to be served
6 # without extensions, which is useful for hosting, e.g., on github that automatically redirects URLs without extensions.
7
8 # Dependencies from optimade-property-tools
9 PROCESS_SCHEMAS=dependencies/submodules/optimade-property-tools/bin/process_schemas
10 EXT_SCHEMAS := $(filter-out dependencies/submodules/optimade-property-tools/external/json-schema/LICENSE, $(wildcard dependencies/submodules/optimade-property-tools/external/json-schema/*))
11
12 BASEDIR = schemas/src/defs/
13 BASEID = https://schemas.optimade.org/defs/
14
15 BASEDIR_META = schemas/src/meta/
16 BASEID_META = https://schemas.optimade.org/meta/
17
18 ifeq ($(origin schemas_html_pretty), undefined)
19 OPTIMADE_HTML_HEADER ?=
20 OPTIMADE_HTML_TOP ?=
21 else
22 OPTIMADE_HTML_HEADER = <link rel="stylesheet" type="text/css" media="screen" href="https://www.optimade.org/assets/css/style.css" /><style>body {background: \#f2f2f2;} html {margin: 0 auto; max-width: 900px;}</style>
23 OPTIMADE_HTML_TOP = <a href="https://www.optimade.org/"><img style="margin: 0.5em; float: left" src="https://avatars0.githubusercontent.com/u/23107754" width="10%" /></a><div style="width: 100%; clear: both"></div>
24 endif
25
26 ALL_SCHEMAS := $(wildcard schemas/src/*/*/*/*/*/*/*.yaml schemas/src/*/*/*/*/*/*.yaml schemas/src/*/*/*/*/*.yaml schemas/src/*/*/*/*.yaml schemas/src/*/*/*.yaml)
27
28 META_SCHEMAS := $(filter schemas/src/meta/%.yaml, $(ALL_SCHEMAS))
29 META_SCHEMAS_JSON := $(patsubst schemas/src/%.yaml,schemas/output/%.json,$(META_SCHEMAS))
30 META_SCHEMAS_ARGS := $(foreach schema,$(META_SCHEMAS_JSON),--schema $(schema))
31
32 DEFINITIONS := $(filter schemas/src/defs/%.yaml, $(ALL_SCHEMAS))
33 DEFINITIONS_JSON := $(patsubst schemas/src/%.yaml,schemas/output/%.json,$(DEFINITIONS))
34 DEFINITIONS_MD := $(patsubst schemas/src/%.yaml,schemas/output/%.md,$(DEFINITIONS))
35
36 OTHER_SCHEMAS := $(filter-out schemas/src/meta/%.yaml,$(filter-out schemas/src/defs/%,$(ALL_SCHEMAS)))
37 OTHER_SCHEMAS_JSON := $(patsubst schemas/src/%.yaml,schemas/output/%.json,$(OTHER_SCHEMAS))
38 OTHER_SCHEMAS_MD := $(patsubst schemas/src/%.yaml,schemas/output/%.md,$(OTHER_SCHEMAS))
39
40 ifeq ($(origin schemas_html_ext), undefined)
41 DEFINITIONS_HTML := $(patsubst schemas/src/%.yaml,schemas/output/%,$(DEFINITIONS))
42 DEFINITIONS_HTML_EXT =
43 else
44 DEFINITIONS_HTML := $(patsubst schemas/src/%.yaml,schemas/output/%.html,$(DEFINITIONS))
45 DEFINITIONS_HTML_EXT = .html
46 endif
47
48 EXT_SCHEMAS_ARGS := $(foreach schema,$(EXT_SCHEMAS),--schema $(schema))
49
50 DEF_INDEXES_HTML = schemas/output/defs/index.html
51 DEF_INDEXES_MD = schemas/output/defs/index.md
52 RELEASES_INDEXES_HTML = schemas/output/releases/latest/index.html
53 RELEASES_INDEXES_MD = schemas/output/releases/latest/index.md
54
55 OPTIMADE_VERSION := $(shell awk 'NR==2 && /OPTIMADE API specification/ { sub(/~develop/, "", $$NF); print $$NF; exit }' optimade.rst)
56
57 ifeq ($(OPTIMADE_VERSION),)
58 OPTIMADE_VERSION_MINOR :=
59 OPTIMADE_VERSION_SUBST :=
60 else
61 OPTIMADE_VERSION_MINOR := "$(basename $(OPTIMADE_VERSION))"
62 OPTIMADE_VERSION_SUBST := --sub '$$$${OPTIMADE_VERSION}' "$(OPTIMADE_VERSION)"
63 endif
64
65 .PHONY: submodule-optimade-property-tools
66
67 submodule-optimade-property-tools:
68 @if [ ! -e "dependencies/submodules/optimade-property-tools/bin/process_schemas" ] ; then \
69 echo "*************************************************************************************************************************"; \
70 echo "ERROR: The optimade-property-tools submodule is required to build the OPTIMADE schemas. Please run the following command:"; \
71 echo "git submodule update --init dependencies/submodules/optimade-property-tools"; \
72 echo "*************************************************************************************************************************"; \
73 false; \
74 elif git submodule status dependencies/submodules/optimade-property-tools | egrep -q '^[-+]' ; then \
75 echo "********************************************************************************************************"; \
76 echo "NOTE: The optimade-property-tools submodule is not in a clean state, if this is unintentional, consider:"; \
77 echo "git submodule update --init dependencies/submodules/optimade-property-tools"; \
78 echo "********************************************************************************************************"; \
79 fi
80
81 .PHONY: schemas schemas_meta schemas_json schemas_docs schemas_html schemas_symlinks schema_releases schemas_indexes_docs schemas_release_indexes_docs
82
83 schemas: submodule-optimade-property-tools schemas_build schemas_releases schemas_release_indexes_docs
84 schemas_build: schemas_symlinks schemas_meta schemas_defs_json schemas_defs_docs schemas_defs_html schemas_other_json schemas_indexes_docs
85 schemas_meta: $(META_SCHEMAS_JSON)
86 schemas_defs_json: $(DEFINITIONS_JSON) schemas_meta
87 schemas_defs_docs: $(DEFINITIONS_MD) schemas_meta
88 schemas_defs_html: $(DEFINITIONS_HTML) schemas_meta
89 schemas_other_json: $(OTHER_SCHEMAS_JSON) schemas_defs_json
90 schemas_indexes_docs: $(DEF_INDEXES_HTML) $(DEF_INDEXES_MD) schemas_meta
91 schemas_release_indexes_docs: $(RELEASES_INDEXES_HTML) $(RELEASES_INDEXES_MD) schemas_meta
92
93 # The 'schemas_symlinks' rule is run before schema builds to try to maintain a structure under '/output' that helps
94 # handling multiple parallel versions of schema definitions. Normally a build would go into a minor version directory (e.g., 'v1.2')
95 # since the source files have to be organized that way for versioned $$inherit to work. The 'schemas_symlinks' rule
96 # symlinks a full version directory (e.g., v1.2.0) to the corresponding minor version directory where the build then goes.
97 # The result is an 'output' that allows a straightforward:
98 #
99 # rsync -a output/ /path/to/arhive/of/versions/
100 #
101 # to do the right thing, where previously generated historical versions remains maintained correctly under '/path/to/arhive/of/versions/'
102 #
103 # Note: output/defs is deliberatly not handled by this rule since updated property defintions with the same ids are meant to replace
104 # older versions in the /defs/<minor version> directories.
105
106 schemas_symlinks:
107 mkdir -p schemas/output/; \
108 cd schemas/output/; \
109 for KIND in meta json-schema json-ld releases; do \
110 if [ ! -e "$$KIND" ]; then \
111 mkdir -p "$$KIND" ;\
112 fi ;\
113 if [ -n "$(OPTIMADE_VERSION)" ]; then \
114 if [ ! -e "$$KIND/$(OPTIMADE_VERSION)" ]; then \
115 mkdir "$$KIND/$(OPTIMADE_VERSION)" ;\
116 fi ;\
117 if [ ! -e "$$KIND/$(OPTIMADE_VERSION_MINOR)" -o -h "$$KIND/$(OPTIMADE_VERSION_MINOR)" ]; then \
118 ln -nsf "$(OPTIMADE_VERSION)" "$$KIND/$(OPTIMADE_VERSION_MINOR)" ;\
119 fi ;\
120 if [ ! -e "$$KIND/latest" -o -h "$$KIND/latest" ]; then \
121 ln -nsf "$(OPTIMADE_VERSION_MINOR)" "$$KIND/latest" ;\
122 fi ;\
123 fi \
124 done
125
126 # The releases directory aggregates this releases versions of all property definitions and is thus
127 # how one finds the definition file that was part of a specific relase.
128 schemas_releases: schemas_build
129 mkdir -p schemas/output/releases/latest
130 cd schemas/output/defs; \
131 find . -type f -exec cp --parents \{\} ../releases/latest \;
132
133 # Old version that keeps only the latest version of all definitions. We may want to go back to this in the future
134 # if these historical definition archives gets too large.
135 #schemas_releases: schemas_build
136 # mkdir -p schemas/output/releases/latest
137 # cd schemas/output/defs; \
138 # for DIR in $$(ls -vrd v*); do \
139 # ( cd "$$DIR"; \
140 # find . -type f -exec cp --parents \{\} ../../releases/latest \; ;\
141 # ) \
142 # done
143
144 # Meta schemas need a separate rule since the other rules depend on the meta schemas for validation (and the meta schemas cannot depend on themselves)
145 $(META_SCHEMAS_JSON): schemas/output/meta/%.json: schemas/src/meta/%.yaml | schemas_symlinks
146 mkdir -p "$(dir $@)"
147 $(PROCESS_SCHEMAS) --remove-null $(OPTIMADE_VERSION_SUBST) --basedir "$(BASEDIR_META)" --baseid "$(BASEID_META)" $(EXT_SCHEMAS_ARGS) --output "$@" "$<"
148
149 $(DEFINITIONS_JSON) $(OTHER_SCHEMAS_JSON): schemas/output/%.json: schemas/src/%.yaml $(META_SCHEMAS_JSON) | schemas_symlinks
150 mkdir -p "$(dir $@)"
151 $(PROCESS_SCHEMAS) --remove-null $(OPTIMADE_VERSION_SUBST) --basedir "$(BASEDIR)" --baseid "$(BASEID)" $(META_SCHEMAS_ARGS) $(EXT_SCHEMAS_ARGS) --output "$@" "$<"
152
153 $(DEFINITIONS_MD): schemas/output/%.md: schemas/src/%.yaml $(META_SCHEMAS_JSON) | schemas_symlinks
154 mkdir -p "$(dir $@)"
155 $(PROCESS_SCHEMAS) --remove-null -f md $(OPTIMADE_VERSION_SUBST) --basedir "$(BASEDIR)" --baseid "$(BASEID)" --output "$@" "$<"
156
157 $(DEFINITIONS_HTML): schemas/output/%$(DEFINITIONS_HTML_EXT): schemas/src/%.yaml $(META_SCHEMAS_JSON) | schemas_symlinks
158 mkdir -p "$(dir $@)"
159 $(PROCESS_SCHEMAS) --remove-null -f html $(OPTIMADE_VERSION_SUBST) --basedir "$(BASEDIR)" --baseid "$(BASEID)" --html-header '$(OPTIMADE_HTML_HEADER)' --html-top '$(OPTIMADE_HTML_TOP)' --output "$@" "$<"
160
161 $(DEF_INDEXES_MD): schemas/output/%/index.md: schemas/src/% $(META_SCHEMAS_JSON) | schemas_symlinks
162 mkdir -p "$(dir $@)"
163 $(PROCESS_SCHEMAS) --index --basedir "$(BASEDIR)" --baseid "$(BASEID)" -f md $(EXT_SCHEMAS_ARGS) --output "$@" "$<"
164
165 $(RELEASES_INDEXES_MD): schemas/output/%/index.md: schemas/output/% $(META_SCHEMAS_JSON) | schemas_symlinks schemas_releases
166 mkdir -p "$(dir $@)"
167 $(PROCESS_SCHEMAS) --index --basedir "$(BASEDIR)" --baseid "$(BASEID)" -f md $(EXT_SCHEMAS_ARGS) --output "$@" "$<"
168
169 $(DEF_INDEXES_HTML): schemas/output/%/index.html: schemas/src/% $(META_SCHEMAS_JSON) | schemas_symlinks
170 mkdir -p "$(dir $@)"
171 $(PROCESS_SCHEMAS) --index --basedir "$(BASEDIR)" --baseid "$(BASEID)" -f html --html-header '$(OPTIMADE_HTML_HEADER)' --html-top '$(OPTIMADE_HTML_TOP)' $(EXT_SCHEMAS_ARGS) --output "$@" "$<"
172
173 $(RELEASES_INDEXES_HTML): schemas/output/%/index.html: schemas/output/% $(META_SCHEMAS_JSON) | schemas_symlinks schemas_releases
174 mkdir -p "$(dir $@)"
175 $(PROCESS_SCHEMAS) --index --basedir "$(BASEDIR)" --baseid "$(BASEID)" -f html --html-header '$(OPTIMADE_HTML_HEADER)' --html-top '$(OPTIMADE_HTML_TOP)' $(EXT_SCHEMAS_ARGS) --output "$@" "$<"
176
177
178 .PHONY: clean clean_schemas
179
180 clean: clean_schemas
181
182 clean_schemas:
183 rm -rf schemas/output
184
185 .PHONY: validate_schemas
186
187 validate_meta_schemas: schemas
188 tests/scripts/validate_json_schema.py schemas/output/meta/latest/optimade/property_definition.json dependencies/submodules/optimade-property-tools/external/json-schema/schema
189 tests/scripts/validate_json_schema.py schemas/output/meta/latest/optimade/physical_unit_definition.json dependencies/submodules/optimade-property-tools/external/json-schema/schema
190
191 validate_schemas: schemas validate_meta_schemas
192 tests/scripts/validate_json_schema.py schemas/tests/example-structures.optimade schemas/output/json-schema/latest/optimade.json
193
194 .PHONY: check_schemas_variables
195
196 schemas_check_variables:
197 @echo "DEFINITIONS = $(DEFINITIONS)"
198 @echo "DEFINITIONS_JSON = $(DEFINITIONS_JSON)"
199 @echo "DEFINITIONS_HTML = $(DEFINITIONS_HTML)"
200 @echo ""
201 @echo "OTHER_SCHEMAS = $(OTHER_SCHEMAS)"
202 @echo "OTHER_SCHEMAS_JSON = $(OTHER_SCHEMAS_JSON)"
203 @echo ""
204 @echo "META_SCHEMAS = $(META_SCHEMAS)"
205 @echo "META_SCHEMAS_JSON = $(META_SCHEMAS_JSON)"
206 @echo "META_SCHEMAS_ARGS = $(META_SCHEMAS_ARGS)"
207 @echo ""
208 @echo "OPTIMADE_VERSION = $(OPTIMADE_VERSION)"
209 @echo "OPTIMADE_VERSION_SUBST = $(OPTIMADE_VERSION_SUBST)"
210 @echo ""
211 @echo "INDEXES_HTML = $(INDEXES_HTML)"
212