Skip to content

Commit

Permalink
Update dependencies, update mypy & ruff config, and associated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolCat467 committed Nov 27, 2024
1 parent 0d21d4c commit 1479c10
Show file tree
Hide file tree
Showing 12 changed files with 297 additions and 79 deletions.
21 changes: 10 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
ci:
autofix_commit_msg: "[pre-commit.ci] auto fixes from pre-commit.com hooks"
autofix_prs: true
autoupdate_commit_msg: "[pre-commit.ci] pre-commit autoupdate"
autoupdate_schedule: quarterly
submodules: false
skip: [badgie, regenerate-files]
skip: [badgie, project-requirements, regenerate-files]

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -20,19 +18,12 @@ repos:
- id: check-case-conflict
- id: sort-simple-yaml
files: .pre-commit-config.yaml
- repo: https://github.com/hadialqattan/pycln
rev: v2.4.0
hooks:
- id: pycln
args: [--config=pyproject.toml, src]
types: [file]
types_or: [python, pyi]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2
rev: v0.8.0
hooks:
- id: ruff
types: [file]
Expand All @@ -48,6 +39,14 @@ repos:
- id: codespell
additional_dependencies:
- tomli
- repo: local
hooks:
- id: project-requirements
name: regenerate requirements.in
language: system
entry: python tools/project_requirements.py
pass_filenames: false
files: ^(test-requirements.in)|(pyproject.toml)$
- repo: local
hooks:
- id: regenerate-files
Expand Down
35 changes: 23 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies = [
"quart~=0.19.4",
"quart-trio~=0.11.1",
"trio~=0.27.0",
"Werkzeug~=3.1.1",
"Werkzeug~=3.1.3",
'exceptiongroup >= 1.2.0; python_version < "3.11"',
'tomli >= 2.0.1; python_version < "3.11"',
]
Expand All @@ -59,10 +59,16 @@ sanescansrv = ["py.typed", "templates/*", "static/*"]
[tool.mypy]
files = ["src/sanescansrv/",]
check_untyped_defs = true
disallow_any_decorated = true
disallow_any_generics = true
disallow_any_unimported = true
disallow_incomplete_defs = true
disallow_subclassing_any = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
ignore_missing_imports = true
local_partial_types = true
no_implicit_optional = true
no_implicit_reexport = true
show_column_numbers = true
Expand All @@ -84,11 +90,10 @@ all = true
disable_all_dunder_policy = true

[tool.black]
line-length = 120 # Will not raise errors if too big, see below.
target-version = ['py39']
line-length = 79

[tool.ruff]
line-length = 120 # I don't care about line length a whole lot, just that it's not TOO big.
line-length = 79
fix = true

include = ["*.py", "*.pyi", "**/pyproject.toml"]
Expand All @@ -100,18 +105,21 @@ select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"COM", # flake8-commas
"CPY", # flake8-copyright
"D", # pydocstyle
"E", # Error
"EXE", # flake8-executable
"F", # pyflakes
"FA", # flake8-future-annotations
"FLY", # flynt
"FURB", # refurb
"I", # isort
"ICN", # flake8-import-conventions
"N", # pep8-naming
"PIE", # flake8-pie
"PT", # flake8-pytest-style
"PYI", # flake8-pyi
"Q", # flake8-quotes
"R", # Refactor
"RET", # flake8-return
"RUF", # Ruff-specific rules
"S", # flake8-bandit
Expand All @@ -123,12 +131,15 @@ select = [
"YTT", # flake8-2020
]
extend-ignore = [
## "E501", # line-too-long
"S101", # use of assert for tests and type narrowing
"D203", # blank line thing
"D204", # blank line thing
"D211", # no-blank-line-before-class
"D213", # multi-line-summary-second-line
"D203", # one-blank-line-before-class
"D204", # one-blank-line-after-class
"D211", # no-blank-line-before-class
"D213", # multi-line-summary-second-line
"D417", # undocumented-param "Missing argument descriptions"
"E501", # line-too-long
"PYI041", # redundant-numeric-union
"S101", # assert (use of assert for tests and type narrowing)
"SIM117", # multiple-with-statements
]

[tool.ruff.lint.per-file-ignores]
Expand All @@ -138,7 +149,7 @@ extend-ignore = [
"tests/*" = [
"D100", # undocumented-public-module
"D103", # undocumented-public-function
"E501", # line too long
"D107", # undocumented-public-init
]

[tool.pytest.ini_options]
Expand Down
4 changes: 3 additions & 1 deletion src/sanescansrv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@
)

if __name__ == "__main__":
print(f"{__title__} v{__version__} Copyright (C) 2022-2024 {__author__}\n")
print(
f"{__title__} v{__version__} Copyright (C) 2022-2024 {__author__}\n",
)
run()
11 changes: 8 additions & 3 deletions src/sanescansrv/generate_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def generate_root_get() -> str:
"Select Image format:",
)

form_content = "\n".join((image_format, scanner_select))
form_content = f"{image_format}\n{scanner_select}"

contents = htmlgen.form(
"scan_request",
Expand Down Expand Up @@ -406,7 +406,9 @@ def generate_scan_status_get() -> str:
refreshes_after = htmlgen.jinja_expression("refreshes_after")
estimated_wait = htmlgen.jinja_expression("estimated_wait")

percent = htmlgen.jinja_expression("(progress[0] / progress[1] * 100)|round(2)")
percent = htmlgen.jinja_expression(
"(progress[0] / progress[1] * 100)|round(2)",
)
is_done = "progress[0] == progress[1]"

title = htmlgen.jinja_if_block(
Expand All @@ -428,7 +430,10 @@ def generate_scan_status_get() -> str:

refresh_link = htmlgen.create_link("/scan-status", "this link")

refresh_time_plural = htmlgen.jinja_number_plural("refreshes_after", "second")
refresh_time_plural = htmlgen.jinja_number_plural(
"refreshes_after",
"second",
)
refresh_time_display = f"{refreshes_after} {refresh_time_plural}"

content = "\n".join(
Expand Down
11 changes: 9 additions & 2 deletions src/sanescansrv/htmlgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,11 @@ def select_dict(
# Otherwise user can define field type.
attributes = dict(value_data) # type: ignore[arg-type]
field_type = attributes.pop("type", "radio")
if field_type == "radio" and "value" in attributes and attributes["value"] == default:
if (
field_type == "radio"
and "value" in attributes
and attributes["value"] == default
):
attributes["checked"] = "checked"
lines.append(
input_field(
Expand Down Expand Up @@ -560,7 +564,10 @@ def jinja_extends(template_filename: str | Iterable[str]) -> str:
"""Return jinja extends statement from given template filename."""
# Using if else instead of ternary because it makes it confusing from
# a types perspective and less readable
if isinstance(template_filename, str): # noqa: SIM108 # ternary operator instead of if else
if isinstance(
template_filename,
str,
): # ternary operator instead of if else
filename = template_filename
else:
filename = "/".join(template_filename)
Expand Down
8 changes: 6 additions & 2 deletions src/sanescansrv/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,15 @@ def log(message: str, level: int = 1, log_dir: str | None = None) -> None:
log_time = time.asctime()
log_message_text = message.encode("unicode_escape").decode("utf-8")

log_msg = f"[{PROGRAM_TITLE}] [{log_time}] [{log_level}] {log_message_text}"
log_msg = (
f"[{PROGRAM_TITLE}] [{log_time}] [{log_level}] {log_message_text}"
)

# Open in append mode; this will create the file if it doesn't exist
with open(log_file, mode="a", encoding="utf-8") as file:
file.write(f"{log_msg}\n") # This handles both file creation and writing
file.write(
f"{log_msg}\n",
) # This handles both file creation and writing
print(log_msg)


Expand Down
Loading

0 comments on commit 1479c10

Please sign in to comment.