rhiza 0.4.0__tar.gz → 0.5.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rhiza-0.5.1/.github/README.md +33 -0
- rhiza-0.5.1/.github/TOKEN_SETUP.md +102 -0
- rhiza-0.5.1/.github/copilot-instructions.md +349 -0
- rhiza-0.5.1/.github/workflows/sync.yml +142 -0
- rhiza-0.5.1/CLI.md +347 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/Makefile +2 -2
- rhiza-0.5.1/PKG-INFO +778 -0
- rhiza-0.5.1/README.md +745 -0
- rhiza-0.5.1/USAGE.md +668 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/pyproject.toml +2 -2
- {rhiza-0.4.0 → rhiza-0.5.1}/src/rhiza/__init__.py +2 -0
- rhiza-0.5.1/src/rhiza/cli.py +115 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/src/rhiza/commands/__init__.py +4 -0
- rhiza-0.5.1/src/rhiza/commands/init.py +64 -0
- rhiza-0.4.0/src/rhiza/commands/inject.py → rhiza-0.5.1/src/rhiza/commands/materialize.py +35 -36
- rhiza-0.5.1/src/rhiza/commands/validate.py +136 -0
- rhiza-0.5.1/src/rhiza/models.py +88 -0
- rhiza-0.5.1/tests/test_cli_commands.py +112 -0
- rhiza-0.5.1/tests/test_commands/test_init.py +105 -0
- rhiza-0.4.0/tests/test_cli_commands.py → rhiza-0.5.1/tests/test_commands/test_materialize.py +170 -206
- rhiza-0.5.1/tests/test_commands/test_validate.py +356 -0
- rhiza-0.5.1/tests/test_models.py +183 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/uv.lock +5 -5
- rhiza-0.4.0/.github/scripts/sync.sh +0 -310
- rhiza-0.4.0/.github/workflows/sync.yml +0 -41
- rhiza-0.4.0/PKG-INFO +0 -35
- rhiza-0.4.0/README.md +0 -2
- rhiza-0.4.0/src/rhiza/cli.py +0 -47
- rhiza-0.4.0/src/rhiza/commands/hello.py +0 -9
- {rhiza-0.4.0 → rhiza-0.5.1}/.editorconfig +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/actions/setup-project/action.yml +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/renovate.json +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/scripts/book.sh +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/scripts/bump.sh +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/scripts/customisations/build-extras.sh +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/scripts/customisations/post-release.sh +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/scripts/marimushka.sh +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/scripts/release.sh +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/scripts/update-readme-help.sh +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/template.yml +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/workflows/book.yml +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/workflows/ci.yml +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/workflows/deptry.yml +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/workflows/marimo.yml +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/workflows/pre-commit.yml +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/workflows/release.yml +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/workflows/scripts/version_matrix.py +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/workflows/scripts/version_max.py +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.github/workflows/structure.yml +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.gitignore +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/.pre-commit-config.yaml +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/CODE_OF_CONDUCT.md +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/CONTRIBUTING.md +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/LICENSE +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/book/marimo/.gitkeep +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/pytest.ini +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/ruff.toml +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/src/rhiza/__main__.py +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/tests/test_rhiza/README.md +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/tests/test_rhiza/conftest.py +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/tests/test_rhiza/test_bump_script.py +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/tests/test_rhiza/test_docstrings.py +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/tests/test_rhiza/test_git_repo_fixture.py +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/tests/test_rhiza/test_makefile.py +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/tests/test_rhiza/test_marimushka_script.py +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/tests/test_rhiza/test_readme.py +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/tests/test_rhiza/test_release_script.py +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/tests/test_rhiza/test_structure.py +0 -0
- {rhiza-0.4.0 → rhiza-0.5.1}/tests/test_rhiza/test_updatereadme_script.py +0 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# GitHub Configuration
|
|
2
|
+
|
|
3
|
+
This directory contains the GitHub-specific configuration for the repository.
|
|
4
|
+
|
|
5
|
+
## Important Documentation
|
|
6
|
+
|
|
7
|
+
- **[TOKEN_SETUP.md](TOKEN_SETUP.md)** - Instructions for setting up the `PAT_TOKEN` secret required for the SYNC workflow
|
|
8
|
+
|
|
9
|
+
## Workflows
|
|
10
|
+
|
|
11
|
+
The repository uses several automated workflows:
|
|
12
|
+
|
|
13
|
+
- **SYNC** (`workflows/sync.yml`) - Synchronizes with the template repository
|
|
14
|
+
- **Requires:** `PAT_TOKEN` secret with `workflow` scope when modifying workflow files
|
|
15
|
+
- See [TOKEN_SETUP.md](TOKEN_SETUP.md) for configuration
|
|
16
|
+
- **CI** (`workflows/ci.yml`) - Continuous integration tests
|
|
17
|
+
- **Pre-commit** (`workflows/pre-commit.yml`) - Code quality checks
|
|
18
|
+
- **Book** (`workflows/book.yml`) - Documentation deployment
|
|
19
|
+
- **Release** (`workflows/release.yml`) - Package publishing
|
|
20
|
+
- **Deptry** (`workflows/deptry.yml`) - Dependency checks
|
|
21
|
+
- **Marimo** (`workflows/marimo.yml`) - Interactive notebooks
|
|
22
|
+
|
|
23
|
+
## Template Synchronization
|
|
24
|
+
|
|
25
|
+
This repository is synchronized with the template repository defined in `template.yml`.
|
|
26
|
+
|
|
27
|
+
The synchronization includes:
|
|
28
|
+
- GitHub workflows and actions
|
|
29
|
+
- Development tools configuration (`.editorconfig`, `ruff.toml`, etc.)
|
|
30
|
+
- Testing infrastructure
|
|
31
|
+
- Documentation templates
|
|
32
|
+
|
|
33
|
+
See `template.yml` for the complete list of synchronized files and exclusions.
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# GitHub Personal Access Token (PAT) Setup
|
|
2
|
+
|
|
3
|
+
This document explains how to set up a Personal Access Token (PAT) for the repository's automated workflows.
|
|
4
|
+
|
|
5
|
+
## Why is PAT_TOKEN needed?
|
|
6
|
+
|
|
7
|
+
The repository uses the `SYNC` workflow (`.github/workflows/sync.yml`) to automatically synchronize with a template repository. When this workflow modifies files in `.github/workflows/`, GitHub requires special permissions that the default `GITHUB_TOKEN` doesn't have.
|
|
8
|
+
|
|
9
|
+
According to GitHub's security policy:
|
|
10
|
+
- The default `GITHUB_TOKEN` **cannot** create or update workflow files (`.github/workflows/*.yml`)
|
|
11
|
+
- A Personal Access Token with the `workflow` scope **is required** to push changes to workflow files
|
|
12
|
+
|
|
13
|
+
## Creating a PAT with workflow scope
|
|
14
|
+
|
|
15
|
+
Follow these steps to create a properly scoped Personal Access Token:
|
|
16
|
+
|
|
17
|
+
### 1. Navigate to GitHub Settings
|
|
18
|
+
|
|
19
|
+
1. Go to [GitHub.com](https://github.com)
|
|
20
|
+
2. Click your profile picture (top-right corner)
|
|
21
|
+
3. Click **Settings**
|
|
22
|
+
4. Scroll down and click **Developer settings** (bottom of left sidebar)
|
|
23
|
+
5. Click **Personal access tokens** → **Tokens (classic)**
|
|
24
|
+
|
|
25
|
+
### 2. Generate a new token
|
|
26
|
+
|
|
27
|
+
1. Click **Generate new token** → **Generate new token (classic)**
|
|
28
|
+
2. Give your token a descriptive name, e.g., `TinyCTA Workflow Sync Token`
|
|
29
|
+
3. Set an expiration date (recommended: 90 days or less for security)
|
|
30
|
+
|
|
31
|
+
### 3. Select the required scopes
|
|
32
|
+
|
|
33
|
+
**Required scopes:**
|
|
34
|
+
- ✅ `repo` (Full control of private repositories)
|
|
35
|
+
- This automatically includes all repo sub-scopes
|
|
36
|
+
- ✅ `workflow` (Update GitHub Action workflows)
|
|
37
|
+
- **This is critical** - without this scope, pushing workflow changes will fail
|
|
38
|
+
|
|
39
|
+
**Optional but recommended:**
|
|
40
|
+
- `write:packages` (if the workflow publishes packages)
|
|
41
|
+
|
|
42
|
+
### 4. Generate and copy the token
|
|
43
|
+
|
|
44
|
+
1. Click **Generate token** at the bottom
|
|
45
|
+
2. **Important:** Copy the token immediately - you won't be able to see it again!
|
|
46
|
+
3. Store it securely (e.g., in a password manager)
|
|
47
|
+
|
|
48
|
+
### 5. Add the token to repository secrets
|
|
49
|
+
|
|
50
|
+
1. Navigate to your repository on GitHub
|
|
51
|
+
2. Click **Settings** tab
|
|
52
|
+
3. Click **Secrets and variables** → **Actions** (left sidebar)
|
|
53
|
+
4. Click **New repository secret**
|
|
54
|
+
5. Name: `PAT_TOKEN`
|
|
55
|
+
6. Value: Paste the token you copied
|
|
56
|
+
7. Click **Add secret**
|
|
57
|
+
|
|
58
|
+
## Verifying the setup
|
|
59
|
+
|
|
60
|
+
After adding the `PAT_TOKEN` secret:
|
|
61
|
+
|
|
62
|
+
1. Navigate to **Actions** tab in your repository
|
|
63
|
+
2. Find the **SYNC** workflow
|
|
64
|
+
3. Click **Run workflow** to manually trigger it
|
|
65
|
+
4. If workflow files are modified, the workflow should successfully push them
|
|
66
|
+
|
|
67
|
+
## Troubleshooting
|
|
68
|
+
|
|
69
|
+
### Error: "refusing to allow a GitHub App to create or update workflow"
|
|
70
|
+
|
|
71
|
+
This error means either:
|
|
72
|
+
- The `PAT_TOKEN` secret is not set
|
|
73
|
+
- The `PAT_TOKEN` exists but lacks the `workflow` scope
|
|
74
|
+
|
|
75
|
+
**Solution:** Create a new token with the `workflow` scope and update the `PAT_TOKEN` secret.
|
|
76
|
+
|
|
77
|
+
### Error: "push_succeeded=false"
|
|
78
|
+
|
|
79
|
+
This usually indicates:
|
|
80
|
+
- The token has expired
|
|
81
|
+
- The token was revoked
|
|
82
|
+
- The token lacks necessary permissions
|
|
83
|
+
|
|
84
|
+
**Solution:** Generate a new token following the steps above and update the secret.
|
|
85
|
+
|
|
86
|
+
## Security best practices
|
|
87
|
+
|
|
88
|
+
1. **Limit scope:** Only grant the minimum required scopes (`repo` and `workflow`)
|
|
89
|
+
2. **Set expiration:** Use short-lived tokens (30-90 days) and rotate them regularly
|
|
90
|
+
3. **Monitor usage:** Regularly review your token usage in GitHub settings
|
|
91
|
+
4. **Revoke unused tokens:** Delete tokens that are no longer needed
|
|
92
|
+
5. **Use separate tokens:** Don't reuse tokens across multiple projects
|
|
93
|
+
|
|
94
|
+
## Alternative: GitHub App (Advanced)
|
|
95
|
+
|
|
96
|
+
For organizations, consider using a GitHub App instead of PAT:
|
|
97
|
+
- More secure and granular permissions
|
|
98
|
+
- Better audit logging
|
|
99
|
+
- No expiration issues
|
|
100
|
+
- Requires more setup complexity
|
|
101
|
+
|
|
102
|
+
Refer to [GitHub's documentation](https://docs.github.com/en/apps) for details on creating GitHub Apps.
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
# GitHub Copilot Instructions for rhiza-cli
|
|
2
|
+
|
|
3
|
+
## Project Overview
|
|
4
|
+
|
|
5
|
+
Rhiza is a command-line interface (CLI) tool for managing reusable configuration templates for modern Python projects. It provides commands for initializing, validating, and materializing configuration templates across projects.
|
|
6
|
+
|
|
7
|
+
**Repository:** <https://github.com/jebel-quant/rhiza-cli>
|
|
8
|
+
|
|
9
|
+
## Technology Stack
|
|
10
|
+
|
|
11
|
+
- **Language:** Python 3.11+ (supports 3.11, 3.12, 3.13, 3.14)
|
|
12
|
+
- **Package Manager:** uv (fast Python package installer and resolver)
|
|
13
|
+
- **CLI Framework:** Typer
|
|
14
|
+
- **Testing:** pytest with coverage reporting
|
|
15
|
+
- **Linting/Formatting:** Ruff
|
|
16
|
+
- **Build System:** Hatchling
|
|
17
|
+
- **Pre-commit Hooks:** YAML/TOML validation, Ruff, markdownlint, actionlint
|
|
18
|
+
|
|
19
|
+
## Project Structure
|
|
20
|
+
|
|
21
|
+
```text
|
|
22
|
+
rhiza-cli/
|
|
23
|
+
├── src/rhiza/ # Main source code
|
|
24
|
+
│ ├── cli.py # CLI entry points (Typer app)
|
|
25
|
+
│ └── commands/ # Command implementations
|
|
26
|
+
├── tests/ # Test suite
|
|
27
|
+
├── book/ # Documentation and Marimo notebooks
|
|
28
|
+
├── .github/ # GitHub workflows and scripts
|
|
29
|
+
├── pyproject.toml # Project configuration
|
|
30
|
+
├── ruff.toml # Linting configuration
|
|
31
|
+
└── Makefile # Development tasks
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Coding Standards
|
|
35
|
+
|
|
36
|
+
### Python Style
|
|
37
|
+
|
|
38
|
+
- **Line length:** Maximum 120 characters
|
|
39
|
+
- **Quotes:** Use double quotes for strings
|
|
40
|
+
- **Indentation:** 4 spaces (no tabs)
|
|
41
|
+
- **Docstrings:** Google style convention (required for all public modules, classes, and functions)
|
|
42
|
+
- **Type hints:** Not strictly enforced but encouraged
|
|
43
|
+
- **Import sorting:** Automatic via isort (part of Ruff)
|
|
44
|
+
|
|
45
|
+
### Linting Rules
|
|
46
|
+
|
|
47
|
+
The project uses Ruff with the following rule sets:
|
|
48
|
+
|
|
49
|
+
- **D** (pydocstyle): Docstring style enforcement
|
|
50
|
+
- **E** (pycodestyle): PEP 8 style guide errors
|
|
51
|
+
- **F** (pyflakes): Logical error detection
|
|
52
|
+
- **I** (isort): Import sorting
|
|
53
|
+
- **N** (pep8-naming): PEP 8 naming conventions
|
|
54
|
+
- **W** (pycodestyle): PEP 8 warnings
|
|
55
|
+
- **UP** (pyupgrade): Modern Python syntax
|
|
56
|
+
|
|
57
|
+
**Exception:** Tests allow assert statements (S101 ignored in tests/)
|
|
58
|
+
|
|
59
|
+
### Docstring Requirements
|
|
60
|
+
|
|
61
|
+
- All public modules, classes, functions, and methods must have docstrings
|
|
62
|
+
- Use Google docstring convention
|
|
63
|
+
- Include magic methods like `__init__` (D105, D107 enforced)
|
|
64
|
+
- Use multi-line format with summary line, then blank line, then details
|
|
65
|
+
|
|
66
|
+
Example:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
def my_function(arg1: str, arg2: int) -> bool:
|
|
70
|
+
"""Short summary of what the function does.
|
|
71
|
+
|
|
72
|
+
Longer description if needed. Explain complex behavior,
|
|
73
|
+
side effects, or important context.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
arg1: Description of arg1
|
|
77
|
+
arg2: Description of arg2
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
Description of return value (bool)
|
|
81
|
+
"""
|
|
82
|
+
return True
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Development Workflow
|
|
86
|
+
|
|
87
|
+
### Setup
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
make install # Install dependencies with uv
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Common Commands
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
make fmt # Run linters and formatters (pre-commit)
|
|
97
|
+
make test # Run tests with coverage
|
|
98
|
+
make docs # Generate documentation with pdoc
|
|
99
|
+
make clean # Clean build artifacts
|
|
100
|
+
make help # Show all available commands
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Testing
|
|
104
|
+
|
|
105
|
+
- Use pytest for all tests
|
|
106
|
+
- Place tests in `tests/` directory
|
|
107
|
+
- Test files should match pattern `test_*.py`
|
|
108
|
+
- Aim for good coverage of new code
|
|
109
|
+
- Run tests with `make test` before submitting changes
|
|
110
|
+
|
|
111
|
+
### Pre-commit Hooks
|
|
112
|
+
|
|
113
|
+
The project uses pre-commit hooks that run automatically on commit:
|
|
114
|
+
|
|
115
|
+
- YAML/TOML validation
|
|
116
|
+
- Ruff linting and formatting
|
|
117
|
+
- Markdown linting (MD013 disabled for long lines)
|
|
118
|
+
- GitHub workflow validation
|
|
119
|
+
- Renovate config validation
|
|
120
|
+
- README.md auto-update with Makefile help
|
|
121
|
+
|
|
122
|
+
## Architecture Notes
|
|
123
|
+
|
|
124
|
+
### CLI Structure
|
|
125
|
+
|
|
126
|
+
The CLI uses Typer for command definitions. Commands are thin wrappers in `cli.py` that delegate to implementations in `rhiza.commands.*`:
|
|
127
|
+
|
|
128
|
+
- `init`: Initialize or validate `.github/template.yml`
|
|
129
|
+
- `materialize` (alias `inject`): Apply templates to a target repository
|
|
130
|
+
- `validate`: Validate template configuration
|
|
131
|
+
|
|
132
|
+
### Command Implementation Pattern
|
|
133
|
+
|
|
134
|
+
1. Command defined in `src/rhiza/cli.py` using Typer decorators
|
|
135
|
+
2. Implementation logic in `src/rhiza/commands/*.py`
|
|
136
|
+
3. Commands use `loguru` for logging
|
|
137
|
+
4. Use `Path` from `pathlib` for file operations
|
|
138
|
+
|
|
139
|
+
## Best Practices
|
|
140
|
+
|
|
141
|
+
1. **Minimal changes:** Make surgical, focused changes
|
|
142
|
+
2. **Type hints:** Use when they improve clarity
|
|
143
|
+
3. **Error handling:** Use appropriate exceptions, log errors clearly
|
|
144
|
+
4. **Documentation:** Update docstrings when changing function signatures
|
|
145
|
+
5. **Tests:** Add tests for new functionality
|
|
146
|
+
6. **Imports:** Keep imports organized (isort handles this automatically)
|
|
147
|
+
7. **File headers:** Include repository attribution comment at top of new files:
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
# This file is part of the jebel-quant/rhiza repository
|
|
151
|
+
# (https://github.com/jebel-quant/rhiza).
|
|
152
|
+
#
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Dependencies
|
|
156
|
+
|
|
157
|
+
### Core Dependencies
|
|
158
|
+
|
|
159
|
+
See `pyproject.toml` for exact versions. Key dependencies:
|
|
160
|
+
|
|
161
|
+
- `typer` - CLI framework
|
|
162
|
+
- `loguru` - Logging
|
|
163
|
+
- `PyYAML` - YAML parsing
|
|
164
|
+
|
|
165
|
+
### Development Dependencies
|
|
166
|
+
|
|
167
|
+
See `pyproject.toml` for complete list. Key dev dependencies:
|
|
168
|
+
|
|
169
|
+
- `pytest`, `pytest-cov`, `pytest-html` - Testing
|
|
170
|
+
- `pre-commit` - Git hooks
|
|
171
|
+
- `marimo` - Notebook support
|
|
172
|
+
- `pdoc` - Documentation generation
|
|
173
|
+
|
|
174
|
+
## Common Patterns
|
|
175
|
+
|
|
176
|
+
### Path Handling
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
from pathlib import Path
|
|
180
|
+
|
|
181
|
+
target = Path(".") # Use Path objects, not strings
|
|
182
|
+
if target.exists():
|
|
183
|
+
# Do something
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Logging
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
from loguru import logger
|
|
190
|
+
|
|
191
|
+
logger.info("Starting operation")
|
|
192
|
+
logger.error("Something went wrong")
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### CLI Arguments
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
import typer
|
|
199
|
+
|
|
200
|
+
@app.command()
|
|
201
|
+
def my_command(
|
|
202
|
+
target: Path = typer.Argument(
|
|
203
|
+
default=Path("."),
|
|
204
|
+
exists=True,
|
|
205
|
+
help="Description"
|
|
206
|
+
),
|
|
207
|
+
):
|
|
208
|
+
"""Command docstring."""
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Security Considerations
|
|
212
|
+
|
|
213
|
+
- **No secrets in code:** Never commit API keys, passwords, or sensitive data
|
|
214
|
+
- **Path traversal:** Always use `Path.resolve()` to normalize paths and prevent directory traversal attacks
|
|
215
|
+
- **Input validation:** Validate all user inputs, especially file paths and command arguments
|
|
216
|
+
- **YAML parsing:** Use safe YAML loading (PyYAML uses safe loading by default)
|
|
217
|
+
- **File permissions:** Be mindful of file permissions when creating files
|
|
218
|
+
|
|
219
|
+
## Error Handling Patterns
|
|
220
|
+
|
|
221
|
+
### Exception Handling
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
from loguru import logger
|
|
225
|
+
from pathlib import Path
|
|
226
|
+
|
|
227
|
+
def safe_operation(path: Path):
|
|
228
|
+
"""Safe operation with proper error handling."""
|
|
229
|
+
try:
|
|
230
|
+
# Normalize path to prevent traversal
|
|
231
|
+
path = path.resolve()
|
|
232
|
+
|
|
233
|
+
if not path.exists():
|
|
234
|
+
logger.error(f"Path does not exist: {path}")
|
|
235
|
+
raise FileNotFoundError(f"Path not found: {path}")
|
|
236
|
+
|
|
237
|
+
# Perform operation
|
|
238
|
+
return True
|
|
239
|
+
|
|
240
|
+
except PermissionError as e:
|
|
241
|
+
logger.error(f"Permission denied: {e}")
|
|
242
|
+
raise
|
|
243
|
+
except Exception as e:
|
|
244
|
+
logger.error(f"Unexpected error: {e}")
|
|
245
|
+
raise
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### CLI Exit Codes
|
|
249
|
+
|
|
250
|
+
Use Typer's `Exit` for non-zero exit codes on errors:
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
import typer
|
|
254
|
+
|
|
255
|
+
if not success:
|
|
256
|
+
raise typer.Exit(code=1)
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Common Tasks
|
|
260
|
+
|
|
261
|
+
### Adding a New Command
|
|
262
|
+
|
|
263
|
+
1. Create a new file in `src/rhiza/commands/` (e.g., `newcommand.py`)
|
|
264
|
+
2. Implement the command logic with proper docstrings
|
|
265
|
+
3. Add a wrapper in `src/rhiza/cli.py` using Typer decorators
|
|
266
|
+
4. Add tests in `tests/` for the new command
|
|
267
|
+
5. Update documentation if needed
|
|
268
|
+
|
|
269
|
+
Example:
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
# In src/rhiza/commands/newcommand.py
|
|
273
|
+
from pathlib import Path
|
|
274
|
+
from loguru import logger
|
|
275
|
+
|
|
276
|
+
def my_new_command(target: Path):
|
|
277
|
+
"""Execute the new command.
|
|
278
|
+
|
|
279
|
+
Parameters
|
|
280
|
+
----------
|
|
281
|
+
target:
|
|
282
|
+
Path to the target directory.
|
|
283
|
+
"""
|
|
284
|
+
target = target.resolve()
|
|
285
|
+
logger.info(f"Running new command on: {target}")
|
|
286
|
+
# Implementation here
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
```python
|
|
290
|
+
# In src/rhiza/cli.py
|
|
291
|
+
from rhiza.commands.newcommand import my_new_command
|
|
292
|
+
|
|
293
|
+
@app.command()
|
|
294
|
+
def newcommand(
|
|
295
|
+
target: Path = typer.Argument(
|
|
296
|
+
default=Path("."),
|
|
297
|
+
exists=True,
|
|
298
|
+
file_okay=False,
|
|
299
|
+
dir_okay=True,
|
|
300
|
+
help="Target directory"
|
|
301
|
+
),
|
|
302
|
+
):
|
|
303
|
+
"""Short description of the command."""
|
|
304
|
+
my_new_command(target)
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Running the CLI in Development
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
# Install in editable mode
|
|
311
|
+
make install
|
|
312
|
+
|
|
313
|
+
# Run the CLI
|
|
314
|
+
uv run rhiza --help
|
|
315
|
+
uv run rhiza init
|
|
316
|
+
uv run rhiza materialize --branch main
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## Troubleshooting
|
|
320
|
+
|
|
321
|
+
### Common Issues
|
|
322
|
+
|
|
323
|
+
**Import errors after adding dependencies:**
|
|
324
|
+
- Run `make install` to sync dependencies
|
|
325
|
+
- Ensure `pyproject.toml` is updated with new dependencies
|
|
326
|
+
|
|
327
|
+
**Linting failures:**
|
|
328
|
+
- Run `make fmt` to auto-fix most issues
|
|
329
|
+
- Check `ruff.toml` for configured rules
|
|
330
|
+
- Ensure docstrings follow Google convention
|
|
331
|
+
|
|
332
|
+
**Test failures:**
|
|
333
|
+
- Run `make test` to see detailed output
|
|
334
|
+
- Check test coverage report in `_tests/html-coverage/`
|
|
335
|
+
- Ensure new code has corresponding tests
|
|
336
|
+
|
|
337
|
+
**Pre-commit hook failures:**
|
|
338
|
+
- Run `make fmt` to fix formatting issues
|
|
339
|
+
- Check `.pre-commit-config.yaml` for hook configuration
|
|
340
|
+
- Install hooks with `uv run pre-commit install`
|
|
341
|
+
|
|
342
|
+
## When Making Changes
|
|
343
|
+
|
|
344
|
+
1. Run `make fmt` to ensure code follows style guidelines
|
|
345
|
+
2. Run `make test` to verify tests pass
|
|
346
|
+
3. Update docstrings if changing public APIs
|
|
347
|
+
4. Add tests for new functionality
|
|
348
|
+
5. Keep changes focused and minimal
|
|
349
|
+
6. Follow existing code patterns and conventions
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
name: SYNC
|
|
2
|
+
# This workflow synchronizes the repository with its template.
|
|
3
|
+
# IMPORTANT: When workflow files (.github/workflows/*.yml) are modified,
|
|
4
|
+
# a Personal Access Token (PAT) with 'workflow' scope is required.
|
|
5
|
+
# The PAT_TOKEN secret must be set in repository secrets.
|
|
6
|
+
# See .github/TOKEN_SETUP.md for setup instructions.
|
|
7
|
+
permissions:
|
|
8
|
+
contents: write
|
|
9
|
+
pull-requests: write
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
on:
|
|
13
|
+
workflow_dispatch:
|
|
14
|
+
inputs:
|
|
15
|
+
create-pr:
|
|
16
|
+
description: "Create a pull request"
|
|
17
|
+
type: boolean
|
|
18
|
+
default: true
|
|
19
|
+
schedule:
|
|
20
|
+
- cron: '0 0 * * 1' # Weekly on Monday
|
|
21
|
+
|
|
22
|
+
jobs:
|
|
23
|
+
sync:
|
|
24
|
+
if: ${{ github.repository != 'jebel-quant/rhiza' && github.ref_name != 'rhiza_update' }}
|
|
25
|
+
runs-on: ubuntu-latest
|
|
26
|
+
|
|
27
|
+
steps:
|
|
28
|
+
- name: Checkout repository
|
|
29
|
+
uses: actions/checkout@v6
|
|
30
|
+
with:
|
|
31
|
+
token: ${{ secrets.PAT_TOKEN }}
|
|
32
|
+
fetch-depth: 0
|
|
33
|
+
|
|
34
|
+
- name: Check PAT_TOKEN configuration
|
|
35
|
+
shell: bash
|
|
36
|
+
env:
|
|
37
|
+
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
|
|
38
|
+
run: |
|
|
39
|
+
if [ -z "$PAT_TOKEN" ]; then
|
|
40
|
+
echo "::warning::PAT_TOKEN secret is not configured."
|
|
41
|
+
echo "::warning::If this sync modifies workflow files, the push will fail."
|
|
42
|
+
echo "::warning::See .github/TOKEN_SETUP.md for setup instructions."
|
|
43
|
+
else
|
|
44
|
+
echo "✓ PAT_TOKEN is configured."
|
|
45
|
+
fi
|
|
46
|
+
|
|
47
|
+
- name: Install uv
|
|
48
|
+
uses: astral-sh/setup-uv@v7
|
|
49
|
+
|
|
50
|
+
- name: Validate repository
|
|
51
|
+
shell: bash
|
|
52
|
+
run: |
|
|
53
|
+
uvx rhiza validate .
|
|
54
|
+
|
|
55
|
+
- name: Sync template
|
|
56
|
+
id: sync
|
|
57
|
+
shell: bash
|
|
58
|
+
env:
|
|
59
|
+
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
|
|
60
|
+
run: |
|
|
61
|
+
set -euo pipefail
|
|
62
|
+
|
|
63
|
+
git checkout -B rhiza_update
|
|
64
|
+
|
|
65
|
+
uvx rhiza materialize --force .
|
|
66
|
+
|
|
67
|
+
git add -A
|
|
68
|
+
|
|
69
|
+
if git diff --cached --quiet; then
|
|
70
|
+
echo "No changes detected."
|
|
71
|
+
{
|
|
72
|
+
echo "changes_detected=false"
|
|
73
|
+
echo "workflows_changed=false"
|
|
74
|
+
echo "push_succeeded=false"
|
|
75
|
+
} >> "$GITHUB_OUTPUT"
|
|
76
|
+
exit 0
|
|
77
|
+
fi
|
|
78
|
+
|
|
79
|
+
echo "changes_detected=true" >> "$GITHUB_OUTPUT"
|
|
80
|
+
|
|
81
|
+
workflows_changed=false
|
|
82
|
+
can_push=true
|
|
83
|
+
|
|
84
|
+
if git diff --cached --name-only | grep -q '^\.github/workflows/'; then
|
|
85
|
+
workflows_changed=true
|
|
86
|
+
echo "workflows_changed=true" >> "$GITHUB_OUTPUT"
|
|
87
|
+
echo "⚠️ Workflow files modified."
|
|
88
|
+
echo ""
|
|
89
|
+
echo "ℹ️ Pushing workflow changes requires a PAT with 'workflow' scope."
|
|
90
|
+
|
|
91
|
+
if [ -n "$PAT_TOKEN" ]; then
|
|
92
|
+
git remote set-url origin \
|
|
93
|
+
"https://x-access-token:${PAT_TOKEN}@github.com/${{ github.repository }}.git"
|
|
94
|
+
echo "✓ Using PAT_TOKEN for authentication."
|
|
95
|
+
else
|
|
96
|
+
echo "::error::Workflow files changed but PAT_TOKEN secret is not set."
|
|
97
|
+
echo "::error::GitHub's security policy requires a Personal Access Token with 'workflow' scope to push workflow changes."
|
|
98
|
+
echo "::error::See .github/TOKEN_SETUP.md for instructions on creating and configuring the PAT_TOKEN secret."
|
|
99
|
+
can_push=false
|
|
100
|
+
fi
|
|
101
|
+
else
|
|
102
|
+
echo "workflows_changed=false" >> "$GITHUB_OUTPUT"
|
|
103
|
+
fi
|
|
104
|
+
|
|
105
|
+
git config user.name "github-actions[bot]"
|
|
106
|
+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
107
|
+
|
|
108
|
+
git commit -m "chore: Update via rhiza"
|
|
109
|
+
|
|
110
|
+
if [ "$can_push" = true ]; then
|
|
111
|
+
if git push origin HEAD:rhiza_update --force-with-lease; then
|
|
112
|
+
echo "push_succeeded=true" >> "$GITHUB_OUTPUT"
|
|
113
|
+
else
|
|
114
|
+
echo "push_succeeded=false" >> "$GITHUB_OUTPUT"
|
|
115
|
+
echo "::error::Failed to push branch 'rhiza_update'."
|
|
116
|
+
echo "::error::If workflow files were changed, this is likely because:"
|
|
117
|
+
echo "::error:: 1. PAT_TOKEN secret is not set, OR"
|
|
118
|
+
echo "::error:: 2. PAT_TOKEN lacks the 'workflow' scope"
|
|
119
|
+
echo "::error::See .github/TOKEN_SETUP.md for setup instructions."
|
|
120
|
+
exit 1
|
|
121
|
+
fi
|
|
122
|
+
else
|
|
123
|
+
echo "push_succeeded=false" >> "$GITHUB_OUTPUT"
|
|
124
|
+
fi
|
|
125
|
+
|
|
126
|
+
- name: Create pull request
|
|
127
|
+
if: ${{ inputs.create-pr && steps.sync.outputs.changes_detected == 'true' && steps.sync.outputs.push_succeeded == 'true' }}
|
|
128
|
+
uses: peter-evans/create-pull-request@v8
|
|
129
|
+
with:
|
|
130
|
+
token: ${{ secrets.PAT_TOKEN || github.token }}
|
|
131
|
+
base: ${{ github.event.repository.default_branch }}
|
|
132
|
+
branch: rhiza_update
|
|
133
|
+
delete-branch: false
|
|
134
|
+
title: "chore: Update via rhiza"
|
|
135
|
+
body: |
|
|
136
|
+
This pull request synchronizes the repository with its template.
|
|
137
|
+
|
|
138
|
+
Changes were generated automatically using **rhiza**.
|
|
139
|
+
|
|
140
|
+
- name: Delete branch
|
|
141
|
+
if: ${{ steps.sync.outputs.changes_detected == 'false' }}
|
|
142
|
+
run: git push origin --delete rhiza_update
|