suggested_best_practices - depcharge-org/depcharge GitHub Wiki

MATLAB Best Practices with DepCharge

Project Folder Layout

project_name/
├─ .git/
├─ .gitignore
├─ +project_name/
│  ├─ +depcharge/
│  │  ├─ deplist.json
│  │  ├─ update.m    (updates dependencies and paths)
│  │  ├─ <dependency_helper_classes>  (optional)
│  ├─ tilefigures.m
│  ├─ <project files>
├─ _deps/   (autogenerated)
   ├─ dependency_1/
   |  ├─ .git/
   |  ├─ +dependency_1/
   |    ├─ <dependency_1 files>
   ├─ dependency_2/
      ├─ .git/
      ├─ +dependency_2/
        ├─ <dependency_2 files>   	

Key Features
Project repo contains a project package, so the project can be included on the path without polluting the global namespace.
This package name also helps programmatically detect if the package is on the MATLAB path.

_deps/ folder is automatically generated when depcharge.update() is run within the +project_name when project_name.depcharge.update() is run.

[!Note]

Global Code cannot be executed "within" a package directory, because you do not move the working directory into a package. You don't put a package directory on the path. You put the parent directory on the path.

Consequently, the appropriate organization may be to have +depcharge/ inside the +project_name/ folder with an update.m script. This could reference the installed DepCharge toolbox, and could determine which +package directory was primary. Default behavior should either be to create _deps/ in the parent directory, OR to ask where _deps/ should be created. One more possibility would be to skip the _deps directory and install the dependencies in a global store.

[!Warning]

+depcharge is the obvious package name for the installed DepCharge toolbox. However, if a user creates a project containing a +depcharge directory, but that project lacks a containing +package directory, we will have a package namespace conflict.

It may be possible to detect that update is being run from the +depcharge namespace and throw an error. Alternatively, the user created package could have a different name, such as +deplist. Otherwise the toolbox could be +depcharge_toolbox.