Skip to content

Commit

Permalink
Apply updates from cookiecutter
Browse files Browse the repository at this point in the history
This automated commit applies the latest updates from our cookiecutters [1] to
this repo.

[1]: https://github.com/hypothesis/cookiecutters
  • Loading branch information
github-actions[bot] committed Jan 22, 2025
1 parent c4b719f commit abb303c
Show file tree
Hide file tree
Showing 8 changed files with 257 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/slack.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Slack
on:
workflow_run:
workflows: [CI, Deploy, Report refresh]
workflows: [CI, Deploy]
types: [completed]
branches: [main]
jobs:
Expand Down
23 changes: 13 additions & 10 deletions lms/scripts/init_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
python3 -m lms.scripts.init_db --help
"""

# pylint:disable=import-outside-toplevel,unused-import
import argparse
import logging
from os import environ
Expand All @@ -19,7 +19,7 @@
from sqlalchemy.engine import Engine
from sqlalchemy.exc import ProgrammingError

from lms import models # noqa: F401
from lms import models
from lms.db import Base, create_engine

log = logging.getLogger(__name__)
Expand All @@ -42,22 +42,25 @@ def delete(engine: Engine) -> None:
"""Delete any existing DB tables."""

try:
from lms.db import pre_delete # noqa: PLC0415
from lms.db import pre_delete
except ImportError:
pass
else:
pre_delete(engine)

with engine.connect() as connection:
# Delete the DB "public" schema directly.
# We do this instead of using SQLAlchemy's drop_all because we want to delete all tables in the current DB.
# For example, this will delete tables created by migrations in other branches, not only the ones SQLAlchemy know about in the current code base.
# Delete the DB's "public" schema directly.
# We do this instead of using SQLAlchemy's drop_all() because we want
# to delete *all* tables in the DB, not just the ones that SQLAlchemy
# knows about from the current codebase.
# For example this will delete tables created by migrations in other
# branches.
connection.execute(text("DROP SCHEMA PUBLIC CASCADE;"))
connection.execute(text("CREATE SCHEMA PUBLIC;"))
connection.execute(text("COMMIT;"))

try:
from lms.db import post_delete # noqa: PLC0415
from lms.db import post_delete
except ImportError:
pass
else:
Expand All @@ -68,7 +71,7 @@ def create(engine: Engine) -> None:
"""Create new DB tables from the app's models."""

try:
from lms.db import pre_create # noqa: PLC0415
from lms.db import pre_create
except ImportError:
pass
else:
Expand All @@ -77,7 +80,7 @@ def create(engine: Engine) -> None:
Base.metadata.create_all(engine)

try:
from lms.db import post_create # noqa: PLC0415
from lms.db import post_create
except ImportError:
pass
else:
Expand Down Expand Up @@ -114,7 +117,7 @@ def main():
stamped = is_stamped(engine)

if args.create:
if stamped:
if stamped: # pylint:disable=possibly-used-before-assignment
log.warning("Not creating tables because the DB is stamped by Alembic")
else:
create(engine)
Expand Down
207 changes: 133 additions & 74 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,34 @@ filterwarnings = [
"ignore:^pkg_resources is deprecated as an API:DeprecationWarning:pyramid",
"ignore:^Deprecated call to .pkg_resources\\.declare_namespace\\('.*'\\).\\.:DeprecationWarning:pkg_resources",
"ignore:^'cgi' is deprecated and slated for removal in Python 3\\.13$:DeprecationWarning:webob",
"ignore:^datetime\\.datetime\\.utcnow\\(\\) is deprecated and scheduled for removal in a future version\\.:DeprecationWarning",
]

[tool.pydocstyle]
ignore = [
# Missing docstrings.
"D100","D101","D102","D103","D104","D105","D106","D107",

# "No blank lines allowed after function docstring" conflicts with the
# Black code formatter which insists on inserting blank lines after
# function docstrings.
"D202",

# "1 blank line required before class docstring" conflicts with another
# pydocstyle rule D211 "No blank lines allowed before class docstring".
"D203",

# "Multi-line docstring summary should start at the first line"
# and "Multi-line docstring summary should start at the second line".
# These two rules conflict with each other so you have to disable one of them.
# How about we disable them both? PEP 257 says either approach is okay:
#
# > The summary line may be on the same line as the opening quotes or on
# > the next line.
# >
# > https://peps.python.org/pep-0257/#multi-line-docstrings
"D212",
"D213",
]

[tool.coverage.run]
Expand All @@ -32,108 +60,139 @@ precision = 2
fail_under = 100.00
skip_covered = true
exclude_also = [
# # TYPE_CHECKING block is only executed while running mypy
"if TYPE_CHECKING:"
# `if TYPE_CHECKING:` blocks are only executed while running mypy.
"if TYPE_CHECKING:",
]

[tool.ruff]
target-version = "py311"
line-length = 88
exclude = [
"tests/bdd/steps/_compiled_feature_steps.py",
[tool.isort]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
line_length = 88
default_section = "THIRDPARTY"
known_first_party = ["lms", "tests"]

[tool.pylint.main]
jobs = 0 # Use one process for CPU.

load-plugins = [
"pylint.extensions.bad_builtin",
"pylint.extensions.check_elif",
"pylint.extensions.docparams",
"pylint.extensions.mccabe",
"pylint.extensions.overlapping_exceptions",
"pylint.extensions.redefined_variable_type",
]

[tool.ruff.lint]
select = [
"E", "W", # https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
"D", # https://docs.astral.sh/ruff/rules/#pydocstyle-d
"ARG", # https://docs.astral.sh/ruff/rules/#flake8-unused-arguments-arg
"BLE001", # https://docs.astral.sh/ruff/rules/blind-except/
"R", "PLR", # https://docs.astral.sh/ruff/rules/#refactor-r
"C", "PLC", # https://docs.astral.sh/ruff/rules/#convention-c
"SLF", # flake-8-self
"N", # https://docs.astral.sh/ruff/rules/#pep8-naming-n
"F", # https://docs.astral.sh/ruff/rules/unused-import/

"RUF100", # unused-noqa
# Fail if there are *any* messages from PyLint.
# The letters refer to PyLint's message categories, see
# https://pylint.pycqa.org/en/latest/messages/messages_introduction.html
fail-on = ["C", "E", "F", "I", "R", "W"]

[tool.pylint.messages_control]
ignore-paths=[
]
enable = [
"bad-inline-option",
"deprecated-pragma",
"useless-suppression",
"use-symbolic-message-instead",
"use-implicit-booleaness-not-comparison-to-zero",
"use-implicit-booleaness-not-comparison-to-string",
]
disable = [
# Docstrings are encouraged but we don't want to enforce that everything
# must have a docstring.
"missing-docstring",

ignore = [
# Missing docstrings.
"D100","D101","D102","D103","D104","D105","D106","D107",
# We don't always want to have to put a `:return:` in a docstring.
"missing-return-doc",

# "No blank lines allowed after function docstring" conflicts with the
# Black code formatter which insists on inserting blank lines after
# function docstrings.
"D202",
# We don't always want to have to put an `:rtype:` in a docstring.
"missing-return-type-doc",

# "1 blank line required before class docstring" conflicts with another
# pydocstyle rule D211 "No blank lines allowed before class docstring".
"D203",
# We don't want to have to document the type of every parameter with a
# `:type:` in the docstring.
"missing-type-doc",

# "Multi-line docstring summary should start at the first line"
# and "Multi-line docstring summary should start at the second line".
# These two rules conflict with each other so you have to disable one of them.
# How about we disable them both? PEP 257 says either approach is okay:
#
# > The summary line may be on the same line as the opening quotes or on
# > the next line.
# >
# > https://peps.python.org/pep-0257/#multi-line-docstrings
"D212",
"D213",
# We use isort to sort and group our imports, so we don't need PyLint to
# check them for us.
"ungrouped-imports",

# We use Black to format our code automatically, so we don't need PyLint to
# check formatting for us.
"E501", # line-too-long
"line-too-long",

"PLR2004", # Magic values, we mostly get it on HTTP status codes
# We use isort to sort out imports so we don't need PyLint to check import
# ordering for us.
"wrong-import-order",

# Disabled during the pylint migration, ideally we'll enable this after we are settled in ruff
"RET504",
"RET501",
"PLR6301",
"too-few-public-methods",

# Issues to disable this for false positives, disabling it globally in the meantime https://github.com/PyCQA/pylint/issues/214
"duplicate-code",
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = [
# Just disable name style checking for the tests, because we
# frequently use lots of argument names that don't conform.
# For example we frequently create pytest fixtures that aren't named in
# snake_case, such as a fixture that returns a mock of the FooBar class would
# be named FooBar in CamelCase.
"N",
# We are more lax about comment formatting in the tests
"D",

"PLR0913",

# Lots of test methods don't use self, but we still want to group our tests
# into classes.
"PLR6301",

"PLR0917", # too-many-arguments
"PLC2701", # private import
"PLR0904", # too-many-public-methods
]
# Ignore unused import errors on __init__ files to avoid having to add either a noqa stament or an __all__ declaration.
"__init__.py" = ["F401"]
good-names = [
"i", "j", "k", "ex", "Run", "_", # PyLint's default good names.
"tm", "db", "ai",
]

[tool.pylint.reports]
output-format = "colorized"
score = "no"

[tool.mypy]
python_version = 3.11
allow_untyped_globals = true
error_summary = false
pretty = true
warn_unused_configs = true
warn_redundant_casts = true
warn_unused_ignores = true
check_untyped_defs = true

disable_error_code = [
# https://mypy.readthedocs.io/en/stable/error_code_list.html#code-import-untyped
"import-untyped",
]

[[tool.mypy.overrides]]
module= [
module = [
# Don't try to typecheck the tests for now.
"tests.*",
"lms.migrations.*"
]
ignore_errors = true

[tool.mypy]
python_version = 3.11

disable_error_code = [
"arg-type",
"assignment",
"attr-defined",
"has-type",
"import-untyped",
"index",
"list-item",
"misc",
"no-redef",
"no-untyped-call",
"no-untyped-def",
"override",
"return-value",
"type-arg",
"union-attr",
"valid-type",
]

plugins = [
"sqlalchemy.ext.mypy.plugin",
]

[[tool.mypy.overrides]]
module="tests.*"
ignore_errors = true

[[tool.mypy.overrides]]
module="lms.migrations.*"
ignore_errors = true
3 changes: 2 additions & 1 deletion requirements/checkformatting.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pip-tools
pip-sync-faster
ruff
black
isort
3 changes: 2 additions & 1 deletion requirements/format.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pip-tools
pip-sync-faster
ruff
black
isort
5 changes: 4 additions & 1 deletion requirements/lint.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ pip-tools
pip-sync-faster
-r tests.txt
-r functests.txt
ruff
toml # Needed for pydocstyle to support pyproject.toml.
pylint>=3.0.0
pydocstyle
pycodestyle
-r bddtests.txt
Loading

0 comments on commit abb303c

Please sign in to comment.