Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .cursorrules
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# RoleFit Analyzer - Cursor Rules
# modified from https://github.com/PatrickJS/awesome-cursorrules/blob/main/rules/python-cursorrules-prompt-file-best-practices/.cursorrules
You are an AI assistant specialized in Python development. Your approach emphasizes:

- Clear project structure with separate directories for source code, tests, docs, and config.
- Modular design with distinct files for models, services, controllers, and utilities.
- Configuration management using environment variables.
- Robust error handling and logging, including context capture.
- Comprehensive testing with pytest.
- Detailed documentation using docstrings and README files.
- Dependency management via https://github.com/astral-sh/uv and virtual environments.
- Code style consistency using Ruff for both formatting and linting.
- CI/CD implementation with GitHub Actions or GitLab CI.

AI-friendly coding practices:
- You provide code snippets and explanations tailored to these principles, optimizing for clarity and AI-assisted development.

Follow the following rules:
- For any Python file, ALWAYS add typing annotations to each function or class. Include explicit return types (including None where appropriate). Add descriptive docstrings to all Python functions and classes.
- Please follow PEP 257 docstring conventions. Update existing docstrings as needed.
- Make sure you keep any comments that exist in a file.
- When writing new features, always consider existing logic to minimize code duplication and propose simple call structures.
- When writing tests, ONLY use pytest or pytest plugins (not unittest). All tests should have typing annotations. Place all tests under ./tests. Create any necessary directories. If you create packages under ./tests or ./src/<package_name>, be sure to add an __init__.py if one does not exist.

All tests should be fully annotated and should contain docstrings. Be sure to import the following if TYPE_CHECKING:
from _pytest.capture import CaptureFixture
from _pytest.fixtures import FixtureRequest
from _pytest.logging import LogCaptureFixture
from _pytest.monkeypatch import MonkeyPatch
from pytest_mock.plugin import MockerFixture
4 changes: 2 additions & 2 deletions .github/workflows/check-pr-title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
steps:
- uses: deepakputhraya/action-pr-title@master
with:
min_length: 6 # Min length of the title
max_length: 72 # Max length of the title
min_length: 6 # Min length of the title
max_length: 72 # Max length of the title
github_token: ${{ github.token }} # Default: ${{ github.token }}
22 changes: 22 additions & 0 deletions .github/workflows/run-static-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Static Tests for Python Scripts

on:
pull_request:
branches: [ main ]

jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: jdx/mise-action@v3
- run: mise exec -- make setup-dev
- run: mise exec -- make format

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: jdx/mise-action@v3
- run: mise exec -- make setup-dev
- run: mise exec -- make lint-no-fix
41 changes: 0 additions & 41 deletions .github/workflows/run-tests.yml

This file was deleted.

14 changes: 14 additions & 0 deletions .github/workflows/run-unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Unit Tests for Python Scripts

on:
pull_request:
branches: [ main ]

jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: jdx/mise-action@v3
- run: mise exec -- make setup-dev
- run: mise exec -- make test
5 changes: 5 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[tools]
python = "3.12"

[env]
_.python.venv = { path = ".venv", create = true } # create the venv if it doesn't exist
13 changes: 0 additions & 13 deletions .pre-commit-config.yaml

This file was deleted.

29 changes: 14 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
PYTHON=3.8
BASENAME=$(shell basename $(CURDIR))
CONDA_CH=conda-forge defaults

env:
conda create -n $(BASENAME) python=$(PYTHON)
init:
# Trust mise configuration
# mise will install Python and uv automatically
mise trust

setup:
conda install --file requirements.txt $(addprefix -c ,$(CONDA_CH))
pre-commit install
uv pip install -e .

setup-dev:
uv pip install -e ".[dev]"

format:
black .
isort .
ruff format .

lint:
pytest src --flake8 --pylint --mypy
ruff check --fix .

utest:
PYTHONPATH=src pytest test/utest --cov=src --cov-report=html --cov-report=term --cov-config=setup.cfg
lint-no-fix:
ruff check .

cov:
open htmlcov/index.html
test:
pytest
31 changes: 7 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
# Python Project Template
This repository is a python template repo for internal uses of Annotation-AI.

## File Structure
### Commands for Setups
```bash
.
├── LICENSE
├── Makefile # commands
├── README.md
├── requirements.txt # package information
├── setup.cfg # configurations for formatting & linting & unit-test
├── src # source code location
└── test
└── utest # unit tests location
make init # Initialize the project
make setup # Install dependencies
make setup-dev # Install dependencies with development packages
```

## Commands
## Commands for Development
```bash
$ make env # create anaconda environment
$ make setup # initial setup for the project
$ make format # format python scripts
$ make lint # lint python scripts
$ make utest # run unit tests
$ make cov # open coverage report (after `make utest`)
$ make test # run unit tests
```

## Configurations
`setup.cfg` states all configurations for formatting & linting & unit-test.

## Verifications
- per commit: pre-commit hook runs formatting and linting.
- per pull-request: GitHub Actions check formatting, linting, and unit-test results.

## Recommended Repository Settings
#### Restriction on multi-commit pushes
`Settings` -> `General` -> `Merge botton` -> `Allow squash merging` ONLY
Expand All @@ -41,4 +24,4 @@ $ make cov # open coverage report (after `make utest`)
- Branch name pattern: `main`
- Require a pull request before merging & Require approvals
- Require status checks to pass before merging & Require branches to be up to date before merging
- Include administrators
- Include administrators
55 changes: 55 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[project]
name = "python-project-template"
version = "0.0.1"
readme = "README.md"
requires-python = ">=3.12"
authors = [
{ name = "Curt Park", email = "[email protected]" },
]
keywords = ["python", "project_template"]
classifiers = []

dependencies = []

[project.optional-dependencies]
dev = [
"ruff>=0.14.3",
"pytest>=8.4.2",
"pytest-cov>=7.0.0",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.ruff]
line-length = 88
target-version = "py312"

[tool.hatch.build.targets.wheel]
packages = ["src"]

[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # Pyflakes
"I", # isort
"N", # pep8-naming
"UP", # pyupgrade
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"PIE", # flake8-pie
"SIM", # flake8-simplify
]

[tool.pytest.ini_options]
testpaths = ["tests"]
pythonpath = ["src"]
addopts = [
"--strict-markers",
"--strict-config",
"--cov=src",
"--cov-report=term-missing",
"--cov-report=html",
]
21 changes: 0 additions & 21 deletions requirements.txt

This file was deleted.

40 changes: 0 additions & 40 deletions setup.cfg

This file was deleted.

File renamed without changes.
Loading