All pull requests, large or small, from anyone are welcome!
uv is the suggested python environment management tool.
- Install uv, as described in the uv installation guide.
uv python install 3.12-- This project requires Python 3.12+.uv python pin 3.12-- Pin the default version.uv self updateuv sync --all-groups- The
.venv/directory will now be created with all project, development and documentation dependencies installed.- Be sure to point your IDE to the python binary appropriate for your OS in this directory.
pre-commit install-- Set up pre-commit hooks for automatic formatting and linting on commit.
- tox
- Creates virtual environments for CI or local pytest runs.
- Note that the CI does not current execute calls to the production API by default.
- Run
tox listor seetox.inifor more info
- Creates virtual environments for CI or local pytest runs.
- pre-commit
- Creates virtual environments for formatting and linting tools
- Run
pre-commit run --all-filesor see.pre-commit-config.yamlfor more info.
Note: Many of the tools below are run by
pre-commitautomatically, but can also be run manually if desired.
- ruff
- Provides both formatting and linting
- Format:
ruff format . - Lint:
ruff check . --fix - Combined:
ruff format . && ruff check . --fix - See
pyproject.tomlfor the rules used. - See all rules (but not necessarily used in the project) available in ruff here.
- ty
- Type checker:
ty check .
- Type checker:
- pyright
- Shipped with vscode by default (via the python extension
ms-python.vscode-pylance) - Suggested settings:
"python.analysis.typeCheckingMode": "off"- The pylance extension has certain opinionated type checking assertions which clash with other type checkers.
- For example, overriding an optional field to be non-optional is considered by pylance to be a type error due to the field being invariant and the parent class potentially settings it to
None. However, by convention in the SDK, this is a forbidden pattern.
"python.analysis.languageServerMode": "full""python.testing.pytestEnabled": true
- Shipped with vscode by default (via the python extension
- tach
- Enforces internal namespace dependency constraints. This helps avoid circular dependencies and helps ensure implementations are in a logical place.
Tests require the AI_HORDE_TESTING=True environment variable to be set. This prevents interference from user-specific environment variables.
# Set the required env var and run tests
export AI_HORDE_TESTING=True
pytest
# Run with coverage
pytest --cov=horde_model_reference --cov-report=html
# Run a specific test file
pytest tests/test_model_reference_manager.py- Singleton reset: Use the
restore_manager_singletonfixture to ensureModelReferenceManageris restored to its pre-test state after your test. This is critical when testing with different manager configurations. - Temp directories: Use the
primary_basefixture for tests that need an isolated temp directory for PRIMARY mode file operations. - Test ordering: Tests in
test_scripts,test_convert_legacy_database, andtest_model_reference_managerrun in a fixed order (defined inconftest.py). Other tests run in arbitrary order.
- Fork the repository and create a feature branch from
main - Make your changes
- Run the quality checks:
ruff format . && ruff check . --fix && ty check . - Run the tests:
AI_HORDE_TESTING=True pytest - Commit with a clear message and open a pull request
- See the python haidra style guide for standards on code style, system design, testing, and documentation.