Skip to content

Add MATLAB to Python porting guide with strict mirroring rules#8

Merged
stevevanhooser merged 10 commits into
mainfrom
claude/add-python-porting-guide-emxaj
Mar 11, 2026
Merged

Add MATLAB to Python porting guide with strict mirroring rules#8
stevevanhooser merged 10 commits into
mainfrom
claude/add-python-porting-guide-emxaj

Conversation

@stevevanhooser
Copy link
Copy Markdown
Contributor

Summary

This PR introduces a comprehensive porting guide that establishes the principles and standards for converting MATLAB code to Python while maintaining strict architectural symmetry with the original codebase.

Key Changes

  • Added PYTHON_PORTING_GUIDE.md with six core sections defining the porting philosophy:
    • Lead-Follow Architecture: Establishes MATLAB as the source of truth, with Python as a faithful mirror
    • Strict Naming Rules: Requires exact function name matching (no PEP 8 conversion) to enable copy-paste compatibility
    • Namespace Mapping: Defines 1:1 mapping of MATLAB + packages to Python directory structure
    • Pydantic Validation: Mandates @pydantic.validate_call decorator for input validation parity with MATLAB's arguments block
    • Error Handling: Specifies hard-fail behavior at function entry points for invalid inputs
    • Documentation Standards: Requires docstring symmetry with original MATLAB documentation

Notable Implementation Details

  • The guide prioritizes symmetry over Pythonic conventions when conflicts arise
  • Emphasizes discoverability through consistent namespace/directory structure mapping
  • Provides concrete type mapping examples (MATLAB double → Python float/int, etc.)
  • Allows Pydantic's default type coercion behavior for flexibility while maintaining validation rigor

https://claude.ai/code/session_012qih1bFF69sgSPvBnWzEHo

claude and others added 10 commits March 10, 2026 12:00
Documents the core rules for porting MATLAB code to Python, including
naming conventions, namespace mapping, Pydantic validation, error
handling, and docstring requirements.

https://claude.ai/code/session_012qih1bFF69sgSPvBnWzEHo
…ule)

Apply the Strict Mirror Rule from PYTHON_PORTING_GUIDE.md: every Python
function name must be an identical string match to its MATLAB counterpart.
Renamed ~80+ functions across 17 source files, 6 test files, and 2 tutorials
from snake_case to camelCase. Updated MATLAB_MAPPING.md to reflect new names.

https://claude.ai/code/session_01Skj3WbRtzYBdW5uk6nazhE
Rename functions across ndi.fun.* to use MATLAB-style camelCase naming:
- utils: name2variable_name → name2variableName
- data: read_image_stack → readImageStack
- doc: all_types → allTypes, find_fuid → findFuid, etc.
- doc_table: ontology_table_row_doc_to_table → ontologyTableRowDoc2Table, etc.
- epoch: t0_t1_to_array → t0_t1cell2array
- file: md5 → MD5, date_created → dateCreated, date_updated → dateUpdated
- table: identify_matching_rows → identifyMatchingRows, etc.
- stimulus: find_mixture_name → findMixtureName, etc.
- name_utils: name_to_variable_name → name2variableName

All old snake_case names preserved as backward-compatible aliases.
New ndi.fun.plot module ported from MATLAB with bar3, multichan, stimulusTimeseries.
Updated all references in tests and tutorials.

https://claude.ai/code/session_01Skj3WbRtzYBdW5uk6nazhE
…unctions-python-L9MAj

Rename Python API functions to match MATLAB camelCase naming
…atting-nbwSK

Reformat long lines to improve code readability
Aligns Python's APIResponse with the richer structure returned by MATLAB's
ndi.cloud.api apiResponse output argument. All new fields use safe defaults
so existing call-sites (including manually-constructed APIResponse instances
in pagination helpers) are fully backward-compatible.

https://claude.ai/code/session_01Y9G6ysXeXzrXRsZGe2Pe3G
…source of truth

Renames (with backward-compatible aliases):
- download.downloadFullDataset → download.dataset
- filehandler.rewrite_file_info_for_cloud → filehandler.updateFileInfoForRemoteFiles
- sync._delete_local_docs → sync.deleteLocalDocuments (now public)
- sync._download_docs_by_ids → sync.downloadNdiDocuments (now public)

New functions ported from MATLAB:
- download.datasetDocuments — per-document download with mode handling
- download.downloadGenericFiles — download generic_file docs with extensions
- download.setFileInfo — set file_info for local/hybrid modes
- download.structsToNdiDocuments — alias for jsons2documents
- upload.uploadToNDICloud — legacy upload entry point
- upload.scanForUpload — moved from orchestration to match MATLAB location
- filehandler.updateFileInfoForLocalFiles — update file_info for local files
- internal.duplicateDocuments — find/remove duplicate cloud documents

Test cleanup:
- Add module-scoped autouse fixture to sweep up any leftover NDI_PYTEST_*
  datasets after all tests complete, preventing stale dataset accumulation.

https://claude.ai/code/session_01Y9G6ysXeXzrXRsZGe2Pe3G
The safety-net fixture now prints a warnings.warn with the names and
IDs of every leftover dataset it deletes, making silent teardown
failures visible in CI logs.

https://claude.ai/code/session_01Y9G6ysXeXzrXRsZGe2Pe3G
…api-response-fUucA

Expand APIResponse to capture additional HTTP response metadata
@stevevanhooser stevevanhooser merged commit 78672b4 into main Mar 11, 2026
3 of 4 checks passed
@stevevanhooser stevevanhooser deleted the claude/add-python-porting-guide-emxaj branch March 11, 2026 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants