Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify #15

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file added .DS_Store
Binary file not shown.
5 changes: 1 addition & 4 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
---
name: Build and test oscem_schemas

on: [pull_request]
on: [push, pull_request]
sbliven marked this conversation as resolved.
Show resolved Hide resolved

jobs:
test:
Expand Down Expand Up @@ -32,8 +32,5 @@ jobs:
- name: Install project
run: poetry install --no-interaction

- name: Run linter
run: make lint
sbliven marked this conversation as resolved.
Show resolved Hide resolved

- name: Run test suite
run: make test
1 change: 1 addition & 0 deletions .github/workflows/test_pages_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
- opened
- reopened
- synchronize
- edited

concurrency: preview-${{ github.ref }}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/project/docs/
/tmp/
/Testing
/*_bak*

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
271 changes: 142 additions & 129 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ SHELL := bash

# environment variables
.EXPORT_ALL_VARIABLES:
ifdef LINKML_ENVIRONMENT_FILENAME
include ${LINKML_ENVIRONMENT_FILENAME}
else
include config.public.mk
endif

RUN = poetry run
SCHEMA_NAME = $(LINKML_SCHEMA_NAME)
SOURCE_SCHEMA_PATH = $(LINKML_SCHEMA_SOURCE_PATH)
SOURCE_SCHEMA_DIR = $(dir $(SOURCE_SCHEMA_PATH))

# List all schema files matching oscem_schemas_*.yaml in the schema directory
SCHEMA_FILES := $(wildcard src/oscem_schemas/schema/oscem_schemas_*.yaml)
sbliven marked this conversation as resolved.
Show resolved Hide resolved

# Extract schema names without the directory and extension
SCHEMA_NAMES := $(notdir $(basename $(SCHEMA_FILES)))
SCHEMA_NAMES := $(patsubst oscem_schemas_%,%,$(SCHEMA_NAMES))

SRC = src
DEST = project
PYMODEL = $(SRC)/$(SCHEMA_NAME)/datamodel
DOCDIR = docs
EXAMPLEDIR = examples
SITE = site
PERMDOCS = perm_docs

CONFIG_YAML =
ifdef LINKML_GENERATORS_CONFIG_YAML
Expand All @@ -34,24 +36,8 @@ ifdef LINKML_GENERATORS_DOC_ARGS
GEN_DOC_ARGS = ${LINKML_GENERATORS_DOC_ARGS}
endif

GEN_OWL_ARGS =
ifdef LINKML_GENERATORS_OWL_ARGS
GEN_OWL_ARGS = ${LINKML_GENERATORS_OWL_ARGS}
endif

GEN_JAVA_ARGS =
ifdef LINKML_GENERATORS_JAVA_ARGS
GEN_JAVA_ARGS = ${LINKML_GENERATORS_JAVA_ARGS}
endif

GEN_TS_ARGS =
ifdef LINKML_GENERATORS_TYPESCRIPT_ARGS
GEN_TS_ARGS = ${LINKML_GENERATORS_TYPESCRIPT_ARGS}
endif


# basename of a YAML file in model/
.PHONY: all clean setup gen-project gen-examples gendoc git-init-add git-init git-add git-commit git-status
.PHONY: setup gen-project git-init-add git-init git-add git-commit git-status

# note: "help" MUST be the first target in the file,
# when the user types "make" they should get help info
Expand All @@ -72,6 +58,13 @@ status: check-config
@echo "Project: $(SCHEMA_NAME)"
@echo "Source: $(SOURCE_SCHEMA_PATH)"

check-config:
ifndef LINKML_SCHEMA_NAME
$(error **Project not configured**:\n\n - See '.env.public'\n\n)
else
$(info Ok)
endif

# generate products and add everything to github
setup: check-config git-init install gen-project gen-examples gendoc git-add git-commit

Expand Down Expand Up @@ -99,104 +92,123 @@ update-template:
update-linkml:
poetry add -D linkml@latest

# EXPERIMENTAL
create-data-harmonizer:
npm init data-harmonizer $(SOURCE_SCHEMA_PATH)

all: site
site: gen-project gendoc
%.yaml: gen-project
deploy: all mkd-gh-deploy

# In future this will be done by conversion
gen-examples:
cp -r src/data/examples/* $(EXAMPLEDIR)

# generates all project files

gen-project: $(PYMODEL)
$(RUN) gen-project ${CONFIG_YAML} -d $(DEST) $(SOURCE_SCHEMA_PATH) && mv $(DEST)/*.py $(PYMODEL)


# non-empty arg triggers owl (workaround https://github.com/linkml/linkml/issues/1453)
ifneq ($(strip ${GEN_OWL_ARGS}),)
mkdir -p ${DEST}/owl || true
$(RUN) gen-owl ${GEN_OWL_ARGS} $(SOURCE_SCHEMA_PATH) >${DEST}/owl/${SCHEMA_NAME}.owl.ttl
endif
# non-empty arg triggers java
ifneq ($(strip ${GEN_JAVA_ARGS}),)
$(RUN) gen-java ${GEN_JAVA_ARGS} --output-directory ${DEST}/java/ $(SOURCE_SCHEMA_PATH)
endif
# non-empty arg triggers typescript
ifneq ($(strip ${GEN_TS_ARGS}),)
mkdir -p ${DEST}/typescript || true
$(RUN) gen-typescript ${GEN_TS_ARGS} $(SOURCE_SCHEMA_PATH) >${DEST}/typescript/${SCHEMA_NAME}.ts
endif

test: test-validate test-examples test-python
.PHONY: test test-validate test-examples test-python

test-schema:
$(RUN) gen-project ${CONFIG_YAML} -d tmp $(SOURCE_SCHEMA_PATH)

test-python:
$(RUN) python -m unittest discover

lint:
$(RUN) linkml-lint --validate --all --ignore-warnings $(SOURCE_SCHEMA_DIR)

check-config:
ifndef LINKML_SCHEMA_NAME
$(error **Project not configured**:\n\n - See '.env.public'\n\n)
else
$(info Ok)
endif

test-validate:
$(RUN) linkml-validate -s $(SOURCE_SCHEMA_PATH) src/data/examples/*.yaml

convert-examples-to-%:
$(patsubst %, $(RUN) linkml-convert % -s $(SOURCE_SCHEMA_PATH) -C Person, $(shell ${SHELL} find src/data/examples -name "*.yaml"))

examples/%.yaml: src/data/examples/%.yaml
$(RUN) linkml-convert -s $(SOURCE_SCHEMA_PATH) -C Person $< -o $@
examples/%.json: src/data/examples/%.yaml
$(RUN) linkml-convert -s $(SOURCE_SCHEMA_PATH) -C Person $< -o $@
examples/%.ttl: src/data/examples/%.yaml
$(RUN) linkml-convert -P EXAMPLE=http://example.org/ -s $(SOURCE_SCHEMA_PATH) -C Person $< -o $@

test-examples: examples/output

examples/output: src/oscem_schemas/schema/oscem_schemas.yaml
mkdir -p $@
$(RUN) linkml-run-examples \
--output-formats json \
--output-formats yaml \
--counter-example-input-directory src/data/examples/invalid \
--input-directory src/data/examples \
--output-directory $@ \
--schema $< > $@/README.md

# Test documentation locally
serve: mkd-serve

# Python datamodel
$(PYMODEL):
mkdir -p $@


$(DOCDIR):
mkdir -p $@

gendoc: $(DOCDIR)
cp -rf $(SRC)/docs/files/* $(DOCDIR) ; \
$(RUN) gen-doc ${GEN_DOC_ARGS} -d $(DOCDIR) $(SOURCE_SCHEMA_PATH)

testdoc: gendoc serve
# Generate code for all schemas
.PHONY: gen-project
gen-project: $(SCHEMA_NAMES:%=gen-project-%)

gen-project-%:
@echo "Generating code for schema $*"
mkdir -p $(DEST)/$*
$(RUN) gen-project $(CONFIG_YAML) -d $(DEST)/$* src/oscem_schemas/schema/oscem_schemas_$*.yaml

# Generate documentation for all schemas
.PHONY: gendoc
gendoc: $(SCHEMA_NAMES:%=gendoc-%)

gendoc-%:
@echo "Generating documentation for schema $*"
mkdir -p $(DOCDIR)/$*
cp -rf $(SRC)/docs/files/* $(DOCDIR)/$*
$(RUN) gen-doc $(GEN_DOC_ARGS) -d $(DOCDIR)/$* src/oscem_schemas/schema/oscem_schemas_$*.yaml
cp $(PERMDOCS)/* $(DOCDIR)/



# Generate examples for all schemas
.PHONY: gen-examples
gen-examples: $(SCHEMA_NAMES:%=gen-examples-%)

gen-examples-%:
@echo "Copying examples for schema $*"
mkdir -p $(EXAMPLEDIR)
cp -r src/data/examples/example_valid_$*.yaml $(EXAMPLEDIR)/example_valid_$*.yaml 2>/dev/null || true

# Run tests for all schemas
test-python: $(SCHEMA_NAMES:%=test-%)
test-lint: $(SCHEMA_NAMES:%=lint-%)
test-examples: $(SCHEMA_NAMES:%=examples-%)
test: test-lint test-examples
.PHONY: test test-lint test-examples

test-%:
@echo "Running tests for schema $*"
@if [ -f tests/test_$*.py ]; then \
$(RUN) pytest tests/test_$*.py; \
else \
echo "No tests found for schema $*"; \
fi

lint-%:
@echo "Running lint for schema $*"
$(RUN) linkml-lint --validate --all --ignore-warnings src/oscem_schemas/schema/oscem_schemas_$*.yaml; \

examples-%:
@echo "Validating examples against schema $*"
@if [ -f src/data/examples/example_valid_$*.yaml ]; then \
$(RUN) linkml-validate -s src/oscem_schemas/schema/oscem_schemas_$*.yaml src/data/examples/example_valid_$*.yaml ; \
else \
echo "No example found"; \
fi

## $(RUN) python -m unittest discover; \

prepare-mkdocs: $(SCHEMA_NAMES:%=prepare-mkdocs-%)

# two options, see which works better: 1 project/$*/$(DOCDIR) 2 $(DOCDIR)/$*
prepare-mkdocs-%:
@echo "Preparing MkDocs configuration for schema $*"
@mkdir -p $(DOCDIR)/$*
@echo "site_name: 'OSC-EM_$*_Documentation'" > $(DOCDIR)/$*/mkdocs.yml
@echo "theme:" >> $(DOCDIR)/$*/mkdocs.yml
@echo " name: material" >> $(DOCDIR)/$*/mkdocs.yml
@echo " features:" >> $(DOCDIR)/$*/mkdocs.yml
@echo " - content.tabs.link" >> $(DOCDIR)/$*/mkdocs.yml
@echo "plugins:" >> $(DOCDIR)/$*/mkdocs.yml
@echo " - search" >> $(DOCDIR)/$*/mkdocs.yml
@echo " - mermaid2" >> $(DOCDIR)/$*/mkdocs.yml
@echo " - mermaid2:" >> $(DOCDIR)/$*/mkdocs.yml
@echo " version: 10.9.0" >> $(DOCDIR)/$*/mkdocs.yml

@echo "docs_dir: '.'" >> $(DOCDIR)/$*/mkdocs.yml
@echo "site_dir: ../../$(SITE)/$*" >> $(DOCDIR)/$*/mkdocs.yml
@echo "nav:" >> $(DOCDIR)/$*/mkdocs.yml
@echo " - Home: index.md" >> $(DOCDIR)/$*/mkdocs.yml


@echo "site_url: https://osc-em.github.io/OSCEM-schemas_$*" >> $(DOCDIR)/$*/mkdocs.yml
@echo "repo_url: https://github.com/osc-em/OSCEM_Schemas" >> $(DOCDIR)/$*/mkdocs.yml

# Build Independent MkDocs Sites
mkdocs-build:
prepare-mkdocs $(SCHEMA_NAMES:%=build-%)

build-test-%:
@echo "Building site for $*"
$(RUN) mkdocs build -f $(DOCDIR)/$*/mkdocs.yml
# $(DOCDIR)/$*/
#-d $(SITE)/$*
build:
@echo "Building site for $*"
$(RUN) mkdocs build -f mkdocs.yml

# Serve a Specific Schema Locally
serve-test-%:
@echo "Serving site for $*"
$(RUN) mkdocs serve -f $(DOCDIR)/$*/mkdocs.yml -a 0.0.0.0:8000

serve:
$(RUN) mkdocs serve -f mkdocs.yml -a 0.0.0.0:8000
# Serve All Schemas Simultaneously
serve-all: $(SCHEMA_NAMES:%=serve-%)



.PHONY: serve prepare-mkdocs mkdocs-build serve-all serve-test build-test

MKDOCS = $(RUN) mkdocs
mkd-%:
$(MKDOCS) $*
mkdocs-deploy: $(MKDOCS) gh-deploy

git-init-add: git-init git-add git-commit git-status
git-init:
Expand All @@ -208,15 +220,16 @@ git-commit:
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 generated files
.PHONY: clean
clean:
rm -rf $(DEST)
rm -rf tmp
rm -fr docs/*
rm -fr $(PYMODEL)/*

include project.Makefile
rm -rf $(DEST)/*
rm -rf $(DOCDIR)/* $(SITE)/*
rm -rf $(EXAMPLEDIR)/*
# rm -f mkdocs.yml

# Default target
.PHONY: all
all: gen-project gen-examples gendoc test
deploy: all mkdocs-deploy
5 changes: 0 additions & 5 deletions examples/README.md

This file was deleted.

Loading