|
| 1 | + |
| 2 | +# Code Guidelines |
| 3 | + |
| 4 | +The hub for discussions and best practices on code management! The goal is someone can fork/clone this repo and start a new project easily. This was written by Mackenzie Mathis, and I thank my lab and the open-source community for many lessons learned. |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +This repository is a work-in-progress template for structuring coding projects with clean, reproducible, and collaborative workflows. It includes tools and practices that streamline development, documentation, testing, and deployment. |
| 9 | + |
| 10 | +### Core Components |
| 11 | + |
| 12 | +1. **Code Organization** |
| 13 | + |
| 14 | + * Make a clear folder structure for modules, tests, and configs; try to keep this across project/s |
| 15 | + * Naming conventions and modular design principles, [here are useful standards](https://dmeg.cessda.eu/Data-Management-Expert-Guide/2.-Organise-Document/File-naming-and-folder-structure) to consider. |
| 16 | + |
| 17 | +#### Recommended Directory Structure |
| 18 | + |
| 19 | +```bash |
| 20 | +project_name/ |
| 21 | +├── README.md |
| 22 | +├── LICENSE |
| 23 | +├── pyproject.toml |
| 24 | +├── setup.cfg |
| 25 | +├── .gitignore |
| 26 | +├── .pre-commit-config.yaml |
| 27 | +├── _toc.yml |
| 28 | +├── docker/ |
| 29 | +│ └── Dockerfile |
| 30 | +├── examples/ |
| 31 | +│ └── basic_usage.ipynb |
| 32 | +├── placeholder (project_name)/ # Main package code |
| 33 | +│ ├── __init__.py |
| 34 | +│ ├── module_example.py |
| 35 | + ├── version.py |
| 36 | +│ └── utils/ |
| 37 | +│ └── helpers.py |
| 38 | +├── tests/ |
| 39 | +│ ├── __init__.py |
| 40 | +│ ├── test_module1.py |
| 41 | +│ └── conftest.py |
| 42 | +├── docs/ # JupyterBook documentation |
| 43 | +│ ├── _config.yml |
| 44 | +│ └── index.md |
| 45 | +└── .github/ |
| 46 | + └── workflows/ |
| 47 | + └── codespell.yml |
| 48 | + └── publish-book.yml |
| 49 | +``` |
| 50 | + |
| 51 | +2. **Documentation** |
| 52 | + |
| 53 | + * [JupyterBook](https://jupyterbook.org/en/stable/intro.html) setup for comprehensive, interactive project documentation! |
| 54 | + * Here are [guidelines for writing readable and maintainable docstrings](https://www.datacamp.com/tutorial/docstrings-python) - this is as important as documentation! |
| 55 | + |
| 56 | +3. **Code Formatting & Linting** |
| 57 | + |
| 58 | + * Formatted code makes your life and those who use/review your code easier. Standardized formatting with tools like `black` and `isort` (see the provided `.pre-commit-config.yaml`). |
| 59 | + * [Pre-commit hooks](https://pre-commit.com/) to automate checks before pushing code! Follow their quick Guide to do this, but in short: |
| 60 | + (1) install it in your dev env |
| 61 | + ```python |
| 62 | + pip install pre-commit |
| 63 | + ``` |
| 64 | + (2) install the git hooks: |
| 65 | + ```python |
| 66 | + pre-commit install |
| 67 | + ``` |
| 68 | + (3) Just run it on your code BEFORE you git push: |
| 69 | + ```python |
| 70 | + pre-commit run --all-files |
| 71 | + ``` |
| 72 | +4. **Continuous Integration** |
| 73 | + |
| 74 | + * Use GitHub Actions for automated testing and code quality checks |
| 75 | + * This template repo gies you built-in `codespell`, `publish-book` and `pre-commit` validations (go to actions in your repo to follow the guidelines to set up/also chatGPT can help ;) |
| 76 | + |
| 77 | +5. **Containerization** |
| 78 | + |
| 79 | + * Docker setup for consistent development and deployment environments - this is not just an after thought, use Docker to develop and share your code! |
| 80 | + * Examples of `Dockerfile` and `docker-compose.yml` configurations (coming) |
| 81 | + * You are welcome/encouraged to use our containers: https://hub.docker.com/u/mmathislab |
| 82 | + |
| 83 | +6. **Data Workflow Integration** |
| 84 | + |
| 85 | + * [DataJoint](https://www.datajoint.com/) examples for managing and querying scientific data pipelines - these are a must; use minimally for data + meta data storage, and use it to automate things you do daily (preprocessing, running DeepLabCut, etc!) |
| 86 | + * [Templates for common workflows and schema management are here!](https://docs.datajoint.com/elements/) |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +Contributions welcome as we refine this template! |
| 91 | + |
| 92 | + |
| 93 | +## Acknowledgement |
| 94 | + |
| 95 | +Some items in this repo are adapted from [DeepLabCut](https://github.com/DeepLabCut/DeepLabCut), [CEBRA](https://cebra.ai/), and the [Mathis Lab of Adaptive Intelligence](https://github.com/orgs/AdaptiveMotorControlLab). It is under an Apache 2.0 License. |
0 commit comments