Skip to content

Commit 08387eb

Browse files
author
liuzhen19
committed
init
Signed-off-by: liuzhen19 <liuzhen19@xiaomi.com>
1 parent b919ddc commit 08387eb

2 files changed

Lines changed: 102 additions & 11 deletions

File tree

.github/copilot-instructions.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Copilot Instructions for Python Development
2+
3+
This project uses a modern, high-performance Python toolchain. Please adhere to the following guidelines and tool usages when generating code or commands.
4+
5+
## Toolchain & Workflow
6+
7+
### Dependency & Project Management: `uv`
8+
- **Primary Tool**: Use `uv` for all project management tasks.
9+
- **Overview**: `uv` is an extremely fast Python package and project manager written in Rust. It effectively replaces `pip`, `poetry`, and `pip-tools`.
10+
- **Commands**:
11+
- Add dependencies: `uv add <package>`
12+
- Add dev dependencies: `uv add --dev <package>`
13+
- Run scripts: `uv run <script.py>` or `uv run -m <module>`
14+
- Sync environment: `uv sync` (creates/updates `.venv`)
15+
- Lock dependencies: `uv lock`
16+
- **Configuration**: Managed in `pyproject.toml`.
17+
18+
### Linting & Formatting: `ruff`
19+
- **Linter & Formatter**: Use `ruff` for all linting and formatting.
20+
- **Overview**: `ruff` is an extremely fast Python linter and code formatter written in Rust. It replaces tools like Black, Flake8, and isort.
21+
- **Commands**:
22+
- Check: `uvx ruff check` (fix with `--fix`)
23+
- Format: `uvx ruff format`
24+
- **Style**: Code should be compliant with `ruff`'s default rules and any overrides in `pyproject.toml` or `ruff.toml`.
25+
26+
### Type Checking: `ty`
27+
- **Type Checker**: Use `ty` for static type checking.
28+
- **Overview**: `ty` is a fast Python type checker and language server found in the Astral ecosystem.
29+
- **Commands**:
30+
- Check: `uvx ty check`
31+
- **Typing**: Ensure all code is fully typed. Use modern Python type hinting features.
32+
33+
### Task Management: `just`
34+
- **Task Runner**: Uses `just` to run project-specific tasks.
35+
- **Overview**: `just` is a handy command runner that saves and runs project-specific commands (recipes) stored in a `Justfile`.
36+
- **Usage**: Check the `Justfile` (if present) for available recipes.
37+
- **Recommendation**: If users ask to run common tasks (build, test, lint), check if a `just` recipe exists.
38+
- **installation**: `just` can be installed via package managers like `brew`, `apt`, or using uv:
39+
```bash
40+
uv tool install rust-just
41+
```
42+
43+
### Git Hooks: `pre-commit`
44+
- **Automation**: `pre-commit` ensures code quality before committing.
45+
- **Overview**: Framework for managing and maintaining multi-language pre-commit hooks.
46+
- **Commands**:
47+
- Run manually: `uvx pre-commit run --all-files`
48+
- **installation**:
49+
```bash
50+
uv tool install pre-commit
51+
pre-commit install
52+
```
53+
54+
### Build System: `hatchling`
55+
- **Backend**: The project uses `hatchling` as the build backend.
56+
- **Overview**: `hatchling` is a modern, extensible build backend for Python projects.
57+
- **Configuration**: Build settings are defined in the `[build-system]` section of `pyproject.toml`.
58+
59+
### Testing: `pytest`
60+
- **Framework**: Use `pytest` for testing.
61+
- **Overview**: The pytest framework makes it easy to write small, readable tests, and can scale to support complex functional testing.
62+
- **Commands**:
63+
- Run tests: `uv run pytest`
64+
- **Practices**: Write unit tests for new functionality in the `tests/` directory.
65+
66+
## Commit Messages
67+
68+
- **Strict Requirement**: You **MUST** reference and follow the commit message conventions defined in `.copilot-commit-message-instructions.md` located in the project root.
69+
- All generated commit messages should adhere to the format and rules specified in that file.
70+
71+
## General Development Guidelines
72+
73+
- **Modern Python**: Use modern Python features (3.10+).
74+
- **Type Safety**: Prioritize type safety and clarity.
75+
- **Performance**: Leverage the speed of the provided Rust-based tools (`uv`, `ruff`, `ty`).

README.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,42 @@ A minimal, practical project template for small Python projects and experiments.
55
## Requirements
66

77
- Python 3.8+
8-
- pip
8+
- [uv](https://github.com/astral-sh/uv)
99

10-
## Installation
10+
## Usage
1111

12-
1. Clone the repository:
13-
git clone <repo-url>
14-
2. Install dependencies (if any):
15-
pip install -r requirements.txt
12+
### Using this Template
1613

17-
## Usage
14+
1. **Fork or Copy**: Fork this repository or copy the files to a new directory.
15+
2. **Rename Directory**: Rename the directory to your desired project name.
16+
3. **Initialize Project**: Run the following command to initialize the project with `uv`, which will generate a `pyproject.toml` based on your directory name:
17+
```bash
18+
uv init --lib --build-backend hatchling .
19+
```
20+
*Note: If you want to specify a project name different from the directory name, you can pass the `--name` argument (if supported by your uv version) or simply rename the directory first.*
21+
22+
### Installation
23+
24+
1. **Install dependencies**:
25+
```bash
26+
uv sync
27+
```
28+
29+
### Running
1830

1931
- Run the main script or module:
20-
python -m your_package
32+
```bash
33+
uv run -m your_package
34+
```
2135

22-
Replace `your_package` with the actual package or script name.
36+
Replace `your_package` with the actual package or script name.
2337

2438
## Testing
2539

26-
- Add tests under a `tests/` directory and run with your preferred test runner (pytest recommended):
27-
pytest
40+
- Run tests using `pytest`:
41+
```bash
42+
uv run pytest
43+
```
2844

2945
## Contributing
3046

0 commit comments

Comments
 (0)