Skip to content
Merged
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
29 changes: 29 additions & 0 deletions .github/workflows/autofix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: autofix.ci

on:
pull_request:

permissions:
contents: read

jobs:
autofix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: j178/prek-action@7b101f8338a08d2bd6fdb3625e4e7692428763a3 # v3.1.1
with:
install-only: true

- name: Run prek
id: prek
continue-on-error: true
run: prek run --all-files

- name: Verify fixes
if: steps.prek.outcome == 'failure'
run: prek run --all-files

- name: Commit fixes
if: always() && !cancelled()
uses: autofix-ci/action@c5b2d67aa2274e7b5a18224e8171550871fc7e4a # v1.3.4
134 changes: 0 additions & 134 deletions .pre-commit-config.yaml

This file was deleted.

1 change: 1 addition & 0 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ A first-class command-line experience ready for daily use.
- [ ] `--fail-on-drift` exit code for CI pipelines
- [ ] `--json` flag on all commands
- [ ] Shell completion
- [x] Replace `mypy` by `ty`

## v0.4 - Format and Integration Expansion

Expand Down
125 changes: 125 additions & 0 deletions prek.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#:schema https://www.schemastore.org/prek.json
# prek.toml
#
# Setup:
# uv tool install prek # or: pip install prek
# prek install # installs the git hook
# prek run --all-files # run once across the whole repo
#
# Maintenance:
# prek auto-update # bump all `rev` pins to latest
# prek util list-builtins # hooks prek implements natively in Rust
#
# Docs: https://prek.j178.dev

minimum_prek_version = "0.5.11"

default_language_version = { python = "python3.11" }

# Keep commits fast: only run on the commit stage by default.
default_stages = ["pre-commit"]

# Don't run hooks on generated / vendored / data paths.
exclude = '''
(?x)^(
\.git/.*|
\.venv/.*|
build/.*|
dist/.*|
docs/_build/.*|
.*\.egg-info/.*|
data/.*|
datasets/.*|
.*\.ipynb_checkpoints/.*
)$
'''

# -----------------------------------------------------------------------------
# Core hygiene: cheap, fast, catch-everything checks.
# prek's automatic fast path runs its built-in Rust implementation for every
# hook here except `debug-statements`, which falls back to the pinned Python
# hook. See https://prek.j178.dev/built-in-hooks/#use-the-automatic-fast-path
# -----------------------------------------------------------------------------
[[repos]]
repo = "https://github.com/pre-commit/pre-commit-hooks"
rev = "v6.0.0"
hooks = [
{ id = "trailing-whitespace", args = ["--markdown-linebreak-ext=md"] },
{ id = "end-of-file-fixer" },
{ id = "mixed-line-ending", args = ["--fix=lf"] },
{ id = "check-yaml" },
{ id = "check-toml" },
{ id = "check-json" },
{ id = "check-merge-conflict" },
{ id = "check-case-conflict" },
{ id = "check-symlinks" },
{ id = "debug-statements" }, # blocks stray breakpoint()/pdb (no builtin)
{ id = "detect-private-key" }, # blocks committed private keys
{ id = "check-added-large-files", args = ["--maxkb=1024"] },
]

# -----------------------------------------------------------------------------
# Ruff: linter + formatter (replaces flake8, isort, black, pyupgrade, etc.).
# Lint (with --fix) MUST run before the formatter.
# -----------------------------------------------------------------------------
[[repos]]
repo = "https://github.com/astral-sh/ruff-pre-commit"
rev = "v0.17.5"
hooks = [
{ id = "ruff-check", args = ["--fix"], types_or = ["python", "pyi", "jupyter"] },
{ id = "ruff-format", types_or = ["python", "pyi", "jupyter"] },
]

# -----------------------------------------------------------------------------
# Static type checking. Paths are configured in pyproject.toml under [tool.ty].
# -----------------------------------------------------------------------------
[[repos]]
repo = "https://github.com/astral-sh/ty-pre-commit"
rev = "v0.0.107"
hooks = [
{ id = "ty" },
]

# -----------------------------------------------------------------------------
# Spelling: catches typos in code, docstrings, and docs.
# Configure ignores in pyproject.toml under [tool.codespell].
# -----------------------------------------------------------------------------
[[repos]]
repo = "https://github.com/codespell-project/codespell"
rev = "v2.4.3"
hooks = [
{ id = "codespell", additional_dependencies = ["tomli"] },
]

# -----------------------------------------------------------------------------
# Notebooks: strip outputs before commit (clean diffs, no data leakage).
# Essential for ML repos that carry .ipynb files.
# -----------------------------------------------------------------------------
[[repos]]
repo = "https://github.com/kynan/nbstripout"
rev = "0.9.1"
hooks = [
{ id = "nbstripout" },
]

# -----------------------------------------------------------------------------
# Secret scanning (baseline-driven). Generate the baseline once with:
# detect-secrets scan > .secrets.baseline
# -----------------------------------------------------------------------------
[[repos]]
repo = "https://github.com/Yelp/detect-secrets"
rev = "v1.5.0"
hooks = [
{ id = "detect-secrets", args = ["--baseline", ".secrets.baseline"] },
]

# -----------------------------------------------------------------------------
# uv lock file update to make sure it is properly synced even if the
# dependencies have been updated.
# -----------------------------------------------------------------------------
[[repos]]
repo = "https://github.com/astral-sh/uv-pre-commit"
rev = "0.13.8" # uv version
hooks = [
{ id = "uv-lock" },
]
29 changes: 10 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,17 @@ docstring-code-format = true
quote-style = "double"

# -----------------------------------------------------------------------------
# mypy: static type checking
# static type checking
# -----------------------------------------------------------------------------
[tool.mypy]
files = ["src"]
python_version = "3.11"
strict = true
show_error_codes = true
warn_unreachable = true
warn_redundant_casts = true
warn_unused_ignores = true
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
[tool.ty.environment]
python-version = "3.11"

# Silence missing stubs for third-party libs that don't ship types.
[[tool.mypy.overrides]]
module = [
"numpy.*",
"pandas.*",
"reportlab.*",
"sklearn.*",
]
ignore_missing_imports = true
[tool.ty.src]
include = ["src", "tests"]
exclude = ["src/generated"]

[tool.ty.rules]
unused-ignore-comment = "error"

# -----------------------------------------------------------------------------
# coverage
Expand All @@ -124,4 +114,5 @@ dev = [
"pytest>=9.1.1",
"pytest-cov>=7.1.0",
"zensical>=0.0.50",
"reportlab>=4.2"
]
14 changes: 11 additions & 3 deletions src/dstrack/_benchmark/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import shutil
import tempfile
from collections.abc import Iterator
from collections.abc import Generator
from contextlib import contextmanager
from pathlib import Path
from typing import Annotated
from typing import Annotated, Protocol

import typer

Expand Down Expand Up @@ -33,8 +33,16 @@ def _main() -> None:
"""


class _CsvKeptSink(Protocol):
"""What [_workspace][dstrack._benchmark._cli._workspace] needs from a reporter."""

def csv_kept(self, path: Path) -> None: ...


@contextmanager
def _workspace(reporter: ConsoleReporter, *, keep_csv: bool) -> Iterator[Path]:
def _workspace(
reporter: _CsvKeptSink, *, keep_csv: bool
) -> Generator[Path, None, None]:
"""Yield a path for the synthetic CSV, discarding it unless ``keep_csv``."""
tmp_dir = Path(tempfile.mkdtemp(prefix="dstrack-benchmark-"))
csv_path = tmp_dir / "synthetic_dataset.csv"
Expand Down
2 changes: 1 addition & 1 deletion src/dstrack/_benchmark/_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class CallGraph:
@classmethod
def from_profile(cls, profiler: cProfile.Profile, scope: CallScope) -> "CallGraph":
"""Build the in-scope call graph of a profiler that has finished running."""
raw: _RawStats = pstats.Stats(profiler).stats # type: ignore[attr-defined]
raw: _RawStats = pstats.Stats(profiler).stats # ty: ignore[missing-attribute]
graph = cls(_scope=scope)
frames = {key for key in raw if scope.contains(key[0])}
callees: set[FrameKey] = set()
Expand Down
4 changes: 2 additions & 2 deletions src/dstrack/_benchmark/_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import cProfile
import time
from collections.abc import Iterator
from collections.abc import Generator
from contextlib import contextmanager
from dataclasses import dataclass
from pathlib import Path
Expand Down Expand Up @@ -175,7 +175,7 @@ def run(self, csv_path: Path) -> BenchmarkRun:
)

@contextmanager
def _timed(self, *, profiled: bool = False) -> Iterator[_Elapsed]:
def _timed(self, *, profiled: bool = False) -> Generator[_Elapsed, None, None]:
"""Time the block, optionally recording it into the shared profiler."""
profiler = self._profiler if profiled else None
elapsed = _Elapsed()
Expand Down
Loading
Loading