inm7-concepts/Makefile
Michał Szczepanik 4abd9b940b
All checks were successful
Codespell / Check for spelling errors (pull_request) Successful in 25s
Model checks / lint (pull_request) Successful in 1m42s
Validate examples and verify unmodified conversion / lint (pull_request) Successful in 2m48s
Stop makefile from calling linkml validate with config absent
This stops the checkvalidation (checkvalid / checkinvalid) target in
the makefile, which globs for `*(in)valid.cfg.yaml` files, from
calling `linkml validate` when no files match the pattern.

Previously, if there were no *.invalid.cfg.yaml files, we still made
it into the `@for ex in $</*invalid.cfg.yaml` loop (same for `*valid`)
-- but with the glob expression verbatim, producing errors like this:

"Invalid value for '--config': File
'src/flat-data/unreleased/validation/*.invalid.cfg.yaml' does not
exist."

It seems that make's wildcard function avoids the pitfall, while
correctly expanding the globs when files are present.

This is an alternative to a solution presented in #90, which excluded
checkinvalid from checkvalidation.

https://www.gnu.org/software/make/manual/html_node/Wildcard-Function.html
2025-08-13 13:55:14 +02:00

163 lines
4.8 KiB
Makefile

# this is a shell monster that will fail with exit(125) if a command produces
# stderr output
FAILIF_STDERR=bash -c 'fail_if_stderr() (rc=$$({("$$@" 2>&1 >&3 3>&- 4>&-; echo "$$?" >&4) | grep '^' >&2 3>&- 4>&-; } 4>&1); err=$$?; [ "$$rc" -eq 0 ] || exit "$$rc"; [ "$$err" -ne 0 ] || exit 125 ) 3>&1; fail_if_stderr $$@' FAILIF_STDERR
# no execution when only command printed is wanted
ifneq (,$(filter n,$(MAKEFLAGS)))
FAILIF_STDERR=: FAILIF_STDERR
endif
try:
${FAILIF_STDERR} bash -c 'exit 12'
all: build/mkdocs-site
build/linkml-docs: \
build/linkml-docs/s/base/unreleased \
build/linkml-docs/s/flat-base/unreleased \
build/linkml-docs/s/flat-users/unreleased \
build/linkml-docs/s/flat-data/unreleased \
build/linkml-docs/s/simpleinput/unreleased
build/linkml-docs/s/%: src/%.yaml src/%/extra-docs
$(MAKE) imports-remote
# take the YAML schema verbatim
mkdir -p $(dir $@)
cp $< $@.yaml
$(MAKE) imports-local
gen-doc \
--hierarchical-class-view \
--include-top-level-diagram \
--diagram-type er_diagram \
--metadata \
--format markdown \
--example-directory src/$*/examples/ \
-d $@ \
$< \
&& (cp -r src/$*/extra-docs/*.md $@ || true)
# try to inject any extra-docs (if any exist)
# generate OWL
gen-owl \
-f owl \
--mergeimports \
$< > $@.owl.ttl
# jsonld context
gen-jsonld-context \
--mergeimports \
$< > $@.context.jsonld
# SHACL with annotation needed to build UI specs
# and excluding automatic addition of sh:order
gen-shacl \
--include-annotations \
--exclude-order \
$< > $@.shacl.ttl
build/mkdocs-site: build/linkml-docs extra-docs/*.md
# top-level content
cp -r extra-docs/*.md $<
mkdocs build
check: check-models check-validation
# add additional schemas to lint here
check-models: \
checkmodel/base/unreleased \
checkmodel/flat-base/unreleased \
checkmodel/flat-users/unreleased \
checkmodel/flat-data/unreleased \
checkmodel/simpleinput/unreleased
checkmodel/%: src/%.yaml
@echo [Check $<]
@echo "Run linter"
@linkml-lint \
--config .linkmllint.yaml \
--max-warnings 0 \
--validate \
$<
# generate various output formats, they all have the potential to
# reveal "hidden" issues
@echo Generate a JSON-LD context
@${FAILIF_STDERR} gen-jsonld-context \
--prefixes \
--model \
--mergeimports \
$< > /dev/null
@echo Generate JSON schema
@${FAILIF_STDERR} gen-json-schema $< > /dev/null
@echo Generate OWL
@${FAILIF_STDERR} gen-owl $< > /dev/null
@echo Generate Python classes
@${FAILIF_STDERR} gen-python $< | python
# within check-validation, conversion targets must come before the
# respective validation targets, because some tests rely on these
# converted formats
check-validation: \
convertexamples/base/unreleased \
checkvalidation/base/unreleased \
convertexamples/flat-base/unreleased \
checkvalidation/flat-base/unreleased \
convertexamples/flat-users/unreleased \
checkvalidation/flat-users/unreleased \
convertexamples/flat-data/unreleased \
checkvalidation/flat-data/unreleased \
convertexamples/simpleinput/unreleased \
checkvalidation/simpleinput/unreleased
checkvalidation/%:
$(MAKE) checkvalid/$* checkinvalid/$*
checkvalid/%: src/%/validation src/%.yaml
@for ex in $(wildcard $</*.valid.cfg.yaml); do \
echo "Validate $$ex" ; \
linkml-validate --config "$$ex" || exit 5 ; \
done
checkinvalid/%: src/%/validation src/%.yaml
@for ex in $(wildcard $</*.invalid.cfg.yaml); do \
echo "(In)validate $$ex" ; \
linkml-validate --config "$$ex" && exit 5 || true; \
done
convert-examples: \
convertexamples/base/unreleased \
convertexamples/flat-base/unreleased \
convertexamples/flat-users/unreleased \
convertexamples/flat-data/unreleased \
convertexamples/simpleinput/unreleased
convertexamples/%: src/%.yaml src/%/examples
# loop over all examples, skip the schema file itself
for ex in $^/*.yaml; do \
[ "$$ex" = "$<" ] && continue; \
echo "Converting $$ex" ; \
for outf in json rdf; do \
linkml-convert \
-s "$<" \
--target-class-from-path \
--infer \
-t "$$outf" \
"$$ex" \
> $${ex%.yaml}.$${outf}.tmp && \
mv $${ex%.yaml}.$${outf}.tmp $${ex%.yaml}.$${outf} ; \
done \
done
@git --no-pager diff -- $(filter-out $<,$^)
@if [ -n "$$(git diff -- $(filter-out $<,$^))" ]; then \
echo -n 'ERROR: Unexpected modification of example output. ' ; \
echo 'Inspect and commit changes shown above!' ; \
exit 22 ; \
fi
deploy: build/mkdocs-site
rsync -rvz --delete $</ irrelephant.ngln.eu:/var/www/concepts.inm7.de/www/
imports-local:
@echo "Switch to local imports"
@sed -i -e 's,- inm7schemas:\(.*/.*\)$$,- ../../src/\1,' src/*/*.yaml
imports-remote:
@echo "Switch to remote imports"
@sed -i -e 's,- \.\./\.\./src/\(.*/.*\)$$,- inm7schemas:\1,' src/*/*.yaml
clean:
rm -rf build
rm -f *-stamp
.PHONY: clean check check-models check-validation convert-examples deploy