Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
seanh committed Jan 10, 2025
1 parent 94b5ad9 commit dbd9cd7
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion _shared/project/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions _shared/project/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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
]

Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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 %}
Expand Down Expand Up @@ -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 %}
{% endif %}
12 changes: 12 additions & 0 deletions _shared/project/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions pyapp/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}",
Expand Down
1 change: 1 addition & 0 deletions pypackage/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#!/usr/bin/env python3
# mypy: disable-error-code="attr-defined"
"""
Initialize the DB.
Usage:
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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit dbd9cd7

Please sign in to comment.