Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cffee39
build(hatch-env): specify env for conversion to LinkML and back
candleindark Mar 10, 2026
b5644c1
build(hatch-env): provide script to translate `dandischema.models`
candleindark Mar 10, 2026
cfe3bea
build(hatch-env): provide script to translate `dandischema/models.yaml`
candleindark Mar 10, 2026
73c46b6
Now we will sanitize the converted model addresses
yarikoptic Mar 13, 2026
c79b1e2
more sanitization
yarikoptic Mar 13, 2026
0b2b51d
feat: provide `prefixes` definition in the overlay file
candleindark Mar 13, 2026
6cb2f82
Added linkml: prefix and sorted all the entries
yarikoptic Mar 13, 2026
76526a9
Provide default prefix to be custom dandi_default
yarikoptic Mar 13, 2026
7fa95c2
use portable ERE sed pattern for normalizing memory addresses
yarikoptic Mar 13, 2026
fad6879
fix: correct `default_prefix` to `dandi`
candleindark Mar 16, 2026
5f78b87
Adding models_importstab.py so we could use it to import from convert…
yarikoptic Mar 13, 2026
0208c9c
Adding the tool to assist in establishing "merges" with regeneration …
yarikoptic Mar 20, 2026
488e2e9
We are doomed to use --no-verify for now as converted python code has…
yarikoptic Mar 20, 2026
0ba5ad7
BF the commit version specification
yarikoptic Mar 20, 2026
2faf932
Implement poor man patch queue
yarikoptic Mar 20, 2026
c177479
reflect that I rewritten how we handle patching
yarikoptic Mar 20, 2026
54cf276
Inform on what we are doing
yarikoptic Mar 20, 2026
5eb4a91
Now do patch diff of master in as well for good measure
yarikoptic Mar 20, 2026
76a9d77
Removing reporting branches - did not work
yarikoptic Mar 20, 2026
c6172c4
ENH: patch converted to pydantic model to strip dciteCOLO
yarikoptic Mar 20, 2026
e2d124c
do pre-commit
yarikoptic Mar 20, 2026
d8b1bea
feat: provide partial schema
candleindark Mar 26, 2026
c0fbd02
feat: enable `2linkml` to merge partial schema in `models_merge.yaml`
candleindark Mar 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions dandischema/models_importstab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .models_linkml import * # noqa: F401,F403
from .models_orig import DANDI_INSTANCE_URL_PATTERN # noqa: F401

# TODO: temporary imports of consts etc which might need to be 'redone'
# so we do not duplicate them


# TODO: do the extra tune ups like linking extra validations etc,
# potentially copied from models_orig.py
7 changes: 7 additions & 0 deletions dandischema/models_merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file specifies a partial schema to be merged with the auto LinkML translation
# `dandischema.models`. It is a place to specify elements of the target dandischema
# LinkML schema that are not translatable from or not available in `dandischema.models`

slots:
schemaKey:
designates_type: true
31 changes: 31 additions & 0 deletions dandischema/models_overlay.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: dandi-schema
id: https://schema.dandiarchive.org/s/dandi/v0.7
version: 0.7.0
status: eunal:concept-status/DRAFT

prefixes:
dandiasset: http://dandiarchive.org/asset/
DANDI: http://dandiarchive.org/dandiset/
dandi: http://schema.dandiarchive.org/
dcite: http://schema.dandiarchive.org/datacite/
dct: http://purl.org/dc/terms/
linkml: https://w3id.org/linkml/
nidm: http://purl.org/nidash/nidm#
ORCID: https://orcid.org/
owl: http://www.w3.org/2002/07/owl#
PATO: http://purl.obolibrary.org/obo/PATO_
pav: http://purl.org/pav/
prov: http://www.w3.org/ns/prov#
rdfa: http://www.w3.org/ns/rdfa#
rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
rdfs: http://www.w3.org/2000/01/rdf-schema#
ROR: https://ror.org/
RRID: "https://scicrunch.org/resolver/RRID:"
rs: http://schema.repronim.org/
schema: http://schema.org/
skos: http://www.w3.org/2004/02/skos/core#
spdx: http://spdx.org/licenses/
uuid: http://uuid.repronim.org/
xsd: http://www.w3.org/2001/XMLSchema#

default_prefix: dandi
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ all = [
installer = "uv"
python = "3.10"

# Env for auto converting `dandischema.models` to LinkML schema and back to Pydantic models
# To invoke conversion scripts provided by the environment, execute the following respective commands:
# `hatch run linkml-auto-converted:2linkml` # Convert dandischema.models -> dandischema/models.yaml
# `hatch run linkml-auto-converted:2pydantic` # Convert dandischema/models.yaml -> dandischema/models_linkml.py
[tool.hatch.envs.linkml-auto-converted]
dependencies = [
"black", # This allows `gen-pydantic` to format the generated Pydantic models with Black formatting
"pydantic2linkml @ git+https://github.com/dandi/pydantic2linkml.git"
]
[tool.hatch.envs.linkml-auto-converted.scripts]
2linkml = "pydantic2linkml -l INFO -M dandischema/models_merge.yaml -O dandischema/models_overlay.yaml dandischema.models | sed -e 's,0x[0-9a-ef]*,0xADDRESS,g' -E -e 's,([^[:space:]]+):[0-9]+,\\1:NUMBER,g' > dandischema/models.yaml"
2pydantic = "gen-pydantic --black dandischema/models.yaml | sed -e 's,dciteCOLON,,g' > dandischema/models_linkml.py"

[tool.setuptools.packages.find]
namespaces = true
include = ["dandischema*"]
Expand Down
60 changes: 60 additions & 0 deletions tools/linkml_conversion
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash
#
# Script which will force us to apply the changes we have
#

set -eu

# ensure we are clean to no side effects and are in
test -z "$(git status --porcelain)" || { echo "Git tree is dirty, aborting."; exit 1; }

# determine remote name based on what remote linkml-conversion is
# tracked from which should correspond to our main repo!
remote=$(git config branch.linkml-conversion.remote)

git checkout linkml-conversion
# ensure up to date!
git pull --ff-only

ver=$(git describe linkml-conversion)

master_mergebase=$(git merge-base $remote/master linkml-conversion)

git checkout linkml-auto-converted

git merge -s ours --no-commit linkml-conversion

git read-tree -m -u linkml-conversion

# Poor man patch queue implementation
# Edit this list if you want to merge or drop PRs branches to be patched with.
# Order matters
branches_to_merge=(
master
remove-discriminated-unions
)

echo "Applying patches from base $master_mergebase"

for b in ${branches_to_merge[@]}; do
b_ver=$(git describe "$remote"/$b)
echo "Applying branch $b patch with following differences"
git diff --stat "$master_mergebase"..."$remote"/$b

git diff "$master_mergebase"..."$remote"/$b | patch -p1
done

hatch run linkml-auto-converted:2linkml
hatch run linkml-auto-converted:2pydantic

# add (re)generated files
git add dandischema/models_linkml.py dandischema/models.yaml

# add our stab and rename original models.py
git mv dandischema/models.py dandischema/models_orig.py
git mv dandischema/models_importstab.py dandischema/models.py

# because we have pre-commit.ci doing that behind our back too!
pre-commit run --all || :

git commit -m "'Merged' with linkml-conversion $ver and ${#branches_to_merge[@]} branches" -a --no-verify
Loading