Repository navigation
Find NDIcalc document definitions in installed calculator packages - #329
Merged
Merged
Conversation
NDI-python used to git-clone NDIcalc-vis-matlab in ndi_install.py and copy
its ndi_common/{database,schema}_documents/{calc,neuro,vision} trees into
src/ndi/ndi_common. A pip/uv install never runs that, so every NDIcalc
document type was missing from a plain install.
Mirror MATLAB instead: ndi.fun.find_calc_directories returns each calculator
toolbox directory -- from the `ndi.calc` entry-point group rather than
MATLAB's sibling-folder scan -- and ndi_common_PathConstants gains CalcDoc /
CalcDocSchema (MATLAB names, lists of <toolbox>/ndi_common/... paths).
$NDICALCDOCUMENTPATH / $NDICALCSCHEMAPATH are registered with DID as those
lists, which DID-python's resolver already walks. Document definition lookup,
ndi.validate's schema lookup and ndi.fun.doc.allTypes search them too, and
`python -m ndi check` reports the calculator packages.
- pyproject: depend on ndicalc-vis-matlab (archive URL, no git)
- ndi_install.py: drop the NDIcalc-vis-matlab clone and the copy step
- .gitignore: drop the entries for the copied trees
- CI: the install-without-git job asserts vision/contrast_tuning resolves
- bridge YAMLs: CalcDoc/CalcDocSchema properties; find_calc_directories
is ported_differently with python_path ndi/fun/utils.py
- test_matlab_bridge_properties follows metaclass= like a base, so the
metaclass properties are seen and their allowlist entries are removed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013devLWydMwi8CvWpbHm6in
Contributor
Author
|
Install without git (and every other job that installs NDI) is failing, as expected. uv reports that This PR cannot fix that on its own side. Pointing the dependency at the feature branch was ruled out on purpose. Once VH-Lab/NDIcalc-vis-matlab's Generated by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Merge this after VH-Lab/NDIcalc-vis-matlab's
python-packagingPR. The new runtime dependency points athttps://github.com/VH-Lab/NDIcalc-vis-matlab/archive/refs/heads/main.zip, andmainhas nopyproject.tomluntil that PR merges. Until then every CI job that installs NDI will fail at the install step. That failure is expected. The dependency is not pointed at the feature branch, on purpose.Why
Today
ndi_install.pygit-clones NDIcalc-vis-matlab, andinstall_ndi_common_docs()copies itsndi_common/{database,schema}_documents/{calc,neuro,vision}trees intosrc/ndi/ndi_common/, which is gitignored. Auv/pipinstall (the double-click installer path that #328 prepared for) never runs that script, so every NDIcalc document type was missing.What
This works the way MATLAB does:
ndi.common.PathConstants.CalcDoc/CalcDocSchemaare built fromndi.fun.find_calc_directories().ndi.fun.find_calc_directories(src/ndi/fun/utils.py): returns each calculator toolbox directory. MATLAB scans for siblingNDIcalc*-matlabfolders; this reads thendi.calcentry points instead (importlib.metadata.entry_points(group="ndi.calc"), sorted by name). If an entry point fails to load, raises, or returns something that is not a directory, it warns and is skipped, soimport ndicannot crash on it.ndi_common_PathConstants.CalcDoc/CalcDocSchema: these use the MATLAB names and are lists of<toolbox>/ndi_common/database_documents(resp.schema_documents). They are lazy and memoized. You can override them (assign a list, orNone/delto rediscover) and also throughset_paths(calc_doc=..., calc_doc_schema=...), the same wayDOCUMENT_PATHworks.$NDICALCDOCUMENTPATH/$NDICALCSCHEMAPATHare now registered as those lists, as in MATLAB. DID-python already supports list values:did.validate.resolve_definition_pathtries each entry of a list, so no DID-python change is needed. The only gap there is that DID'sDEFINITIONStype annotation still saysdict[str, str], and that is cosmetic. Empty values are not registered, matching MATLAB. The old comment saying Python has no separate calculator packages has been replaced.ndi_document.read_blank_definition(both the explicit-path and bare-name searches),ndi.validate._load_schemaandndi.fun.doc.allTypes(which MATLAB also points atCalcDoc) now search NDI's tree first, then everyCalcDoc/CalcDocSchemafolder.vision/contrast_tuningresolves from the installed package.python -m ndi check: adds a "NDI calculator documents (ndi.calc)" check, and the DID-globals check now handles list values.install_ndi_common_docs()are gone fromndi_install.py, along with the.gitignoreentries for the copied folders. The Pyraview and vhlab-toolbox steps are unchanged.pyproject.toml: addsndicalc-vis-matlab @ …/archive/refs/heads/main.zip. It is an archive URL, notgit+.ndicalc_vis_matlaband checks thatvision/contrast_tuningresolves, both directly and through DID's$NDICALCDOCUMENTPATH.Tests
tests/test_calc_doc_discovery.pybuilds a fake calculator package (a module plus a.dist-infowith anndi.calcentry point) intmp_path, so it needs no network. It covers:CalcDocallTypesresolutionndicalc-vis-matlab: it is discovered,vision/contrast_tuningresolves, and its schema resolves through DID. It skips if the package is absent.test_document_path_variables.py,test_did_integration.pyandtest_issues_93_94.pynow read the calculator trees fromCalcDoc/CalcDocSchemainstead of the copied folders. The calculator-only assertions skip when no calculator package is installed.test_ndi_install_exit_codes.pydrops its stub for the removed function.test_matlab_bridge_properties.pynow followsmetaclass=the same way it follows a base class.CalcDoc/CalcDocSchemaare metaclass properties, asDOCUMENT_PATHis, so they are now visible to the check, and their entries inbridge_property_allowlist.yamlare removed.Run locally:
black --check,ruff check, and the fullpytest tests/(5906 passed, 601 skipped). The bridge checks also ran against an NDI-matlab checkout withNDI_BRIDGE_CHECK_STRICT=1(197 passed). I also ran the affected tests with ndicalc-vis-matlab uninstalled, and they pass and skip correctly.Sandbox caveat: this sandbox gets 403 on
github.com/.../archive/.... So locally I installed every dependency from local clones, and ndicalc-vis-matlab from a clone of itspython-packagingbranch. The archive-URL install path is checked only by CI.Bridge
src/ndi/common/ndi_matlab_python_bridge.yaml: addsCalcDocandCalcDocSchemaproperties.set_pathsgets two new arguments.updateDIDConstantsnow returnsdict[str, str | list[str]], and the divergence paragraph in its decision_log is replaced. Hashes are unchanged (MATLAB has not moved).src/ndi/fun/ndi_matlab_python_bridge.yaml:find_calc_directoriesstaysported_differently, now withpython_path: ndi/fun/utils.py, output arguments, and a decision_log explaining that entry points replace the sibling-folder scan.allTypes's log now mentionsCalcDoc.🤖 Generated with Claude Code
https://claude.ai/code/session_013devLWydMwi8CvWpbHm6in
Generated by Claude Code