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
43 changes: 0 additions & 43 deletions .circleci/config.yml

This file was deleted.

13 changes: 11 additions & 2 deletions .copier-answers-py.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# Changes here will be overwritten by Copier; NEVER EDIT MANUALLY
_commit: v1.20250226.1
# Changes here will be overwritten by Copier
#
# Updating `_src` could be helpful, see notes at:
# https://github.com/level12/coppy/wiki#creating-a-project
#
# Otherwise, NEVER EDIT MANUALLY
_commit: v1.20250622.1-36-g7b1cff7
_src_path: gh:level12/copier-py-package
author_email: randy.syring@level12.io
author_name: Randy Syring
gh_org: level12
gh_repo: pre-commit-hooks
hatch_version_tag_sign: true
project_name: pre-commit-hooks
py_module: pre_commit_hooks
python_version: '3.12'
script_name: check-ruff-versions
use_circleci: false
use_gh_nox: true
17 changes: 6 additions & 11 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
# .coveragerc to control coverage.py
[run]
branch = True
omit =
src/pre_commit_hooks/version.py

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover
source =
src/pre_commit_hooks
tests/pre_commit_hooks_tests

# testing assertions usually used with exceptions
assert False

# patterns for running cli
cli_entry()

[html]
directory = ci/coverage-html
directory = tmp/coverage-html
7 changes: 2 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ root = true

# Set the default whitespace settings for all files
[*]
# Sensible modern default
charset = utf-8

# Use UNIX-style line endings
end_of_line = lf
Expand All @@ -23,11 +25,6 @@ insert_final_newline = true
trim_trailing_whitespace = true


[*.py]
# ensure Python source files are utf-8
charset = utf-8


[*.{yml,yaml}]
# Set two-space indents for YAML files
indent_size = 2
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/nox.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Nox

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

# Limit this workflow to a single run at a time per-branch to avoid wasting worker resources
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
nox:
runs-on: ubuntu-latest

# Runs all steps inside this container
container:
image: ghcr.io/level12/ubuntu-mive:24-3.12
options: --user root

env:
UV_LINK_MODE: copy

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Mark repo as safe for Git
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"

- name: Run Tests
run: |
uv run --frozen --only-group nox -- nox
8 changes: 6 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: check-merge-conflict
- id: check-ast
Expand All @@ -13,7 +13,7 @@ repos:
- id: check-added-large-files
- id: check-yaml
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.9.7
rev: v0.13.1
hooks:
# i.e. `ruff check`
- id: ruff
Expand All @@ -28,3 +28,7 @@ repos:
rev: v0.20250226.1
hooks:
- id: check-ruff-versions
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.8.17
hooks:
- id: uv-lock
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

1 change: 1 addition & 0 deletions ci/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
artifacts
coverage
test-reports
2 changes: 1 addition & 1 deletion env-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
profile:
pypi:
HATCH_INDEX_USER: '__token__'
HATCH_INDEX_AUTH: 'op://private/pypi.python.org/api-token'
HATCH_INDEX_AUTH: 'op://my/private/pypi.org/api-token'
24 changes: 21 additions & 3 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
[env]
PROJECT_SLUG = '{{ config_root | basename | slugify }}'
# Will use a centralized venv if `~/.cache/uv-venvs` exists. `.venv` otherwise.
UV_PROJECT_ENVIRONMENT = "{{ exec(command='tasks/mise-uv-init.py proj-env', cache_key='proj-env', cache_duration='1h') | trim }}"
_.python.venv.path = '{{ env.UV_PROJECT_ENVIRONMENT }}'

_.python.venv.path = '{% if env.UV_PROJECT_ENVIRONMENT %}{{ env.UV_PROJECT_ENVIRONMENT }}{% else %}.venv{% endif %}'
_.python.venv.create = true

[tools]
python = "{{ exec(command='tasks/mise-uv-init.py py-ver', cache_key='py-ver', cache_duration='1h') | trim }}"


[task_config]
includes = [
'tasks',
]


################ TASKS #################
[tasks.pytest-cov]
description = 'Full pytest run with html coverage report'
# .coveragerc sets directory to ./tmp/coverage-html
run = 'pytest --cov --cov-report=html --no-cov-on-fail'


[tasks.upgrade-deps]
description = 'Upgrade uv and pre-commit dependencies'
run = [
'uv sync --upgrade',
'pre-commit autoupdate',
]
60 changes: 42 additions & 18 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,19 @@
import nox


package_path = Path.cwd()
package_path = Path(__file__).parent
nox.options.default_venv_backend = 'uv'


@nox.session
def tests(session: nox.Session):
session.run('uv', 'sync', '--active', '--no-dev', '--group', 'tests')
session.run(
'pytest',
'-ra',
'--tb=native',
'--strict-markers',
'--cov=pre_commit_hooks',
'--cov-config=.coveragerc',
'--cov-report=xml',
'--no-cov-on-fail',
f'--junit-xml={package_path}/ci/test-reports/{session.name}.pytests.xml',
'src/tests',
*session.posargs,
)
def pytest(session: nox.Session):
uv_sync(session)
pytest_run(session)


@nox.session
def precommit(session: nox.Session):
session.run('uv', 'sync', '--active', '--no-dev', '--group', 'pre-commit')
uv_sync(session, 'pre-commit')
session.run(
'pre-commit',
'run',
Expand All @@ -38,9 +26,45 @@ def precommit(session: nox.Session):
@nox.session
def audit(session: nox.Session):
# Much faster to install the deps first and have pip-audit run against the venv
session.run('uv', 'sync', '--active', '--no-dev', '--group', 'audit')
uv_sync(session)
session.run(
'pip-audit',
'--desc',
'--skip-editable',
)


def uv_sync(session: nox.Session, *groups, project=False, extra=None):
if not groups:
groups = (session.name,)
project_args = () if project or session.name.startswith('pytest') else ('--no-install-project',)
group_args = [arg for group in groups for arg in ('--group', group)]
extra_args = ('--extra', extra) if extra else ()
run_args = (
'uv',
'sync',
'--active',
'--no-default-groups',
*project_args,
*group_args,
*extra_args,
)
session.run(*run_args)


def pytest_run(session: nox.Session, *args, **env):
session.run(
'pytest',
'-ra',
'--tb=native',
'--strict-markers',
'--cov',
'--cov-config=.coveragerc',
f'--junit-xml={package_path}/ci/test-reports/{session.name}.pytests.xml',
f'--cov-report=xml:{package_path}/ci/coverage/{session.name}.xml',
'--no-cov-on-fail',
package_path / 'tests',
*args,
*session.posargs,
env=env,
)
26 changes: 14 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ name = 'pre-commit-hooks'
authors = [
{name = 'Randy Syring', email = 'randy.syring@level12.io'},
]
requires-python = '>=3.12'
requires-python = '~=3.12.0'
dynamic = ['version']
readme = 'readme.md'
dependencies = [
Expand All @@ -21,6 +21,7 @@ dependencies = [
]



[project.scripts]
'check-ruff-versions' = 'pre_commit_hooks.check_ruff_versions:main'

Expand All @@ -30,20 +31,21 @@ dependencies = [
# conflicts when upgrading to the latest Coppy template.
dev = [
# From Coppy:
{include-group = "tests"},
{include-group = "pytest"},
{include-group = "audit"},
{include-group = "nox"},
'click>=8.1.8',
'hatch>=1.14.0',
'ruff>=0.9.6',
'click',
'hatch',
'ruff',

# App specific:
# TODO: fill in app deps here
]
# Used by nox
tests = [
pytest = [
# From Coppy:
'pytest>=8.3.4',
'pytest-cov>=6.0',
'pytest',
'pytest-cov',

# App specific:
# TODO: fill in app deps here
Expand All @@ -52,15 +54,15 @@ tests = [
# Used by nox
pre-commit = [
# From Coppy:
'pre-commit>=4.1.0',
'pre-commit-uv>=4.1.4',
'pre-commit',
'pre-commit-uv',
]
# Used by nox
audit = [
# From Coppy:
'pip-audit>=2.8.0',
'pip-audit',
]
# Used by CI
nox = [
'nox>=2025.2.9',
'nox',
]
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pre-commit-hooks
[![CircleCI](https://dl.circleci.com/status-badge/img/gh/level12/pre-commit-hooks/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/level12/pre-commit-hooks/tree/main)
[![nox](https://github.com/level12/pre-commit-hooks/actions/workflows/nox.yaml/badge.svg)](https://github.com/level12/pre-commit-hooks/actions/workflows/nox.yaml)


## Usage

Expand Down Expand Up @@ -27,6 +28,7 @@ repos:
- args: [--package, foo-pkg, --package, bar-pkg]
```


## Dev

### Copier Template
Expand Down
Loading