-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjustfile
186 lines (147 loc) · 5.17 KB
/
justfile
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
# On Windows the bash shell that comes with Git for Windows should be used.
# If it is not on path, give the path to the executable in the following line.
#set windows-shell := ["C:/Program Files/Git/usr/bin/sh", "-cu"]
# Load environment variables from config.public.mk or specified file
set dotenv-load := true
# set dotenv-filename := env_var_or_default("LINKML_ENVIRONMENT_FILENAME", "config.public.mk")
set dotenv-filename := x'${LINKML_ENVIRONMENT_FILENAME:-config.public.mk}'
# List all commands as default command. The prefix "_" hides the command.
_default: _status
@just --list
# Set cross-platform Python shebang line (assumes presence of launcher on Windows)
shebang := if os() == 'windows' {
'py'
} else {
'/usr/bin/env python3'
}
# Environment variables with defaults
schema_name := env_var_or_default("LINKML_SCHEMA_NAME", "")
source_schema_path := env_var_or_default("LINKML_SCHEMA_SOURCE_PATH", "")
config_yaml := if env_var_or_default("LINKML_GENERATORS_CONFIG_YAML", "") == "" {
"--config-file " + env_var_or_default("LINKML_GENERATORS_CONFIG_YAML", "")
} else {
""
}
gen_doc_args := env_var_or_default("LINKML_GENERATORS_DOC_ARGS", "")
gen_owl_args := env_var_or_default("LINKML_GENERATORS_OWL_ARGS", "")
gen_java_args := env_var_or_default("LINKML_GENERATORS_JAVA_ARGS", "")
gen_ts_args := env_var_or_default("LINKML_GENERATORS_TYPESCRIPT_ARGS", "")
# Directory variables
src := "src"
dest := "project"
pymodel := src / schema_name / "datamodel"
docdir := "docs"
exampledir := "examples"
# Show current project status
_status: _check-config
@echo "Project: {{schema_name}}"
@echo "Source: {{source_schema_path}}"
# Run initial setup (run this first)
setup: _check-config _git-init install _gen-project _gen-examples _gendoc _git-add _git-commit
# Install project dependencies
install:
poetry install
# Check project configuration
_check-config:
#!{{shebang}}
import os
schema_name = os.getenv('LINKML_SCHEMA_NAME')
if not schema_name:
print('**Project not configured**:\n - See \'.env.public\'')
exit(1)
print('Project-status: Ok')
# Updates project template and LinkML package
update: _update-template _update-linkml
# Update project template
_update-template:
cruft update
# Update LinkML to latest version
_update-linkml:
poetry add -D linkml@latest
# Create data harmonizer
_create-data-harmonizer:
npm init data-harmonizer {{source_schema_path}}
# Generate all project files
alias all := site
# Generate site locally
site: _gen-project _gendoc
# Deploy site
deploy: site
mkd-gh-deploy
# Generate examples
_gen-examples:
mkdir -p {{exampledir}}
cp src/data/examples/* {{exampledir}}
# Generate project files
_gen-project: _ensure_pymodel_dir
poetry run gen-project {{config_yaml}} -d {{dest}} {{source_schema_path}}
mv {{dest}}/*.py {{pymodel}}
poetry run gen-pydantic {{source_schema_path}} > "{{pymodel}}/{{schema_name}}_pydantic.py"
@if [ ! -z "${{gen_owl_args}}" ]; then \
poetry run gen-owl {{gen_owl_args}} {{source_schema_path}} > {{dest}}/owl/{{schema_name}}.owl.ttl || true && \
poetry run gen-owl {{gen_owl_args}} {{source_schema_path}} > {{dest}}/owl/{{schema_name}}.owl.ttl || true ; \
fi
@if [ ! ${{gen_java_args}} ]; then \
poetry run gen-java {{gen_java_args}} --output-directory {{dest}}/java/ {{source_schema_path}} || true ; \
fi
@if [ ! ${{gen_ts_args}} ]; then \
poetry run gen-typescript {{gen_ts_args}} {{source_schema_path}} > {{dest}}/typescript/{{schema_name}}.ts || true ; \
fi
# Run all tests
test: _test-schema _test-python _test-examples
# Test schema generation
_test-schema:
poetry run gen-project {{config_yaml}} -d tmp {{source_schema_path}}
# Run Python unit tests
_test-python:
poetry run python -m unittest discover
# Run example tests
_test-examples: _ensure_examples_output
poetry run linkml-run-examples \
--output-formats json \
--output-formats yaml \
--counter-example-input-directory src/data/examples/invalid \
--input-directory src/data/examples/valid \
--output-directory examples/output \
--schema src/pid4cat_model/schema/pid4cat_model.yaml > examples/output/README.md
# Run linting
lint:
poetry run linkml-lint {{source_schema_path}}
# Generate documentation
_gendoc: _ensure_docdir
cp -r {{src}}/docs/files/* {{docdir}}
poetry run gen-doc {{gen_doc_args}} -d {{docdir}} {{source_schema_path}}
# Build docs and run test server
testdoc: _gendoc _serve
# Run documentation server
_serve:
poetry run mkdocs serve
# Initialize and add everything to git
_git-init-add: _git-init _git-add _git-commit _git-status
# Initialize git repository
_git-init:
git init
# Add files to git
_git-add:
touch .cruft.json
git add .
# Commit files to git
_git-commit:
git commit -m 'chore: make setup was run' -a
# Show git status
_git-status:
git status
# Clean all generated files
clean:
rm -rf {{dest}}
rm -rf tmp
rm -rf {{docdir}}/*
rm -rf {{pymodel}}
# Private recipes
_ensure_pymodel_dir:
-mkdir -p {{pymodel}}
_ensure_docdir:
-mkdir -p {{docdir}}
_ensure_examples_output:
-mkdir -p examples/output
import "project.justfile"