Skip to content

Commit

Permalink
Building up ruff linting, still need to add pylint or pyflakes
Browse files Browse the repository at this point in the history
  • Loading branch information
le717 committed Jun 8, 2024
1 parent b59174e commit 6b190bb
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 26 deletions.
4 changes: 1 addition & 3 deletions db/env.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from logging.config import fileConfig

from alembic import context
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from sqlalchemy import engine_from_config, pool

from src.app_factory import create_app


# There's no access to current_app here so we must create our own app.
app = create_app()
db_uri = app.config["SQLALCHEMY_DATABASE_URI"]
Expand Down
3 changes: 1 addition & 2 deletions db/versions/7e3df200a38d_remove_rotted_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
"""

from alembic import op
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "7e3df200a38d"
Expand Down
3 changes: 1 addition & 2 deletions db/versions/c41abb284c8f_add_is_dead_is_web_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
"""

from alembic import op
import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision = "c41abb284c8f"
Expand Down
2 changes: 1 addition & 1 deletion get-requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def filter_packages(packages: list, key: str) -> list:
all_packages += filter_packages(poetry_lock["package"], "dev")

# Open the requirements file for writing
with open("requirements.txt", "wt") as f:
with open("requirements.txt", "w") as f:
# Write all the requested packages
for package in all_packages:
f.write(f"{get_package(package)}\n")
30 changes: 30 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,37 @@ target-version = "py311"
line-length = 100
indent-width = 4

[tool.ruff.lint]
preview = true

select = [
"A", # flake8-builtins
"ARG", # flake8-unused-arguments
"BLE", # flake8-blind-except
"C4", # flake8-comprehensions
"C90", # mccabe
"DTZ", # flake8-datetimez
"ERA", # eradicate
"FIX", # flake8-fixme
"FLY", # flynt
"FURB", # refurb
"I", # isort
"LOG", # flake8-logging
"G", # flake8-logging-format
"PERF", # Perflint
"PIE", # flake8-pie
"PTH", # flake8-use-pathlib
"RET", # flake8-return
"SIM", # flake8-simplify
"T20", # flake8-print
"TD", # flake8-todos
"UP", # pyupgrade
]

[tool.ruff.format]
preview = true
indent-style = "space"
quote-style = "double"

[tool.ruff.lint.mccabe]
max-complexity = 10
3 changes: 2 additions & 1 deletion src/core/database/linkrot.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __update(data: RottedLinks) -> Literal[True]:


def delete(uuid: str) -> bool:
"""Delete an item from the linkrot log."""
if exists := __get(uuid):
db.session.delete(exists)
db.session.commit()
Expand All @@ -74,7 +75,7 @@ def delete(uuid: str) -> bool:

def check_all() -> list[RotResult]:
"""Check all links for rotting."""
return [check_one(link.id) for link in weblink.get_all()]
return [check_one(link.id) for link in weblink.get_all(include_rotted=False)]


def check_one(uuid: str) -> RotResult | None:
Expand Down
1 change: 0 additions & 1 deletion src/core/database/schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import Column, DateTime, Integer, String, inspect

Expand Down
9 changes: 5 additions & 4 deletions src/core/database/weblink.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import uuid
from datetime import datetime, timezone
from typing import Any, Optional, OrderedDict
from collections import OrderedDict
from datetime import UTC, datetime, timezone
from typing import Any, Optional

from markupsafe import Markup
from sqlalchemy import func
Expand All @@ -19,7 +20,7 @@ def create(data: OrderedDict) -> dict[str, uuid.UUID]:
title=Markup(data["title"]).striptags(),
description=Markup(data["description"]).striptags(),
url=Markup(data["url"]).striptags(),
date_added=datetime.now(timezone.utc),
date_added=datetime.now(UTC),
)
db.session.add(weblink)
db.session.commit()
Expand Down Expand Up @@ -52,7 +53,7 @@ def exists(uuid: str) -> bool:
return get(uuid) is not None


def get(uuid: str) -> Optional[WebLink]:
def get(uuid: str) -> WebLink | None:
"""Get a single weblink."""
return db.session.execute(db.select(WebLink).filter_by(id=uuid)).scalars().first()

Expand Down
3 changes: 1 addition & 2 deletions src/core/models/AuthKey.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from marshmallow import fields, Schema
import sys_vars

from marshmallow import Schema, fields

AUTH_KEYS = sys_vars.get_json("AUTH_KEYS")

Expand Down
1 change: 0 additions & 1 deletion src/core/models/Empty.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from marshmallow import Schema


__all__ = ["Empty"]


Expand Down
3 changes: 1 addition & 2 deletions src/core/models/HttpError.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from marshmallow import fields, Schema

from marshmallow import Schema, fields

__all__ = ["HttpError"]

Expand Down
3 changes: 1 addition & 2 deletions src/core/models/RotResult.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from marshmallow import fields, Schema

from marshmallow import Schema, fields

__all__ = ["RotResult"]

Expand Down
4 changes: 2 additions & 2 deletions src/core/models/WebLink.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import timezone
from datetime import UTC, timezone

from marshmallow import Schema, fields

Expand All @@ -10,7 +10,7 @@ class WebLink(Schema):
title = fields.String()
description = fields.String()
url = fields.Url()
date_added = fields.AwareDateTime(format="iso", default_timezone=timezone.utc)
date_added = fields.AwareDateTime(format="iso", default_timezone=UTC)
is_dead = fields.Boolean()
is_web_archive = fields.Boolean()

Expand Down
3 changes: 2 additions & 1 deletion src/views/root.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Sequence
from collections.abc import Sequence
from typing import Any
from uuid import UUID

from flask import abort, request
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

import pytest

os.environ["SYS_VARS_PATH"] = f"{os.getcwd()}/tests/secrets"
Expand Down
3 changes: 1 addition & 2 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
from urllib.parse import urlencode
from typing import Any

from urllib.parse import urlencode

__all__ = [
"INVALID_AUTH",
Expand Down

0 comments on commit 6b190bb

Please sign in to comment.