This guide provides AI agents (and developers) with comprehensive information to contribute to and maintain the deep-solutions project.
- Project Engineering Structure
- Code Format & Development Specifications
- Local Testing Guide
- Maintenance & Release Guide
deep-solutions/
├── src/deep_solutions/ # Main package source code
├── tests/ # Unit tests
├── docs/ # Documentation (bilingual)
│ ├── en-US/ # English docs (devs/, user-guide/, design/)
│ └── zh-CN/ # Chinese docs (same structure as en-US)
├── scripts/ # Development & release scripts
├── .github/ # GitHub config (workflows, templates, dependabot)
├── pyproject.toml # Project metadata & tool config
├── environment.yml # Conda environment specification
├── tox.ini # Tox multi-version testing config
├── README.md # English README
├── README.zh-CN.md # Chinese README
└── CHANGELOG.md # Release history
| Directory | Purpose |
|---|---|
src/deep_solutions/ |
Main package modules (core, utils, etc.) |
tests/ |
pytest unit tests |
docs/en-US/ |
English documentation (devs/, user-guide/, design/) |
docs/zh-CN/ |
Chinese documentation (mirrors en-US/ structure) |
scripts/ |
Dev scripts: check.sh, ci-local.sh, check_language.py, document_checker.py, test_release.sh, final_release.sh |
.github/workflows/ |
GitHub Actions: CI, publish, test-report |
.github/ISSUE_TEMPLATE/ |
Issue templates (bug, feature, docs, custom) |
pyproject.toml |
Project config: dependencies, tool settings (ruff, mypy, pytest) |
environment.yml |
Conda environment file for dev setup |
tox.ini |
Multi-Python-version testing (3.8-3.12) |
src/deep_solutions/
├── __init__.py # Public API: hello_world, DeepSolution, format_output, get_library_version
├── _version.py # Auto-generated by setuptools-scm (do not edit)
├── tools/ # User-facing utility tools (public API)
│ ├── helloworld/ # Template/example tool
│ │ ├── core.py # Core functionality (@public_api)
│ │ ├── utils.py # Utility functions (@public_api)
│ │ └── __init__.py # Public API exports
│ └── parameter_search/ # Parameter search library
│ ├── core/ # Core engine (ParamSearcher, SearchResult)
│ ├── epochs/ # Built-in epoch implementations (timed_epoch, simple_epoch)
│ ├── analyzers/ # Result analyzers (BestParamAnalyzer, ChartAnalyzer)
│ └── pytorch/ # PyTorch wrapper (DataLoaderParamSelector)
└── _utils/ # Internal utilities (NOT public API)
├── timer.py # Performance timing
├── metrics.py # Metrics collection
├── decorators.py # @public_api decorator
└── __init__.py # Internal exports
Structure Principles:
tools/: User-facing utilities (public API). Each tool is a complete, task-oriented package. Use@public_apidecorator to mark stable APIs._utils/: Internal, project-agnostic utilities. NOT public API. Users should not import from_utils.- Tests: Match structure under
tests/test_tools/andtests/test__utils/.
| Module | Contents | Purpose |
|---|---|---|
tools/helloworld/ |
hello_world(), DeepSolution, format_output() |
Template tool demonstrating structure |
tools/parameter_search/ |
ParamSearcher, DataLoaderParamSelector |
Parameter space exploration |
_utils/ |
Timer, MetricsCollector, @public_api |
Internal utilities for all modules |
- Language: Python 3.8+ (minimum: 3.8, maximum tested: 3.13)
- Package Manager: Conda + pip
- Build System: setuptools with setuptools-scm (auto-versioning from Git tags)
- Code Quality: Ruff (format + lint), mypy (type checking), pytest (testing)
- CI/CD: GitHub Actions (CI, publish, test-report)
Core Dependencies (runtime):
numpy >= 1.17.0
scipy >= 1.5.0
Development Dependencies (optional):
pytest >= 7.0.0 # Unit testing
pytest-cov >= 4.0.0 # Coverage reporting
ruff >= 0.4.0 # Formatting + linting
mypy >= 1.0.0 # Type checking
build >= 0.10.0 # Building packages
twine >= 4.0.0 # Publishing to PyPI
tox >= 4.0.0 # Multi-version testing
commitizen >= 3.0.0 # Conventional commits
pre-commit >= 3.0.0 # Git hooks
Step 1: Clone the repository
git clone https://github.com/FrostyHec/deep-solutions.git
cd deep-solutionsStep 2: Create Conda environment
conda env create -f environment.yml
conda activate deep-solutionsStep 3: Install the package in editable mode
pip install -e ".[dev]"Step 4: Verify setup
python -c "import deep_solutions; print(f'Version: {deep_solutions.__version__}')"
python -m pytest tests/ -vCore Principle: All pip dependencies managed in pyproject.toml only.
- Runtime deps →
[project].dependencies - Dev deps →
[project.optional-dependencies].dev - Local dev environment must strictly match
pyproject.toml
Update Strategy:
- Runtime deps: Conservative updates (impacts users). Increase minimum version only when needed for features.
- Dev deps: Can update more aggressively (only affects contributors & CI).
Adding a new dependency:
- Create branch:
git checkout -b chore/add-<pkg> - Edit
pyproject.toml(add version like"package>=x.y") - Reinstall:
pip install -U pip && pip install -e ".[dev]" - Verify:
bash scripts/check.sh && tox - Commit with reason (e.g.,
"build(deps): add requests for HTTP support")
Upgrading existing dependency:
When you need a new feature (available in version X.Y):
- Update
pyproject.toml: change>=oldto>=x.y - Reinstall:
pip install -U pip && pip install -e ".[dev]" - Verify:
bash scripts/check.sh && tox
Example:
# Before: numpy>=1.17
# After (need new API): numpy>=1.23
Verification checklist (after any dependency change):
-
pip install -e ".[dev]"succeeds -
bash scripts/check.shpasses -
toxpasses (at least Python 3.8 + latest)
-
Source Code: English only (no Chinese)
- Comments, docstrings, variable names must be in English
- Type hints required for function parameters and returns
-
Documentation: Bilingual (English base + Chinese translations)
- English docs in
docs/en-US/(organized by devs/, user-guide/, design/) - Chinese docs in
docs/zh-CN/(mirrors en-US/ structure) - See Language Guidelines for details
- English docs in
-
Git Commits: English only (Conventional Commits format)
- Format:
type(scope): subject(e.g.,feat(core): add new solver) - See Commit Conventions for details
- Format:
Formatting (Ruff):
- Line length: 88 characters
- Quote style: double quotes (
") - Indent: 4 spaces
Linting (Ruff):
- No unused imports
- PEP 8 compliance
- Bugbear checks enabled
- Comprehension checks enabled
Type Hints (mypy):
- Required for all public functions
- Target Python 3.8 compatibility
- Example:
def process_data(x: List[int]) -> Dict[str, float]: """Process a list of integers.""" return {"mean": sum(x) / len(x)}
Docstrings:
- Use Google-style docstrings
- Include Args, Returns, Raises sections
- Example:
def hello_world() -> str: """Return a greeting message. Returns: A simple greeting string. """ return "Hello from deep-solutions!"
✅ Allowed:
- Documentation in
docs/zh-CN/directory (files prefixed withzh-CN_) - Comments in Chinese documentation files
- User-facing error messages (can be localized), but must use appropriate i18n framework
❌ Not Allowed:
- Source code (
.pyfiles) - Git commit messages
- GitHub issue/PR titles
- Code comments
# Using bash script
bash scripts/check.sh
# Or manually, in order:
ruff format --check src/ tests/ # 1. Format check
ruff check src/ tests/ # 2. Lint check
mypy src/ # 3. Type check
python scripts/check_language.py # 4. Language check
pytest # 5. Unit tests# Run all tests with coverage
pytest
# Run specific test file
pytest tests/test_core.py
# Run with verbose output
pytest -v
# Run only tests matching a pattern
pytest -k "test_hello" -v# Check formatting
ruff format --check src/ tests/
# Auto-fix formatting
ruff format src/ tests/
# Lint check (code quality)
ruff check src/ tests/
# Auto-fix linting issues
ruff check --fix src/ tests/# Type check
mypy src/
# Type check with verbose output
mypy src/ --show-error-codes# Check for Chinese characters in source code
python scripts/check_language.py -vTest against multiple Python versions (3.8-3.12):
# Run all Python versions
tox
# Run specific Python version
tox -e py38
# Run and generate coverage report
tox -- --cov=deep_solutionsView test coverage:
pytest --cov=deep_solutions --cov-report=html
# Open htmlcov/index.html in browserThe project uses setuptools-scm for automatic versioning from Git tags.
Version Format: v<major>.<minor>.<patch> (e.g., v1.0.0, v0.2.1)
Prerequisites (one-time setup):
conda install -c conda-forge gh
gh auth loginTo release version v0.1.1:
Step A — Test on TestPyPI (test_release.sh):
bash scripts/test_release.sh
# Enter tag: v0.1.1.dev1
# If it fails, fix and re-run with v0.1.1.dev2, etc.Step B — Publish to PyPI (final_release.sh):
bash scripts/final_release.sh
# Choose rename mode (y): rename v0.1.1.dev1 → v0.1.1
# Optionally clean up leftover .dev tags
# Script triggers publish.yml and waits for resultShortcut: If you're confident, you can test directly with
v0.1.1in Step A (no.devsuffix), then use direct mode (n) in Step B.
Automates the TestPyPI validation pipeline:
- Reminds you to update CHANGELOG.md
- Switches to main and pulls latest code
- Prompts for version tag (e.g.,
v0.1.1.dev1) - Creates and pushes git tag
- Triggers
publish-test.ymlvia gh CLI - Waits for completion and displays results
Publishes to production PyPI with two modes:
- Rename mode (typical): Renames a tested tag to a clean version
(e.g.,
v0.1.1.dev3→v0.1.1), optionally deletes leftover.devtags. - Direct mode: Uses an existing tag as-is (when you tested with the final version number directly).
Then triggers publish.yml, waits for completion, and reports the result.
| Workflow | Trigger | Purpose |
|---|---|---|
CI |
PR / push to main | Lint, type-check, test (3.8 for PR, full matrix for main) |
Test Report |
After CI completes | Parse test results, post sticky PR comment |
Publish to TestPyPI |
Manual dispatch | Build & publish to TestPyPI for testing |
Publish to PyPI |
Manual dispatch | Build & publish to production PyPI, create Release |
| Command | Purpose |
|---|---|
conda activate deep-solutions |
Activate dev environment |
pip install -e ".[dev]" |
Install package in editable mode with dev deps |
bash scripts/check.sh |
Run all local checks (format, lint, type, language, tests) |
bash scripts/ci-local.sh |
Simulate CI pipeline locally |
python scripts/check_language.py |
Check English-only code (calls document_checker) |
python scripts/document_checker.py |
Check bilingual docs, broken refs, structure |
pytest |
Run unit tests |
ruff format src/ tests/ |
Auto-fix code formatting |
ruff check --fix src/ tests/ |
Auto-fix linting issues |
mypy src/ |
Type check |
tox |
Test on Python 3.8-3.12 |
git tag -a v1.0.0 -m "Release v1.0.0" |
Create release tag |
python -m build |
Build distribution (wheel + sdist) |
twine upload dist/* |
Upload to PyPI |
When the project file structure changes significantly, the following documents must be updated to stay in sync:
| Document | What to Update |
|---|---|
en-US_project_structure.md + zh-CN_project_structure.md |
Directory tree, file descriptions |
en-US_agent.md + zh-CN_agent.md |
Directory layout (§0), scripts table |
docs/{en-US,zh-CN}/index.md |
Top-level doc index if new subdirs added |
docs/{en-US,zh-CN}/{subdir}/index.md |
Subdir index if files added/removed |
README.md + README.zh-CN.md |
Documentation links table |
- English docs:
docs/en-US/{subdir}/en-US_filename.md - Chinese docs:
docs/zh-CN/{subdir}/zh-CN_filename.md - Every new doc must have both EN and ZH versions
- Every directory must contain an
index.md check_language.pyenforces bilingual parity automatically
- Developer Guide - Detailed setup and contribution workflow
- Code Standards - PR workflow, merge requirements
- Commit Conventions - Conventional Commits format
- Project Structure - Dependency management details
- CI Workflow - GitHub Actions pipeline details
- Local Testing - Comprehensive testing guide
- Publishing - Release process deep dive
- Language Guidelines - Language policy