8000 Update pre-commit to all files and Mypy setup by Ckk3 · Pull Request #247 · strawberry-graphql/strawberry-sqlalchemy · GitHub
[go: up one dir, main page]

Skip to content

Update pre-commit to all files and Mypy setup #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
97fcd53
Update pre-commit and mypy .ini just like the main strawberry project
Ckk3 May 15, 2025
1438dbf
add a lint error on purpose to test lint
Ckk3 May 15, 2025
fe06304
add a release md and add file attr to tmol pre-commit
Ckk3 May 15, 2025
02e8b96
fix test action to run when a PR is ready for review
Ckk3 May 15, 2025
dd930aa
test mappe
Ckk3 May 15, 2025
cc0f7bd
fix action
Ckk3 May 15, 2025
0eb03fc
continue with tests in lint in nox file
Ckk3 May 15, 2025
7779489
remove pydantic.mypy plugin
Ckk3 May 15, 2025
8183f72
made first lint ajustment, but still missing lint test
Ckk3 May 15, 2025
59891f5
add ruff and black to lint te
Ckk3 May 15, 2025
0bda534
Fix nox file and add ruff to pyptoject toml
Ckk3 May 15, 2025
e653367
fix poetry lock
Ckk3 May 15, 2025
18b1149
fix command to raise error
Ckk3 May 15, 2025
adf32a4
make ruff output errors
Ckk3 May 15, 2025
75c902d
bring back black to pre-commit
Ckk3 May 15, 2025
5ba4a2a
remove --diff from ruff because we want to run in all files, remove i…
Ckk3 May 15, 2025
a8ecbff
update pre-commit to ruff run lint and formatter
Ckk3 May 15, 2025
ca21f70
separate ruff lint from formater in noxfile
Ckk3 May 15, 2025
4e54534
remove test function from mapper
Ckk3 May 15, 2025
2092cc4
remove black and use only ruff
Ckk3 May 17, 2025
ee70dae
add lint tag to ruff format in nox
Ckk3 May 17, 2025
1960ed0
change test.yml to run lint and format divided
Ckk3 May 17, 2025
5ab92da
Run pre-commit in all files and made line-lenght 100
Ckk3 May 17, 2025
b0062eb
updated ruff check
Ckk3 May 17, 2025
c7bba33
update pyproject.toml
Ckk3 May 17, 2025
6683ab8
Made sourcery fixes
Ckk3 May 18, 2025
8062203
remove unecessary else
Ckk3 May 18, 2025
29f86c6
bring back session._session
Ckk3 May 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .alexrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"allow": [
"black",
"hook",
"hooks",
"failure",
Expand Down
7 changes: 3 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@
"python.linting.enabled": true,
"python.linting.pylintEnabled": false,
"python.linting.mypyEnabled": true,
"python.linting.mypyPath": "${workspaceFolder}/.venv/bin/mypy",
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
},
"python.formatting.provider": "black",
"python.formatting.blackPath": "${workspaceFolder}/.venv/bin/black",
"python.linting.mypyPath": "${workspaceFolder}/.venv/bin/mypy"
"python.formatting.provider": "none"
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-azuretools.vscode-docker",
"eamodio.gitlens",
"charliermarsh.ruff",
// Dont install these extensions because they conflict with black lint
// Dont install these extensions because they conflict with lint
"-dbaeumer.vscode-eslint",
"-ms-python.autopep8"
]
Expand Down
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ updates:
all-dependencies:
patterns:
- "*"
# Strawberry is an internal dependency,
# Strawberry is an internal dependency,
# let's keep an additional eye on this
exclude-patterns:
- "strawberry-graphql"
Expand Down
4 changes: 1 addition & 3 deletions .github/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[tool.ruff]
extend = "../pyproject.toml"
extend-ignore = [
"T201",
]
lint.extend-ignore = ["T201"]
10 changes: 7 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ on:
push:
branches: [main]
pull_request:
branches: [main]
types: [synchronize, reopened, opened, ready_for_review]
branches:
- main
paths:
- "src/strawberry-sqlalchemy-mapper/**"
- "tests/**"
Expand All @@ -29,7 +31,7 @@ jobs:
- id: set-matrix
shell: bash
run: |
. .venv/bin/activate
. .venv/bin/activate
pip install poetry nox nox-poetry
echo sessions=$(
nox --json -t tests -l |
Expand Down Expand Up @@ -103,7 +105,7 @@ jobs:
run: poetry run pytest tests/benchmarks --codspeed

lint:
name: ✨ Lint
name: ✨ Lint and Format
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -132,7 +134,9 @@ jobs:
${{ runner.os }}-nox-lint-${{ env.pythonLocation }}

- run: pip install poetry nox nox-poetry uv
- run: mkdir .mypy_cache
- run: nox -r -t lint
- run: nox -r -t format

unit-tests-on-windows:
name: 🪟 Tests on Windows
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ cover/*
MANIFEST

# Per-project virtualenvs
venv*/
.venv*/
.conda*/
3 changes: 0 additions & 3 deletions .isort.cfg

This file was deleted.

22 changes: 13 additions & 9 deletions .pre-commit-config.yaml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
repos:
- repo: https://github.com/psf/black
rev: 24.4.0
hooks:
- id: black
exclude: ^tests/\w+/snapshots/

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.7
# Ruff version.
rev: v0.11.10
hooks:
- id: ruff
exclude: ^tests/\w+/snapshots/
# Run the linter.
- id: ruff-check
args: [--fix]
# Run the formatter.
- id: ruff-format

- repo: https://github.com/patrick91/pre-commit-alex
rev: aa5da9e54b92ab7284feddeaf52edf14b1690de3
Expand Down Expand Up @@ -37,3 +35,9 @@ repos:
hooks:
- id: blacken-docs
args: [--skip-errors]

- repo: https://github.com/ComPWA/taplo-pre-commit
rev: v0.9.3
hooks:
- id: taplo-format
files: \.(toml)$
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,3 @@ Contributed by [Layton Wedgeworth](https://github.com/asimov-layton) via [PR #24
Dependency version changes needed for python 3.12 compatibility.

Contributed by [mattalbr](https://github.com/mattalbr) via [PR #35](https://github.com/strawberry-graphql/strawberry-sqlalchemy/pull/35/)


1 change: 0 additions & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ on PyPI_, the following steps can be used to release a new version for
.. |tox| replace:: ``tox``


.. _black: https://pypi.org/project/black/
.. _CommonMark: https://commonmark.org/
.. _contribution-guide.org: https://www.contribution-guide.org/
.. _creating a PR: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request
Expand Down
10 changes: 10 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Release type: patch

This release does not introduce any new features or bug fixes. It focuses solely on internal code quality improvements.

Changes:
- Added Mypy configuration aligned with the main Strawberry project.
- Enforced type checking via CI to ensure consistency.
- Ran pre-commit across all files to standardize formatting and follow the project's linting architecture.

These changes aim to improve maintainability and ensure better development practices moving forward.
27 changes: 15 additions & 12 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
# serve to show the default.

import os
import sys
import shutil
import sys
from contextlib import suppress

# -- Path setup --------------------------------------------------------------

Expand All @@ -35,10 +36,9 @@

output_dir = os.path.join(__location__, "api")
module_dir = os.path.join(__location__, "../src/strawberry_sqlalchemy_mapper")
try:

with suppress(FileNotFoundError):
shutil.rmtree(output_dir)
except FileNotFoundError:
pass

try:
import sphinx
Expand All @@ -52,7 +52,7 @@

apidoc.main(args)
except Exception as e:
print("Running `sphinx-apidoc` failed!\n{}".format(e))
print(f"Running `sphinx-apidoc` failed!\n{e}") # noqa: T201

# -- General configuration ---------------------------------------------------

Expand Down Expand Up @@ -96,7 +96,7 @@
#
# version: The short X.Y version.
# release: The full version, including alpha/beta/rc tags.
# If you dont need the separation provided between version and release,
# If you don't need the separation provided between version and release,
# just set them both to the same value.
try:
from strawberry_sqlalchemy_mapper import __version__ as version
Expand Down Expand Up @@ -158,10 +158,7 @@
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
"sidebar_width": "300px",
"page_width": "1200px"
}
html_theme_options = {"sidebar_width": "300px", "page_width": "1200px"}

# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = []
Expand Down Expand Up @@ -246,7 +243,13 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
("index", "user_guide.tex", "strawberry-sqlalchemy-mapper Documentation", "Tim Dumol", "manual")
(
"index",
"user_guide.tex",
"strawberry-sqlalchemy-mapper Documentation",
"Tim Dumol",
"manual",
)
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -283,4 +286,4 @@
"pyscaffold": ("https://pyscaffold.org/en/stable", None),
}

print(f"loading configurations for {project} {version} ...", file=sys.stderr)
print(f"loading configurations for {project} {version} ...", file=sys.stderr) # noqa: T201
46 changes: 42 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
]


def poetry_install_run_always(session: Session) -> None:
session.run_always("poetry", "install", external=True)


@session(python=PYTHON_VERSIONS, name="SQLAlchemy 2.0 Tests", tags=["tests"])
def tests_sqlalchemy_latest(session: Session) -> None:
session.run_always(
Expand All @@ -31,7 +35,7 @@ def tests_sqlalchemy_latest(session: Session) -> None:
"wheel",
external=True,
)
session.run_always("poetry", "install", external=True)
poetry_install_run_always(session)

session.run(
"pytest",
Expand All @@ -53,7 +57,7 @@ def tests_sqlalchemy_1_4(session: Session) -> None:
"wheel",
external=True,
)
session.run_always("poetry", "install", external=True)
poetry_install_run_always(session)
session._session.install("sqlalchemy~=1.4")

session.run(
Expand All @@ -64,6 +68,40 @@ def tests_sqlalchemy_1_4(session: Session) -> None:

@session(name="Mypy", tags=["lint"])
def mypy(session: Session) -> None:
session.run_always("poetry", "install", external=True)
poetry_install_run_always(session)

session.run(
"mypy",
"--install-types",
"--non-interactive",
"--cache-dir=.mypy_cache/",
"--config-file",
"mypy.ini",
)

session.run("mypy", "--config-file", "mypy.ini")

@session(name="Ruff Lint", tags=["lint"])
def ruff_lint(session: Session) -> None:
poetry_install_run_always(session)

session.run(
"ruff",
"check",
"--no-fix",
".",
silent=False,
)


@session(name="Ruff Format", tags=["format"])
def ruff_format(session: Session) -> None:
poetry_install_run_always(session)

session.run(
"ruff",
"format",
"--check",
"--diff",
".",
silent=False,
)
Loading
Loading
0