Skip to content

Commit

Permalink
Merge pull request #185 from nationalarchives/FCL-343-add-typing-and-…
Browse files Browse the repository at this point in the history
…type-checking-to-utils

[FCL-343] Add typing to utils
  • Loading branch information
jacksonj04 authored Sep 30, 2024
2 parents c014352 + bd35b89 commit d6eb5c8
Show file tree
Hide file tree
Showing 14 changed files with 434 additions and 116 deletions.
34 changes: 34 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
exclude: courts_schema_types_autogenerated\.py
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
Expand All @@ -14,11 +15,44 @@ repos:
- id: no-commit-to-branch
- id: trailing-whitespace

# There is a bug with upstream which means the imports are
# not sorted -- this should do for now
- repo: https://github.com/camptocamp/jsonschema-gentypes
rev: 2.8.1
hooks:
- id: jsonschema-gentypes
files: src/ds_caselaw_utils/data/schema/courts.schema.json
language_version: python3.9

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.8
hooks:
- id: ruff
args:
- --fix
- --exit-non-zero-on-fix
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
name: mypy-src
additional_dependencies:
- types-PyYAML
- ruamel.yaml
args:
- --strict
files: ^(src/ds_caselaw_utils|scripts)
exclude: (?:test_|factory.py)

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
name: mypy-tests
files: ^src/ds_caselaw_utils/test_

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.2
hooks:
Expand Down
22 changes: 22 additions & 0 deletions jsonschema-gentypes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
headers: >
# Automatically generated file from a JSON schema
# Used to correctly format the generated file
# callbacks:
# - - black
# - - isort
generate:
- # JSON schema file path
source: src/ds_caselaw_utils/data/schema/courts.schema.json
# Python file path
destination: src/ds_caselaw_utils/courts_schema_types_autogenerated.py
# The name of the root element
root_name: RawCourtRepository
# Argument passed to the API
api_arguments:
additional_properties: Only explicit
# Rename an element
name_mapping: {}
# The minimum Python version that the code should support. By default the
# currently executing Python version is chosen. Note that the output
# may require typing_extensions to be installed.
python_version: "3.9"
13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 8 additions & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,23 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.9"
"ruamel.yaml" = "^0.18.0"
typing-extensions = "^4.12.2"

[tool.poetry.dev-dependencies]

[tool.ruff]
line-length = 120

[tool.ruff.lint]
ignore = ["E501", "G004", "PLR2004", "RUF005", "RUF012", "UP040"] # long lines, fstrings in logs, magic values, consider not concat, mutable classbits, type instead of TypeAlias
extend-select = ["W", "B", "Q", "C90", "I", "UP", "YTT", "ASYNC", "S", "BLE", "A", "COM", "C4", "DTZ", "T10", "DJ", "EM", "EXE", "FA",
"ISC", "ICN", "G", "INP", "PIE", "T20", "PYI", "PT", "Q", "RSE", "RET", "SLF", "SLOT", "SIM", "TID", "TCH", "INT", "PTH",
"FIX", "PGH", "PL", "TRY", "FLY", "PERF", "RUF"]
ignore = ["E501", "G004", "PLR2004", "RUF005", "RUF012", "UP040"] # longlines, fstrings in logs, magic values, consider not concat, mutable classbits, type instead of TypeAlias
extend-select = ["W", "I", ]
# extend-select = [ "SLF", "SIM", "B", "Q", "C90", "I", "UP", "YTT", "ASYNC", "S", "BLE", "A", "COM", "C4", "DTZ", "T10", "DJ", "EM", "EXE", "FA",
# "ISC", "ICN", "G", "INP", "PIE", "T20", "PYI", "PT", "Q", "RSE", "RET", "SLOT", "TID", "TCH", "INT", "PTH",
# "FIX", "PGH", "PL", "TRY", "FLY", "PERF", "RUF"]
unfixable = ["ERA"]

# things skipped:
# N: naming, possibly good
# D: docstrings missing throughout
# ANN: annotations missing throughout
# FBT: not convinced boolean trap worth auto-banning.
# CPY: copyright at top of each file
# G: logging warnings -- fstrings bad?
# ARG: sometimes you need to accept arguments.
# TD: somewhat finicky details about formatting TODOs
# FIX: flags todos: possible to add -- skipped for now
# ERA: lots of false positives, not a good autofix
# PD, NPY, AIR: ignored, panda / numpy / airflow specific
# FURB: not yet out of preview

[tool.ruff.lint.extend-per-file-ignores]
"test_*" = ["S101"] # `assert` is fine in tests

[tool.commitizen]
name = "cz_conventional_commits"
Expand Down
1 change: 1 addition & 0 deletions scripts/build_courts_list
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

from pathlib import Path

import yaml

print("Loading courts...")
Expand Down
4 changes: 3 additions & 1 deletion src/ds_caselaw_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from .courts import courts
from .neutral import neutral_url as neutral_url
from .neutral import neutral_url

__all__ = ["courts", "neutral_url"]
Loading

0 comments on commit d6eb5c8

Please sign in to comment.