Skip to content

Commit

Permalink
Clean up lint handling and mypy config (#305)
Browse files Browse the repository at this point in the history
* clean up lint handling

* clean up mypy config
  • Loading branch information
blink1073 authored Nov 5, 2023
1 parent edabdca commit 7a8ef60
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9, "3.10", "3.11"]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
fail-fast: false

steps:
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
- name: Run Linters
run: |
hatch run typing:test
hatch run lint:style
hatch run lint:build
pipx run interrogate -v .
pipx run doc8 --max-line-length=200 docs/source *.md
Expand Down
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ci:
autoupdate_schedule: monthly
autoupdate_commit_msg: "chore: update pre-commit hooks"
skip: [mypy]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down Expand Up @@ -49,6 +50,16 @@ repos:
- id: codespell
args: ["-L", "ans,te,manuel"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.6.1"
hooks:
- id: mypy
files: "^oct2py"
stages: [manual]
args: ["--install-types", "--non-interactive"]
additional_dependencies:
["ipython", "metakernel", "octave_kernel", "scipy"]

- repo: https://github.com/pre-commit/pygrep-hooks
rev: "v1.10.0"
hooks:
Expand Down
2 changes: 1 addition & 1 deletion oct2py/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def eval( # noqa
warnings.warn(msg % name, stacklevel=2)

return_both = kwargs.pop("return_both", False)
lines: list = []
lines: list[str] = []
if return_both and not stream_handler:
stream_handler = lines.append

Expand Down
6 changes: 3 additions & 3 deletions oct2py/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def write_file(obj, path, oned_as="row", convert_to_float=True):
raise Exception(msg) from None


class Struct(dict):
class Struct(dict): # type:ignore[type-arg]
"""
Octave style struct, enhanced.
Expand Down Expand Up @@ -125,7 +125,7 @@ def __dict__(self):
return self.copy()


class StructArray(np.recarray):
class StructArray(np.recarray): # type:ignore[type-arg]
"""A Python representation of an Octave structure array.
Notes
Expand Down Expand Up @@ -200,7 +200,7 @@ def __repr__(self):
return msg


class Cell(np.ndarray):
class Cell(np.ndarray): # type:ignore[type-arg]
"""A Python representation of an Octave cell array.
Notes
Expand Down
47 changes: 13 additions & 34 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,37 +72,24 @@ ARGS = "--doctest-modules -l --cov-report html --cov-report=xml --cov=oct2py -vv
[tool.hatch.envs.cover.scripts]
test = "python -m pytest $ARGS --cov-fail-under 85 {args}"

[tool.hatch.envs.typing]
features = ["test"]
dependencies = ["mypy==1.6.0"]
[tool.hatch.envs.typing.scripts]
test = "mypy --install-types --non-interactive {args:oct2py}"

[tool.hatch.envs.lint]
dependencies = [
"mdformat>0.7",
"mdformat-gfm>=0.3.5",
"ruff==0.1.3"
]
detached = true
dependencies = ["pre-commit"]
[tool.hatch.envs.lint.scripts]
style = [
"ruff {args:.}",
"ruff format {args:.}",
"mdformat --check {args:docs *.md}"
]
fmt = [
"ruff --fix {args:.}",
"ruff format {args:.}",
"mdformat {args:docs *.md}"
]
build = "pre-commit run --all-files ruff"

[tool.hatch.envs.typing]
dependencies = [ "pre-commit"]
detached = true
[tool.hatch.envs.typing.scripts]
test = "pre-commit run --all-files --hook-stage manual mypy"

[tool.pytest.ini_options]
minversion = "6.0"
xfail_strict = true
log_cli_level = "info"
addopts = [
"-raXs", "--durations=10", "--color=yes", "--doctest-modules",
"-ra", "--durations=10", "--color=yes", "--doctest-modules",
"--showlocals", "--strict-markers", "--strict-config"
]
testpaths = ["tests", "tests/ipython"]
Expand All @@ -117,6 +104,7 @@ filterwarnings= [
"ignore:Using deprecated:UserWarning:tests",
"ignore:Key - value pairs:UserWarning:tests",
"module:Jupyter is migrating its paths:DeprecationWarning",
"module:datetime.datetime.utcf:DeprecationWarning",
]

[tool.coverage.run]
Expand All @@ -127,22 +115,13 @@ omit = [
]

[tool.mypy]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_untyped_decorators = true
strict = true
disable_error_code = ["no-untyped-call", "no-untyped-def"]
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
no_implicit_optional = true
no_implicit_reexport = false
pretty = true
show_error_context = true
show_error_codes = true
strict_equality = true
strict_optional = true
warn_unused_configs = true
warn_redundant_casts = true
warn_return_any = true
warn_unreachable = true
warn_unused_ignores = true

[tool.ruff]
target-version = "py38"
Expand Down Expand Up @@ -184,4 +163,4 @@ fail-under=100
exclude = ["tests", "docs"]

[tool.repo-review]
ignore = ["PY007", "PP308", "GH102", "PC140", "MY101"]
ignore = ["PY007", "GH102", "MY101"]

0 comments on commit 7a8ef60

Please sign in to comment.