Commit 81950065 authored by one's avatar one
Browse files

[hytop] Use uv and hatch, add pre-commit

parent 516fd909
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.0
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
.PHONY: help setup format lint test clean bump
help:
@echo "Available targets:"
@echo " make setup - Create venv, install all dependencies, and set up git hooks"
@echo " make format - Auto-fix and format code (ruff)"
@echo " make lint - Check code style and errors without modifying files (ruff)"
@echo " make test - Run all unit tests (pytest)"
@echo " make clean - Remove build caches and the virtual environment"
@echo " make bump part=X - Bump version (patch/minor/major or X.Y.Z)"
setup:
@echo ">> Initializing virtual environment and installing dependencies..."
uv sync --group dev
@echo ">> Installing pre-commit git hooks..."
uvx pre-commit install
format:
uv run ruff check --fix src/ tests/
uv run ruff format src/ tests/
lint:
uv run ruff check src/ tests/
uv run ruff format --check src/ tests/
test:
uv run pytest -v
clean:
rm -rf .pytest_cache .ruff_cache .venv
find src tests -type f -name "*.pyc" -delete
find src tests -type d -name "__pycache__" -delete
bump:
uv run hytop-bump $(part)
......@@ -2,10 +2,17 @@
## Quick start
Use `uv` to run hytop:
```bash
uv pip install -e .
uv run hytop --help
```
Run hytop directly:
```bash
source .venv/Scripts/activate
hytop --help
hytop gpu --help
```
## Prerequisites
......@@ -94,20 +101,29 @@ If no `--show*` flags are specified, hytop defaults to:
## Development
### Version bump
Clone the repo and run `make setup` to create the virtual environment, install all dependencies (including dev), and configure pre-commit hooks:
Version is sourced from `src/hytop/__init__.py` (`__version__`).
```bash
make setup
```
Common development commands:
```bash
# patch: 0.1.0 -> 0.1.1
python scripts/bump_version.py patch
make format # Auto-fix and format code (ruff)
make lint # Check code style and errors without modifying files
make test # Run all unit tests (pytest)
make bump part=patch # Bump version (patch/minor/major or X.Y.Z)
make clean # Remove build caches and the virtual environment
```
# minor: 0.1.1 -> 0.2.0
python scripts/bump_version.py minor
### Version bump
# major: 0.2.0 -> 1.0.0
python scripts/bump_version.py major
Version is sourced from `src/hytop/__init__.py` (`__version__`).
# set an explicit version
python scripts/bump_version.py set 1.2.3
```bash
make bump part=patch # 0.1.0 -> 0.1.1
make bump part=minor # 0.1.1 -> 0.2.0
make bump part=major # 0.2.0 -> 1.0.0
make bump part="set 1.2.3" # set an explicit version
```
[build-system]
requires = ["setuptools>=68", "wheel"]
build-backend = "setuptools.build_meta"
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "hytop"
......@@ -12,18 +12,16 @@ dependencies = ["rich>=13", "typer>=0.12"]
[project.scripts]
hytop = "hytop.main:main"
hytop-bump = "hytop._bump:main"
[project.optional-dependencies]
dev = ["pytest>=8", "ruff>=0.11"]
[dependency-groups]
dev = ["pytest>=8", "ruff>=0.15"]
[tool.setuptools]
package-dir = { "" = "src" }
[tool.hatch.version]
path = "src/hytop/__init__.py"
[tool.setuptools.packages.find]
where = ["src"]
[tool.setuptools.dynamic]
version = { attr = "hytop.__version__" }
[tool.hatch.build.targets.wheel]
packages = ["src/hytop"]
[tool.pytest.ini_options]
testpaths = ["tests"]
......
......@@ -6,13 +6,11 @@ import re
import sys
from pathlib import Path
VERSION_PATTERN = re.compile(r'^(\s*__version__\s*=\s*")(\d+)\.(\d+)\.(\d+)(".*)$')
VERSION_PATTERN = re.compile(r'^(\s*__version__\s*=\s*")(\d+)\.(\d+)\.(\d+)(".*)\s*$')
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="Bump hytop version in src/hytop/__init__.py"
)
parser = argparse.ArgumentParser(description="Bump hytop version in src/hytop/__init__.py")
parser.add_argument(
"action",
choices=["patch", "minor", "major", "set"],
......@@ -53,7 +51,13 @@ def bump_version(current: tuple[int, int, int], action: str) -> tuple[int, int,
def main() -> int:
args = parse_args()
root = Path(__file__).resolve().parents[1]
# Find the project root by walking up from cwd until src/hytop/__init__.py is found
root = Path.cwd()
for candidate in [root, *root.parents]:
if (candidate / "src" / "hytop" / "__init__.py").exists():
root = candidate
break
init_file = root / "src" / "hytop" / "__init__.py"
if not init_file.exists():
print(f"Cannot find version file: {init_file}", file=sys.stderr)
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment