generated from linkml/linkml-template
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
294 lines (244 loc) · 8.06 KB
/
Makefile
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
MAKEFLAGS += --warn-undefined-variables
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := help
.DELETE_ON_ERROR:
.SUFFIXES:
.SECONDARY:
RUN = poetry run
# get values from about.yaml file
# replaced sh with bash esp for linux
SCHEMA_NAME = $(shell bash ./utils/get-value.sh name)
DOCDIR = docs
SOURCE_SCHEMA_PATH = $(shell bash ./utils/get-value.sh source_schema_path)
SOURCE_SCHEMA_DIR = $(dir $(SOURCE_SCHEMA_PATH))
SRC = src
DEST = project
PYMODEL = $(SCHEMA_NAME)
EXAMPLEDIR = examples
TEMPLATEDIR = doc-templates
.PHONY: all clean examples-clean install site site-clean site-copy squeaky-clean test test-python test-with-examples
# note: "help" MUST be the first target in the file,
# when the user types "make" they should get help info
help: status
@echo ""
@echo "This project requires that dependencies are loaded into a poetry environment with 'poetry install'"
@echo "Most typical usage: 'make squeaky-clean all test'"
@echo "Documentation publication is handled by a GitHub merge action"
@echo " but users can generate a local documentation site with 'make testdoc'"
@echo "Please excuse the currently verbose logging mode"
@echo "make help -- show this help"
@echo ""
cookiecutter-help: status
@echo ""
@echo "make setup -- initial setup (run this first)"
@echo "make site -- makes site locally"
@echo "make install -- install dependencies"
@echo "make test -- runs tests"
@echo "make lint -- perfom linting"
@echo "make testdoc -- builds docs and runs local test server"
@echo "make deploy -- deploys site"
@echo "make update -- updates linkml version"
@echo "make cookiecutter-help -- show this help"
@echo ""
status: check-config
@echo "Project: $(SCHEMA_NAME)"
@echo "Source: $(SOURCE_SCHEMA_PATH)"
# generate products and add everything to github
setup: install gen-project gendoc git-init-add
# install any dependencies required for building
install:
poetry install
# ---
# Project Synchronization
# ---
#
# check we are up to date
check: cruft-check
cruft-check:
# added cruft to poetry env and added poetry wrapper to cruft invocations
$(RUN) cruft check
cruft-diff:
$(RUN) cruft diff
update: update-template update-linkml
update-template:
$(RUN) cruft update
# todo: consider pinning to template
update-linkml:
poetry add -D linkml@latest
# EXPERIMENTAL
create-data-harmonizer:
npm init data-harmonizer $(SOURCE_SCHEMA_PATH)
prefixmaps:
@mkdir -p $(DEST)/prefixmap
$(RUN) gen-prefix-map nmdc_schema/nmdc_materialized_patterns.yaml > $(DEST)/prefixmap/nmdc-prefix-map.json
pydantic:
@mkdir -p $(DEST)/pydantic
$(RUN) gen-pydantic nmdc_schema/nmdc_materialized_patterns.yaml > $(DEST)/pydantic/nmdc-pydantic.py
# Note: `all` is an alias for `site`.
all: site
site: clean site-clean gen-project gendoc \
nmdc_schema/gold-to-mixs.sssom.tsv \
nmdc_schema/nmdc_materialized_patterns.schema.json nmdc_schema/nmdc_materialized_patterns.yaml \
migration-doctests \
prefixmaps \
pydantic
%.yaml: gen-project
# was deploy: all mkd-gh-deploy
deploy: gendoc mkd-gh-deploy
gen-project: $(PYMODEL) prefixmaps pydantic # depends on src/schema/mixs.yaml # can be nuked with mixs-yaml-clean
$(RUN) gen-project \
--exclude excel \
--exclude graphql \
--exclude jsonld \
--exclude markdown \
--exclude proto \
--exclude shacl \
--exclude shex \
--exclude sqlddl \
--include jsonldcontext \
--include jsonschema \
--include owl \
--include python \
--include rdf \
--config-file gen-project-config.yaml \
-d $(DEST) $(SOURCE_SCHEMA_PATH) && mv $(DEST)/*.py $(PYMODEL) && cp $(DEST)/pydantic/*.py $(PYMODEL)/nmdc-pydantic.py
cp project/jsonschema/nmdc.schema.json $(PYMODEL)
test: examples-clean site test-python migration-doctests examples/output
only-test: examples-clean test-python migration-doctests examples/output
test-schema:
$(RUN) gen-project \
--exclude excel \
--exclude graphql \
--exclude jsonld \
--exclude markdown \
--exclude proto \
--exclude shacl \
--exclude shex \
--exclude sqlddl \
--include jsonldcontext \
--include jsonschema \
--include owl \
--include python \
--include rdf \
-d tmp $(SOURCE_SCHEMA_PATH)
test-python:
$(RUN) python -m unittest discover
$(RUN) python -m doctest nmdc_schema/nmdc_data.py
lint:
$(RUN) linkml-lint $(SOURCE_SCHEMA_PATH) > local/lint.log
check-config:
@(grep my-datamodel about.yaml > /dev/null && printf "\n**Project not configured**:\n\n - Remember to edit 'about.yaml'\n\n" || exit 0)
# Test documentation locally
serve: mkd-serve
# Python datamodel
$(PYMODEL):
mkdir -p $@
$(DOCDIR):
mkdir -p $@
# Compile static Markdown files, images, and JavaScript scripts, into a documentation website.
#
# Then, use `refgraph` (part of `refscan`) to generate a diagram (i.e. a graph that depicts
# inter-collection relationships) in the documentation website's file tree.
gendoc: $(DOCDIR) prefixmaps
# Copy all documentation files to the documentation directory
cp -rf $(SRC)/docs/* $(DOCDIR)
# Added copying of images and renaming of TEMP.md
cp $(SRC)/docs/*md $(DOCDIR)
cp -r $(SRC)/docs/images $(DOCDIR)
# Generate documentation using the gen-doc command
$(RUN) gen-doc -d $(DOCDIR) --template-directory $(SRC)/$(TEMPLATEDIR) --include src/schema/deprecated.yaml $(SOURCE_SCHEMA_PATH)
# Create directory for JavaScript files and copy them
mkdir -p $(DOCDIR)/javascripts
$(RUN) cp $(SRC)/scripts/*.js $(DOCDIR)/javascripts/
# Use `refgraph` to generate an interactive diagram within the compiled documentation website file tree.
mkdir -p $(DOCDIR)/visualizations
$(RUN) refgraph --schema nmdc_schema/nmdc_materialized_patterns.yaml --subject collection --graph $(DOCDIR)/visualizations/collection-graph.html
testdoc: gendoc serve
MKDOCS = $(RUN) mkdocs
mkd-%:
$(MKDOCS) $*
PROJECT_FOLDERS = jsonldcontext jsonschema owl python rdf
git-init-add: git-init git-add git-commit git-status
git-init:
git init
git-add: .cruft.json
git add \
*.md \
.cruft.json \
.github \
.gitignore \
CODE_OF_CONDUCT.md \
CONTRIBUTING.md \
LICENSE \
MAINTAINERS.md \
Makefile \
README.md \
RELEASE_NOTES_v7.7.2_to_v7.7.7.md \
about.yaml \
assets \
images \
mkdocs.yml \
nmdc_schema \
notebooks \
poetry.lock \
project.Makefile \
project/ \
pyproject.toml \
src/ \
tests \
utils
git add $(patsubst %, project/%, $(PROJECT_FOLDERS))
git-commit:
git commit -m 'Initial commit' -a
git-status:
git status
# only necessary if setting up via cookiecutter
.cruft.json:
echo "creating a stub for .cruft.json. IMPORTANT: setup via cruft not cookiecutter recommended!" ; \
touch $@
clean:
rm -rf $(DEST)
rm -rf tmp
rm -rf docs/*.md
rm -rf docs/*.html
include project.Makefile
# custom
site-clean: clean
rm -rf nmdc_schema/*.json
rm -rf nmdc_schema/*.tsv
rm -rf nmdc_schema/*.yaml
squeaky-clean: clean examples-clean rdf-clean shuttle-clean site-clean # does not include mixs-yaml-clean
rm -rf $(PYMODEL)/nmdc.py
rm -rf $(PYMODEL)/nmdc-pydantic.py
mkdir project
rm -rf local/biosample_slots_ranges_report.tsv
nmdc_schema/nmdc_materialized_patterns.yaml:
$(RUN) gen-linkml \
--format yaml \
--materialize-patterns \
--no-materialize-attributes \
--output $@ $(SOURCE_SCHEMA_PATH)
nmdc_schema/nmdc_materialized_patterns.schema.json: nmdc_schema/nmdc_materialized_patterns.yaml
$(RUN) gen-json-schema \
--closed \
--include-range-class-descendants \
--top-class Database $< > $@
# the sssom/ files should be double checked too... they're probably not all SSSSOM files
nmdc_schema/gold-to-mixs.sssom.tsv: sssom/gold-to-mixs.sssom.tsv
# just can't seem to tell pyproject.toml to bundle artifacts like these
# so reverting to copying into the module
cp $< $@
nmdc_schema/nmdc_schema_merged.yaml: project/nmdc_schema_merged.yaml
cp $< $@
####
.PHONY: check-invalids-for-single-failure
# echo "Running command: $$cmd"; \
check-invalids-for-single-failure:
for file in src/data/invalid/*.yaml; do \
echo "$$file:"; \
target_class=$$(basename $$file | cut -d'-' -f1); \
cmd="poetry run linkml-validate --schema nmdc_schema/nmdc_materialized_patterns.yaml --target-class $$target_class $$file"; \
output=$$($$cmd 2>&1 || true); \
echo "$$output" | sort | uniq; \
done