The MATLAB codebase is the Source of Truth. The Python version is a "faithful mirror." When a conflict arises between "Pythonic" style and MATLAB symmetry, symmetry wins.
- Lead-Follow: MATLAB defines the logic, hierarchy, and naming.
- The Contract: Every package contains an
ndr_matlab_python_bridge.yaml. This file is the binding contract for function names, arguments, and return types.
Function and class names must match MATLAB exactly.
-
Naming Source: Refer to the local
ndr_matlab_python_bridge.yaml. -
Missing Entries: If a function is not in the bridge file, refer to the MATLAB source, add the entry to the bridge file, and notify the user.
-
Case Preservation: Use
readchannels_epochsamples, notread_channels_epoch_samples. -
Directory Parity: Python file paths must mirror MATLAB
+namespacepaths (e.g.,+ndr/+reader->src/ndr/reader/). -
Class Name Mirror Rule: Python class names are derived from the fully-qualified MATLAB class name by applying two substitutions:
- Periods (
.) are replaced with single underscores (_). - Existing underscores (
_) in the MATLAB name are replaced with double underscores (__).
Examples:
MATLAB qualified name Python class name ndr.readerndr_readerndr.reader.basendr_reader_basendr.reader.intan_rhdndr_reader_intan__rhdndr.reader.ced_smrndr_reader_ced__smrndr.reader.axon_abfndr_reader_axon__abfndr.reader.somecompany_someformatndr_reader_somecompany__someformat - Periods (
- Check the Bridge: Open the
ndr_matlab_python_bridge.yamlin the target package. - Sync the Interface: If the function is missing or outdated, update the YAML first.
- Record the Sync Hash: Store the short git hash of the MATLAB
.mfile:git log -1 --format="%h" -- <path-to-matlab-file> - Implement: Write Python code to satisfy the interface defined in the YAML.
- Log & Notify: Record the sync date in the YAML's
decision_log.
Use @pydantic.validate_call on all public-facing API functions.
- MATLAB
double/numeric-> Pythonfloat | int - MATLAB
char/string-> Pythonstr - MATLAB
{member1, member2}-> PythonLiteral["member1", "member2"]
Return multiple values as a tuple in the exact order defined in the YAML.
- Black: The sole code formatter. Line length 100.
- Ruff: The primary linter. Run
ruff check --fixbefore committing.
If MATLAB throws an error, Python MUST raise a corresponding Exception.