jupyter-ai
jupyter-ai copied to clipboard
[v3.x.x] Define a directory structure for the `jupyter_ai` package
trafficstars
Problem
The Python code under packages/jupyter-ai/jupyter_ai lacks a directory structure. The location of each file was just determined by whoever added it first.
This brings about a few minor issues for contributors:
- A disorganized directory structure makes it hard to find specific source files.
- A disorganized directory structure makes it easy to create circular dependencies.
- All of the unit tests are being placed under a single
test/directory, which is often far removed from the source code it is testing.
Proposed Solution
Define a directory structure under the "top level", which we use to denote packages/jupyter-ai/jupyter_ai:
- Direct children of the top level should only be directories that contain source files.
- Each direct child should contain an
__init__.pyfile that exports everything from within that directory. - Each direct child may contain a
README.mdfile that explains the contents of that directory & their purpose. - Unit tests should be placed only within direct children.
For example, if we follow this structure, config_manager.py should be broken down into 4 files under a new config_manager/ directory:
config_manager/config_manager.py: Implements the config manager.config_manager/__init__.py: Exports the config manager.config_manager/tests/: Contains unit tests for the config manager, e.g.test_config_manager.py.config_manager/README.md: Explain the contents of this directory to developers.
Additional context
This can be documented in the contributor docs for v3, but I don't think that's really a priority / something that needs to be tracked. The directory structure proposed here was designed to be fairly intuitive & obvious for other contributors to follow.