From dbd9cd78bbc302a2cbefd53670b55880f6b678a2 Mon Sep 17 00:00:00 2001 From: Sean Hammond Date: Fri, 10 Jan 2025 17:36:11 +0000 Subject: [PATCH] wip --- _shared/project/migrations/env.py | 2 +- _shared/project/pyproject.toml | 19 ++++++++++--------- _shared/project/tox.ini | 12 ++++++++++++ pyapp/cookiecutter.json | 1 + pypackage/cookiecutter.json | 1 + .../scripts/init_db.py | 8 ++------ 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/_shared/project/migrations/env.py b/_shared/project/migrations/env.py index b4dc856..eccf737 100644 --- a/_shared/project/migrations/env.py +++ b/_shared/project/migrations/env.py @@ -4,7 +4,7 @@ from alembic import context from sqlalchemy import engine_from_config, pool -from {{ cookiecutter.package_name }} import models +from {{ cookiecutter.package_name }} import models # noqa: F401 from {{ cookiecutter.package_name }}.db import Base # this is the Alembic Config object, which provides diff --git a/_shared/project/pyproject.toml b/_shared/project/pyproject.toml index c8e1cbb..2a97288 100644 --- a/_shared/project/pyproject.toml +++ b/_shared/project/pyproject.toml @@ -24,11 +24,13 @@ filterwarnings = [ {% if cookiecutter.get("linter") == "ruff" %} [tool.ruff] -target-version = "py311" +target-version = "py{{ python_versions()|oldest|pyformat(PyFormats.MAJOR_MINOR_FMT) }}" line-length = 88 +{% if include_exists("ruff/exclude") %} exclude = [ - "tests/bdd/steps/_compiled_feature_steps.py", +{{ include("ruff/exclude", indent=4) -}} ] +{% endif %} [tool.ruff.lint] select = [ @@ -41,7 +43,6 @@ select = [ "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 ] @@ -70,7 +71,7 @@ ignore = [ "D212", "D213", - # We use Black to format our code automatically, so we don't need PyLint to + # We use Black to format our code automatically, so we don't need Ruff to # check formatting for us. "E501", # line-too-long @@ -92,7 +93,7 @@ ignore = [ "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 @@ -102,7 +103,7 @@ ignore = [ "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"] {% else %} @@ -279,11 +280,11 @@ disable_error_code = [ [[tool.mypy.overrides]] module= [ - # Don't try to typecheck the tests for now - "tests.*", + # Don't try to typecheck the tests for now + "tests.*", ] ignore_errors = true {% if include_exists("pyproject.toml") %} {{ include("pyproject.toml") -}} -{% endif %} \ No newline at end of file +{% endif %} diff --git a/_shared/project/tox.ini b/_shared/project/tox.ini index 91682e1..cbbfdbd 100644 --- a/_shared/project/tox.ini +++ b/_shared/project/tox.ini @@ -66,12 +66,16 @@ deps = pip-sync-faster {% elif cookiecutter._directory == 'pypackage' %} dev: ipython +{% if cookiecutter.get("linter") == "ruff" %} + format,checkformatting,lint: ruff +{% else %} format,checkformatting: black format,checkformatting: isort lint: toml lint: pylint>=3.0.0 lint: pydocstyle lint: pycodestyle +{% endif %} lint,tests: pytest-mock lint,tests,functests: pytest lint,tests,functests: h-testkit @@ -135,6 +139,13 @@ commands = {% endif %} {% else %} dev: {posargs:ipython --classic --no-banner --no-confirm-exit} + {% if cookiecutter.get("linter") == "ruff" %} + format: ruff check --select I --fix src tests bin + format: ruff format src tests bin + checkformatting: ruff check --select I src tests bin + checkformatting: ruff format --check src tests bin + lint: ruff check --preview -q src tests bin + {% else %} format: black src tests bin format: isort --atomic src tests bin checkformatting: black --check src tests bin @@ -143,6 +154,7 @@ commands = lint: pylint --rcfile=tests/pyproject.toml tests lint: pydocstyle src tests bin lint: pycodestyle src tests bin + {% endif %} {% endif %} {% if cookiecutter._directory == "pyramid-app" and cookiecutter.get("postgres") == "yes" %} {tests,functests}: python3 -m {{ cookiecutter.package_name }}.scripts.init_db --delete --create diff --git a/pyapp/cookiecutter.json b/pyapp/cookiecutter.json index 08442aa..9d072c2 100644 --- a/pyapp/cookiecutter.json +++ b/pyapp/cookiecutter.json @@ -14,6 +14,7 @@ "devdata": ["no", "yes"], "postgres": ["no", "yes"], "docker": ["no", "yes"], + "linter": ["pylint", "ruff"], "__postgres_version": "15.3-alpine", "__postgres_port": "{{ random_port_number() }}", "__docker_namespace": "{{ cookiecutter.github_owner }}", diff --git a/pypackage/cookiecutter.json b/pypackage/cookiecutter.json index 3f67fff..9ed2831 100644 --- a/pypackage/cookiecutter.json +++ b/pypackage/cookiecutter.json @@ -13,6 +13,7 @@ "create_github_repo": ["no", "yes"], "dependabot_pip_interval": ["monthly", "weekly", "daily"], "pypi": ["no", "yes"], + "linter": ["pylint", "ruff"], "__postgres_version": "15.3-alpine", "__postgres_port": "{{ random_port_number() }}", "__entry_point": "{{ cookiecutter.slug }}", diff --git a/pyramid-app/{{ cookiecutter.slug }}/{{ cookiecutter.package_name }}/scripts/init_db.py b/pyramid-app/{{ cookiecutter.slug }}/{{ cookiecutter.package_name }}/scripts/init_db.py index be127c8..5bbf816 100755 --- a/pyramid-app/{{ cookiecutter.slug }}/{{ cookiecutter.package_name }}/scripts/init_db.py +++ b/pyramid-app/{{ cookiecutter.slug }}/{{ cookiecutter.package_name }}/scripts/init_db.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 # mypy: disable-error-code="attr-defined" """ - Initialize the DB. Usage: @@ -9,10 +8,10 @@ python3 -m {{ cookiecutter.package_name }}.scripts.init_db --help """ - {% if cookiecutter.get("linter") == "pylint" %} # pylint:disable=import-outside-toplevel,unused-import {% else %} + # ruff: noqa: PLC0415, F401 {% endif %} import argparse @@ -114,10 +113,7 @@ def main(): stamped = is_stamped(engine) if args.create: - {% if cookiecutter.get("linter") == "pylint" %} - # pylint:disable=possibly-used-before-assignment - {% endif %} - if stamped: + if stamped:{% if cookiecutter.get("linter") == "pylint" %} # pylint:disable=possibly-used-before-assignment{% endif +%} log.warning("Not creating tables because the DB is stamped by Alembic") else: create(engine)