Skip to content

Commit

Permalink
Use --implicit_start, add ruff & pretty-format-toml (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenodegard authored Apr 17, 2024
1 parent a614ad4 commit cdb38a2
Show file tree
Hide file tree
Showing 20 changed files with 66 additions and 41 deletions.
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/0_bug.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: Bug Report
description: Create a bug report.
labels:
Expand Down
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/1_feature.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: Feature Request
description: Create a feature request.
labels:
Expand Down
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/2_documentation.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: Documentation
description: Create a documentation related issue.
labels:
Expand Down
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/epic.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: Epic
description: A collection of related tickets.
labels:
Expand Down
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
version: 2
updates:
- package-ecosystem: github-actions
Expand Down
21 changes: 10 additions & 11 deletions .github/global.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
# General
- name: mitigated
description: a workaround has been identified
Expand Down Expand Up @@ -37,7 +36,7 @@
color: '#ededed'
- name: locked
description: '[bot] locked due to inactivity'
color: '#85BDB1'
color: '#85bdb1'
- name: dependencies
description: '[bot] PRs that update a dependency file'
color: '#0366d6'
Expand All @@ -61,7 +60,7 @@
# Sync
- name: sync::anaconda
description: sync internally with Anaconda, Inc. ticket tracker
color: '#5B2B76'
color: '#5b2b76'

# Duplicates
- name: duplicate
Expand Down Expand Up @@ -251,14 +250,14 @@
# Stale
- name: stale
description: '[bot] marked as stale due to inactivity'
color: '#E79676'
color: '#e79676'
aliases: [stale-marked]
- name: stale::recovered
description: '[bot] recovered after being marked as stale'
color: '#40A6B3'
color: '#40a6b3'
- name: stale::closed
description: '[bot] closed after being marked as stale'
color: '#86A8D8'
color: '#86a8d8'

# Hackathons
- name: hack::HackIllinois2019
Expand All @@ -276,20 +275,20 @@
# Tags
- name: tag::performance
description: related to degraded performance
color: '#86C579'
color: '#86c579'
- name: tag::encoding-error
description: related to an encoding error
color: '#86C579'
color: '#86c579'
- name: tag::api
description: related to the public API
color: '#86C579'
color: '#86c579'
- name: tag::reproducibility
description: related to producing reproducible results
color: '#86C579'
color: '#86c579'
aliases: [reproducibility]
- name: tag::ux
description: related to user experience
color: '#86C579'
color: '#86c579'

# Documentation
- name: documentation::tutorials
Expand Down
1 change: 0 additions & 1 deletion .github/labels.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
- name: type::development
color: '#fff2cc'
description: related to developer environment setups
Expand Down
1 change: 0 additions & 1 deletion .github/messages.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
stale-issue: |
Hi there, thank you for your contribution!
Expand Down
1 change: 0 additions & 1 deletion .github/sync/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
group:
# all projects
- repos: |
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/cla.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: CLA

on:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/issues.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: Automate Issues

on:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/labels.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: Sync Labels

on:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/lock.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: Lock

on:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/project.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: Add to Project

on:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: Stale

on:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/sync.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: Sync

on:
Expand Down
19 changes: 16 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
Expand All @@ -8,6 +7,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
# ensure syntaxes are valid
- id: check-toml
- id: check-yaml
# catch git merge/rebase problems
- id: check-merge-conflict
Expand All @@ -20,20 +20,33 @@ repos:
files: ^.clabot$
require_serial: true
args: [--sort-keys=contributors]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.7
hooks:
# lint & attempt to correct failures (e.g. pyupgrade)
- id: ruff
args: [--fix]
# compatible replacement for black
- id: ruff-format
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.13.0
hooks:
- id: pretty-format-toml
args: [--autofix, --trailing-commas]
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.2.3
hooks:
- id: yamlfmt
# ruamel.yaml doesn't line wrap correctly (?) so set width to 1M to avoid issues
args: [--mapping, '2', --offset, '2', --sequence, '4', --width, '1000000']
args: [--mapping=2, --offset=2, --sequence=4, --width=1000000, --implicit_start]
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.2
hooks:
# verify github syntaxes
- id: check-github-workflows
- id: check-dependabot
- repo: https://github.com/codespell-project/codespell
# see setup.cfg
# see pyproject.toml
rev: v2.2.6
hooks:
- id: codespell
Expand Down
22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[tool.codespell]
# see https://github.com/codespell-project/codespell#using-a-config-file
ignore-words-list = "rever,"
skip = '.git'

[tool.ruff]
target-version = "py38"

[tool.ruff.lint]
# see https://docs.astral.sh/ruff/rules/
select = [
"D", # pydocstyle
"E", # pycodestyle errors
"F", # pyflakes
"FA", # flake8-future-annotations
"I", # isort
"ISC", # flake8-implicit-str-concat
"T10", # flake8-debugger
"TCH", # flake8-type-checking
"UP", # pyupgrade
"W", # pycodestyle warnings
]
4 changes: 0 additions & 4 deletions setup.cfg

This file was deleted.

26 changes: 18 additions & 8 deletions sort_json.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
#!/usr/bin/env python3
from argparse import ArgumentParser
"""Sort specified keys in JSON files."""

from __future__ import annotations

import json
import sys
from argparse import ArgumentParser
from pathlib import Path
from typing import Optional, Sequence
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Sequence


def main(argv: Optional[Sequence[str]] = None) -> int:
def main(argv: Sequence[str] | None = None) -> int:
"""Sort specified keys in JSON files."""
parser = ArgumentParser()
parser.add_argument(
"--sort-keys", type=lambda v: v.split(","), default=[], help="Keys to sort"
"--sort-keys",
type=lambda keys: keys.split(","),
default=[],
help="Keys to sort",
)
parser.add_argument("filenames", nargs="*", type=Path, help="Filenames to fix")
args = parser.parse_args(argv)
Expand All @@ -29,11 +41,9 @@ def object_pairs_hook(pairs):
else:
pretty = f"{json.dumps(content, indent=2)}\n" # include trailing newline
path.write_text(pretty)
status = (
status or original != pretty
) # record whether modifications were made
status = status or original != pretty # record whether modified
return status


if __name__ == "__main__":
raise SystemExit(main())
sys.exit(main())

0 comments on commit cdb38a2

Please sign in to comment.