From 0eaf8ef9f06f821bfb590d7643d3f0f3eaba78ff Mon Sep 17 00:00:00 2001 From: Eduardo Klosowski Date: Wed, 28 Aug 2024 01:58:32 -0300 Subject: [PATCH 1/6] Refactor editorconfig settings --- .devcontainer/devcontainer.json | 58 ++++++++++++++++----------------- .editorconfig | 5 +-- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index da411c2..de8fe49 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,37 +1,35 @@ { - "name": "qldebugger", + "name": "qldebugger", - "image": "mcr.microsoft.com/devcontainers/python:3.8-bookworm", - "features": { - "ghcr.io/devcontainers-contrib/features/apt-packages:1": { - "packages": "bash-completion" - }, - "ghcr.io/devcontainers-contrib/features/poetry:2": {} - }, + "image": "mcr.microsoft.com/devcontainers/python:3.8-bookworm", + "features": { + "ghcr.io/devcontainers-contrib/features/apt-packages:1": {"packages": "bash-completion"}, + "ghcr.io/devcontainers-contrib/features/poetry:2": {} + }, - "containerUser": "vscode", - "runArgs": [ - "--userns=keep-id" - ], - "mounts": [ - { - "type": "bind", - "source": "/etc/localtime", - "target": "/etc/localtime" - } - ], + "containerUser": "vscode", + "runArgs": [ + "--userns=keep-id" + ], + "mounts": [ + { + "type": "bind", + "source": "/etc/localtime", + "target": "/etc/localtime" + } + ], - "postCreateCommand": "scripts/update-tools-completion.sh\nscripts/init-project.sh", + "postCreateCommand": "scripts/update-tools-completion.sh\nscripts/init-project.sh", - "customizations": { - "vscode": { - "extensions": [ - "editorconfig.editorconfig", - "tamasfe.even-better-toml", - "ms-python.autopep8", - "charliermarsh.ruff", - "matangover.mypy" - ] - } + "customizations": { + "vscode": { + "extensions": [ + "editorconfig.editorconfig", + "tamasfe.even-better-toml", + "ms-python.autopep8", + "charliermarsh.ruff", + "matangover.mypy" + ] } + } } diff --git a/.editorconfig b/.editorconfig index b477bf3..e2d9602 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,8 +11,5 @@ insert_final_newline = true [Makefile] indent_style = tab -[*.toml] -indent_size = 2 - -[*.{yml,yaml}] +[*.{json,toml,yaml,yml}] indent_size = 2 From e28ef23fd981e3b55e7664730f821eeef03dcd47 Mon Sep 17 00:00:00 2001 From: Eduardo Klosowski Date: Tue, 3 Sep 2024 23:39:35 -0300 Subject: [PATCH 2/6] Refactor devcontainer --- .devcontainer/devcontainer.json | 25 ++++++++++++------- .gitignore | 4 +-- .vscode/settings.json.example | 18 ------------- scripts/init-project.sh | 7 ------ ...ls-completion.sh => setup-devcontainer.sh} | 19 ++++++++------ 5 files changed, 30 insertions(+), 43 deletions(-) delete mode 100644 .vscode/settings.json.example delete mode 100755 scripts/init-project.sh rename scripts/{update-tools-completion.sh => setup-devcontainer.sh} (53%) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index de8fe49..795dd7d 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,16 +1,11 @@ { "name": "qldebugger", - "image": "mcr.microsoft.com/devcontainers/python:3.8-bookworm", + "image": "mcr.microsoft.com/devcontainers/python:1-3.8-bookworm", "features": { - "ghcr.io/devcontainers-contrib/features/apt-packages:1": {"packages": "bash-completion"}, - "ghcr.io/devcontainers-contrib/features/poetry:2": {} + "ghcr.io/devcontainers-contrib/features/poetry:2": {"version": "1.8.3"} }, - "containerUser": "vscode", - "runArgs": [ - "--userns=keep-id" - ], "mounts": [ { "type": "bind", @@ -19,7 +14,7 @@ } ], - "postCreateCommand": "scripts/update-tools-completion.sh\nscripts/init-project.sh", + "postCreateCommand": "./scripts/setup-devcontainer.sh", "customizations": { "vscode": { @@ -29,7 +24,19 @@ "ms-python.autopep8", "charliermarsh.ruff", "matangover.mypy" - ] + ], + "settings": { + "python.defaultInterpreterPath": "./.venv/bin/python", + "autopep8.importStrategy": "fromEnvironment", + "ruff.importStrategy": "fromEnvironment", + "mypy.runUsingActiveInterpreter": true, + "mypy.targets": ["qldebugger", "tests"], + "python.testing.pytestEnabled": true, + "python.testing.pytestArgs": ["--no-cov", "tests"], + "[python]": { + "editor.defaultFormatter": "ms-python.autopep8" + } + } } } } diff --git a/.gitignore b/.gitignore index b3aa7c4..aad0166 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ __pycache__ /dist # Development tools +/.venv /.ruff_cache /.mypy_cache /.pytest_cache @@ -17,8 +18,7 @@ __pycache__ # Editors *.swp /.idea -/.vscode/* -!/.vscode/*.example +/.vscode # Configs /qldebugger.toml diff --git a/.vscode/settings.json.example b/.vscode/settings.json.example deleted file mode 100644 index 0c3395a..0000000 --- a/.vscode/settings.json.example +++ /dev/null @@ -1,18 +0,0 @@ -{ - "python.defaultInterpreterPath": "python", - "autopep8.importStrategy": "fromEnvironment", - "ruff.importStrategy": "fromEnvironment", - "mypy.runUsingActiveInterpreter": true, - "mypy.targets": [ - "qldebugger", - "tests" - ], - "python.testing.pytestEnabled": true, - "python.testing.pytestArgs": [ - "--no-cov", - "tests" - ], - "[python]": { - "editor.defaultFormatter": "ms-python.autopep8" - } -} diff --git a/scripts/init-project.sh b/scripts/init-project.sh deleted file mode 100755 index 6342000..0000000 --- a/scripts/init-project.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -xe - -# Project dependencies -poetry install --with=docs - -# Visual Studio Code -[ -e .vscode/settings.json ] || jq ".[\"python.defaultInterpreterPath\"] = \"$(poetry env info -e)\"" .vscode/settings.json.example > .vscode/settings.json diff --git a/scripts/update-tools-completion.sh b/scripts/setup-devcontainer.sh similarity index 53% rename from scripts/update-tools-completion.sh rename to scripts/setup-devcontainer.sh index f1144df..cf189f6 100755 --- a/scripts/update-tools-completion.sh +++ b/scripts/setup-devcontainer.sh @@ -1,11 +1,16 @@ -#!/bin/bash -xe +#!/bin/bash -# Dependencies -which register-python-argcomplete >/dev/null || /usr/local/bin/pip install --user argcomplete -mkdir -p ~/.local/share/bash-completion/completions +set -xe -# pipx -echo 'eval "$(register-python-argcomplete pipx)"' > ~/.local/share/bash-completion/completions/pipx +# Config poetry +poetry config virtualenvs.in-project true +[ -e .venv ] || poetry env use /usr/local/bin/python -# Poetry +# Completion +pipx install argcomplete +mkdir -p ~/.local/share/bash-completion/completions +echo 'eval "$(register-python-argcomplete pipx)"' > ~/.local/share/bash-completion/completions/pipx echo 'eval "$(poetry completions bash)"' > ~/.local/share/bash-completion/completions/poetry + +# Init project +poetry install --with=docs From 8d1d88ece62bd136b05be3b8cc217804b7951442 Mon Sep 17 00:00:00 2001 From: Eduardo Klosowski Date: Tue, 3 Sep 2024 23:57:45 -0300 Subject: [PATCH 3/6] Refactor project struct --- .devcontainer/devcontainer.json | 4 ++-- .gitignore | 4 ++-- Makefile | 23 +++++++++++++++---- docs/debuggers/vscode.md | 2 +- pyproject.toml | 8 +++---- scripts/setup-devcontainer.sh | 2 +- {qldebugger => src/qldebugger}/__init__.py | 0 {qldebugger => src/qldebugger}/__main__.py | 0 .../qldebugger}/actions/__init__.py | 0 .../actions/event_source_mapping.py | 0 .../qldebugger}/actions/infra.py | 0 .../qldebugger}/actions/lambda_.py | 0 .../qldebugger}/actions/message.py | 0 {qldebugger => src/qldebugger}/aws.py | 0 {qldebugger => src/qldebugger}/cli.py | 0 .../qldebugger}/config/__init__.py | 0 .../qldebugger}/config/file_parser.py | 0 .../qldebugger}/example/__init__.py | 0 .../qldebugger}/example/lambdas.py | 0 {qldebugger => src/qldebugger}/py.typed | 0 .../actions/test_event_source_mapping.py | 1 + tests/qldebugger/actions/test_infra.py | 2 +- tests/qldebugger/actions/test_lambda_.py | 2 +- tests/qldebugger/actions/test_message.py | 2 +- tests/qldebugger/config/test_file_parser.py | 2 +- tests/qldebugger/config/test_init.py | 2 +- tests/qldebugger/example/test_lambdas.py | 2 +- tests/qldebugger/test_aws.py | 2 +- 28 files changed, 35 insertions(+), 23 deletions(-) rename {qldebugger => src/qldebugger}/__init__.py (100%) rename {qldebugger => src/qldebugger}/__main__.py (100%) rename {qldebugger => src/qldebugger}/actions/__init__.py (100%) rename {qldebugger => src/qldebugger}/actions/event_source_mapping.py (100%) rename {qldebugger => src/qldebugger}/actions/infra.py (100%) rename {qldebugger => src/qldebugger}/actions/lambda_.py (100%) rename {qldebugger => src/qldebugger}/actions/message.py (100%) rename {qldebugger => src/qldebugger}/aws.py (100%) rename {qldebugger => src/qldebugger}/cli.py (100%) rename {qldebugger => src/qldebugger}/config/__init__.py (100%) rename {qldebugger => src/qldebugger}/config/file_parser.py (100%) rename {qldebugger => src/qldebugger}/example/__init__.py (100%) rename {qldebugger => src/qldebugger}/example/lambdas.py (100%) rename {qldebugger => src/qldebugger}/py.typed (100%) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 795dd7d..71ae885 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -30,9 +30,9 @@ "autopep8.importStrategy": "fromEnvironment", "ruff.importStrategy": "fromEnvironment", "mypy.runUsingActiveInterpreter": true, - "mypy.targets": ["qldebugger", "tests"], + "mypy.targets": ["src", "tests"], "python.testing.pytestEnabled": true, - "python.testing.pytestArgs": ["--no-cov", "tests"], + "python.testing.pytestArgs": ["-vv", "tests"], "[python]": { "editor.defaultFormatter": "ms-python.autopep8" } diff --git a/.gitignore b/.gitignore index aad0166..6cc52cd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,11 @@ # Python *.py[cod] __pycache__ -/poetry.lock -/dist # Development tools /.venv +/poetry.lock +/dist /.ruff_cache /.mypy_cache /.pytest_cache diff --git a/Makefile b/Makefile index e5ee980..fd5a18a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Project -srcdir = qldebugger +srcdir = src testsdir = tests @@ -12,6 +12,14 @@ build: poetry build +# Init + +.PHONY: init + +init: + poetry install --sync + + # Format .PHONY: fmt @@ -50,7 +58,7 @@ lint-mypy: test: test-pytest test-pytest: - poetry run pytest --numprocesses=auto $(testsdir) + poetry run pytest --cov=qldebugger --cov-report=term-missing --no-cov-on-fail $(testsdir) # Docs @@ -66,16 +74,18 @@ docs-serve: # Clean -.PHONY: clean clean-build clean-cache clean-docs clean-lock +.PHONY: clean clean-build clean-pycache clean-python-tools clean-docs clean-lock dist-clean -clean: clean-build clean-cache clean-docs +clean: clean-build clean-pycache clean-python-tools clean-docs clean-build: rm -rf dist -clean-cache: +clean-pycache: find $(srcdir) $(testsdir) -name '__pycache__' -exec rm -rf {} + find $(srcdir) $(testsdir) -type d -empty -delete + +clean-python-tools: rm -rf .ruff_cache .mypy_cache .pytest_cache .coverage .coverage.* clean-docs: @@ -84,6 +94,9 @@ clean-docs: clean-lock: rm -rf poetry.lock +dist-clean: clean clean-lock + rm -rf .venv qldebugger.toml + # Misc diff --git a/docs/debuggers/vscode.md b/docs/debuggers/vscode.md index 3d25069..d30c578 100644 --- a/docs/debuggers/vscode.md +++ b/docs/debuggers/vscode.md @@ -10,7 +10,7 @@ Exemplo de configuraĆ§Ć£o do arquivo `.vscode/launch.json`: "configurations": [ { "name": "Lambda myrun", - "type": "python", + "type": "debugpy", "request": "launch", "module": "qldebugger", "args": ["run", "myrun"], diff --git a/pyproject.toml b/pyproject.toml index 8fa6a0f..41a229d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["poetry-core>=1.0.0"] +requires = ["poetry-core>=1,<2"] build-backend = "poetry.core.masonry.api" [tool.poetry] @@ -40,7 +40,6 @@ ruff = "^0.1" mypy = "^1.3" pytest = "^7.3" pytest-cov = "^4.1" -pytest-xdist = "^3.3" moto = {version = "^4.1", extras = ["server"]} [tool.poetry.group.docs] @@ -62,7 +61,7 @@ select = ["ALL"] ignore = ["D", "ANN101", "ANN102", "ANN401", "FBT", "EM", "FA100", "ARG", "PLR0913", "TRY003", "PERF203"] [tool.ruff.per-file-ignores] -"qldebugger/example/*.py" = ["T20"] +"src/qldebugger/example/*.py" = ["T20"] "tests/*.py" = ["S101", "S311", "PLR2004"] [tool.ruff.pep8-naming] @@ -80,10 +79,9 @@ show_error_codes = true sqlite_cache = true strict = true plugins = ["pydantic.mypy"] -files = ["qldebugger/**/*.py", "tests/**/*.py"] +files = ["src/**/*.py", "tests/**/*.py"] [tool.pytest.ini_options] -addopts = "--strict-config --cov-report=term-missing --no-cov-on-fail --cov=qldebugger" testpaths = ["tests"] [tool.coverage.run] diff --git a/scripts/setup-devcontainer.sh b/scripts/setup-devcontainer.sh index cf189f6..56ff999 100755 --- a/scripts/setup-devcontainer.sh +++ b/scripts/setup-devcontainer.sh @@ -13,4 +13,4 @@ echo 'eval "$(register-python-argcomplete pipx)"' > ~/.local/share/bash-completi echo 'eval "$(poetry completions bash)"' > ~/.local/share/bash-completion/completions/poetry # Init project -poetry install --with=docs +make init diff --git a/qldebugger/__init__.py b/src/qldebugger/__init__.py similarity index 100% rename from qldebugger/__init__.py rename to src/qldebugger/__init__.py diff --git a/qldebugger/__main__.py b/src/qldebugger/__main__.py similarity index 100% rename from qldebugger/__main__.py rename to src/qldebugger/__main__.py diff --git a/qldebugger/actions/__init__.py b/src/qldebugger/actions/__init__.py similarity index 100% rename from qldebugger/actions/__init__.py rename to src/qldebugger/actions/__init__.py diff --git a/qldebugger/actions/event_source_mapping.py b/src/qldebugger/actions/event_source_mapping.py similarity index 100% rename from qldebugger/actions/event_source_mapping.py rename to src/qldebugger/actions/event_source_mapping.py diff --git a/qldebugger/actions/infra.py b/src/qldebugger/actions/infra.py similarity index 100% rename from qldebugger/actions/infra.py rename to src/qldebugger/actions/infra.py diff --git a/qldebugger/actions/lambda_.py b/src/qldebugger/actions/lambda_.py similarity index 100% rename from qldebugger/actions/lambda_.py rename to src/qldebugger/actions/lambda_.py diff --git a/qldebugger/actions/message.py b/src/qldebugger/actions/message.py similarity index 100% rename from qldebugger/actions/message.py rename to src/qldebugger/actions/message.py diff --git a/qldebugger/aws.py b/src/qldebugger/aws.py similarity index 100% rename from qldebugger/aws.py rename to src/qldebugger/aws.py diff --git a/qldebugger/cli.py b/src/qldebugger/cli.py similarity index 100% rename from qldebugger/cli.py rename to src/qldebugger/cli.py diff --git a/qldebugger/config/__init__.py b/src/qldebugger/config/__init__.py similarity index 100% rename from qldebugger/config/__init__.py rename to src/qldebugger/config/__init__.py diff --git a/qldebugger/config/file_parser.py b/src/qldebugger/config/file_parser.py similarity index 100% rename from qldebugger/config/file_parser.py rename to src/qldebugger/config/file_parser.py diff --git a/qldebugger/example/__init__.py b/src/qldebugger/example/__init__.py similarity index 100% rename from qldebugger/example/__init__.py rename to src/qldebugger/example/__init__.py diff --git a/qldebugger/example/lambdas.py b/src/qldebugger/example/lambdas.py similarity index 100% rename from qldebugger/example/lambdas.py rename to src/qldebugger/example/lambdas.py diff --git a/qldebugger/py.typed b/src/qldebugger/py.typed similarity index 100% rename from qldebugger/py.typed rename to src/qldebugger/py.typed diff --git a/tests/qldebugger/actions/test_event_source_mapping.py b/tests/qldebugger/actions/test_event_source_mapping.py index 57fa5d8..536e01f 100644 --- a/tests/qldebugger/actions/test_event_source_mapping.py +++ b/tests/qldebugger/actions/test_event_source_mapping.py @@ -4,6 +4,7 @@ from qldebugger.actions.event_source_mapping import convert_sqs_messages_to_event, receive_messages_and_run_lambda from qldebugger.config.file_parser import ConfigEventSourceMapping + from tests.utils import randstr if TYPE_CHECKING: diff --git a/tests/qldebugger/actions/test_infra.py b/tests/qldebugger/actions/test_infra.py index 672d761..4263c9a 100644 --- a/tests/qldebugger/actions/test_infra.py +++ b/tests/qldebugger/actions/test_infra.py @@ -2,7 +2,6 @@ from unittest.mock import Mock, patch from botocore.exceptions import ClientError - from qldebugger.actions.infra import create_queues, create_secrets, create_topics, subscribe_topics from qldebugger.config.file_parser import ( ConfigQueue, @@ -11,6 +10,7 @@ ConfigTopic, ConfigTopicSubscriber, ) + from tests.utils import randstr diff --git a/tests/qldebugger/actions/test_lambda_.py b/tests/qldebugger/actions/test_lambda_.py index 7091256..3b39e70 100644 --- a/tests/qldebugger/actions/test_lambda_.py +++ b/tests/qldebugger/actions/test_lambda_.py @@ -3,9 +3,9 @@ from unittest.mock import Mock, patch import pytest - from qldebugger.actions.lambda_ import get_lambda_function, run_lambda from qldebugger.config.file_parser import ConfigLambda + from tests.utils import randstr if TYPE_CHECKING: diff --git a/tests/qldebugger/actions/test_message.py b/tests/qldebugger/actions/test_message.py index f41e2f9..7e289e2 100644 --- a/tests/qldebugger/actions/test_message.py +++ b/tests/qldebugger/actions/test_message.py @@ -3,8 +3,8 @@ from unittest.mock import Mock, patch import pytest - from qldebugger.actions.message import delete_messages, publish_message, receive_message, send_message + from tests.utils import randstr if TYPE_CHECKING: diff --git a/tests/qldebugger/config/test_file_parser.py b/tests/qldebugger/config/test_file_parser.py index 1725aa0..0c4218c 100644 --- a/tests/qldebugger/config/test_file_parser.py +++ b/tests/qldebugger/config/test_file_parser.py @@ -5,7 +5,6 @@ import pytest from pydantic import ValidationError - from qldebugger.config.file_parser import ( Config, ConfigAWS, @@ -18,6 +17,7 @@ ConfigTopicSubscriber, NameHandlerTuple, ) + from tests.utils import randstr diff --git a/tests/qldebugger/config/test_init.py b/tests/qldebugger/config/test_init.py index bc7f723..52bfa71 100644 --- a/tests/qldebugger/config/test_init.py +++ b/tests/qldebugger/config/test_init.py @@ -1,8 +1,8 @@ from unittest.mock import Mock, patch import pytest - from qldebugger.config import get_config, load_config + from tests.utils import randstr diff --git a/tests/qldebugger/example/test_lambdas.py b/tests/qldebugger/example/test_lambdas.py index 56503d2..6429c19 100644 --- a/tests/qldebugger/example/test_lambdas.py +++ b/tests/qldebugger/example/test_lambdas.py @@ -3,8 +3,8 @@ from unittest.mock import Mock, patch import pytest - from qldebugger.example.lambdas import LambdaCustomError, exec_fail, print_messages + from tests.utils import randstr diff --git a/tests/qldebugger/test_aws.py b/tests/qldebugger/test_aws.py index 2ab6dd9..fcd3cb0 100644 --- a/tests/qldebugger/test_aws.py +++ b/tests/qldebugger/test_aws.py @@ -2,9 +2,9 @@ from unittest.mock import Mock, patch import pytest - from qldebugger.aws import get_account_id, get_client, inject_aws_config_in_client from qldebugger.config.file_parser import ConfigAWS + from tests.utils import randstr From 621680b07e22e7a60fea055cb32783a3d37d0d2c Mon Sep 17 00:00:00 2001 From: Eduardo Klosowski Date: Wed, 4 Sep 2024 00:56:08 -0300 Subject: [PATCH 4/6] Refactor dev tools --- .devcontainer/devcontainer.json | 4 +- Makefile | 19 ++++----- pyproject.toml | 40 +++++++++---------- setup.cfg | 2 - src/qldebugger/actions/lambda_.py | 3 +- src/qldebugger/actions/message.py | 3 +- src/qldebugger/cli.py | 12 +++--- src/qldebugger/config/file_parser.py | 6 +-- .../actions/test_event_source_mapping.py | 1 - tests/qldebugger/actions/test_infra.py | 23 +++++------ tests/qldebugger/actions/test_lambda_.py | 12 ++++-- tests/qldebugger/actions/test_message.py | 8 ++-- tests/qldebugger/config/test_file_parser.py | 2 +- tests/qldebugger/config/test_init.py | 2 +- tests/qldebugger/example/test_lambdas.py | 2 +- tests/qldebugger/test_aws.py | 2 +- 16 files changed, 66 insertions(+), 75 deletions(-) delete mode 100644 setup.cfg diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 71ae885..750d0dd 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -21,20 +21,18 @@ "extensions": [ "editorconfig.editorconfig", "tamasfe.even-better-toml", - "ms-python.autopep8", "charliermarsh.ruff", "matangover.mypy" ], "settings": { "python.defaultInterpreterPath": "./.venv/bin/python", - "autopep8.importStrategy": "fromEnvironment", "ruff.importStrategy": "fromEnvironment", "mypy.runUsingActiveInterpreter": true, "mypy.targets": ["src", "tests"], "python.testing.pytestEnabled": true, "python.testing.pytestArgs": ["-vv", "tests"], "[python]": { - "editor.defaultFormatter": "ms-python.autopep8" + "editor.defaultFormatter": "charliermarsh.ruff" } } } diff --git a/Makefile b/Makefile index fd5a18a..2358a73 100644 --- a/Makefile +++ b/Makefile @@ -25,27 +25,24 @@ init: .PHONY: fmt fmt: - poetry run autopep8 --recursive --in-place $(srcdir) $(testsdir) - poetry run ruff --fix $(srcdir) $(testsdir) + poetry run ruff check --select I001 --fix $(srcdir) $(testsdir) + poetry run ruff format $(srcdir) $(testsdir) # Lint -.PHONY: lint lint-poetry lint-pycodestyle lint-autopep8 lint-ruff lint-mypy +.PHONY: lint lint-poetry lint-ruff-format lint-ruff-check lint-mypy -lint: lint-poetry lint-pycodestyle lint-autopep8 lint-ruff lint-mypy +lint: lint-poetry lint-ruff-format lint-ruff-check lint-mypy lint-poetry: poetry check -lint-pycodestyle: - poetry run pycodestyle --show-source $(srcdir) $(testsdir) +lint-ruff-format: + poetry run ruff format --diff $(srcdir) $(testsdir) -lint-autopep8: - poetry run autopep8 --diff --exit-code --recursive $(srcdir) $(testsdir) - -lint-ruff: - poetry run ruff check --show-source $(srcdir) $(testsdir) +lint-ruff-check: + poetry run ruff check $(srcdir) $(testsdir) lint-mypy: poetry run mypy --show-error-context --pretty $(srcdir) $(testsdir) diff --git a/pyproject.toml b/pyproject.toml index 41a229d..e25f548 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,13 +34,11 @@ aws-lambda-typing = "^2.17" boto3-stubs = {version = "^1.26", extras = ["secretsmanager", "sns", "sqs", "sts"]} [tool.poetry.group.dev.dependencies] -pycodestyle = "^2.10" -autopep8 = "^2.0" -ruff = "^0.1" -mypy = "^1.3" -pytest = "^7.3" -pytest-cov = "^4.1" -moto = {version = "^4.1", extras = ["server"]} +ruff = "^0.6" +mypy = "^1.11" +pytest = "^8.3" +pytest-cov = "^5.0" +moto = {version = "^5.0", extras = ["server", "secretsmanager", "sns", "sqs", "sts"]} [tool.poetry.group.docs] optional = true @@ -51,28 +49,30 @@ mkdocs = "^1.4" [tool.poetry.scripts] qldebugger = "qldebugger.cli:cli" -[tool.autopep8] -aggressive = 3 - [tool.ruff] target-version = "py38" line-length = 119 -select = ["ALL"] -ignore = ["D", "ANN101", "ANN102", "ANN401", "FBT", "EM", "FA100", "ARG", "PLR0913", "TRY003", "PERF203"] +src = ["src", "tests"] -[tool.ruff.per-file-ignores] -"src/qldebugger/example/*.py" = ["T20"] -"tests/*.py" = ["S101", "S311", "PLR2004"] +[tool.ruff.format] +line-ending = "lf" +quote-style = "single" -[tool.ruff.pep8-naming] -classmethod-decorators = ["pydantic.validator"] +[tool.ruff.lint] +select = ["ALL"] +ignore = ["D", "UP037", "ANN401", "FBT", "COM812", "EM", "FA100", "ISC001", "PLR0913", "TRY003", "PERF203"] -[tool.ruff.flake8-quotes] +[tool.ruff.lint.per-file-ignores] +"src/qldebugger/example/*.py" = ["T20", "ARG001"] +"tests/*.py" = ["S101", "S311", "ARG", "PLR2004"] + +[tool.ruff.lint.flake8-quotes] inline-quotes = "single" -multiline-quotes = "single" + +[tool.ruff.lint.pep8-naming] +classmethod-decorators = ["pydantic.validator"] [tool.mypy] -follow_imports = "normal" warn_unused_configs = true show_column_numbers = true show_error_codes = true diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 4c4cc59..0000000 --- a/setup.cfg +++ /dev/null @@ -1,2 +0,0 @@ -[pycodestyle] -max-line-length = 119 diff --git a/src/qldebugger/actions/lambda_.py b/src/qldebugger/actions/lambda_.py index f5165ca..88c25d3 100644 --- a/src/qldebugger/actions/lambda_.py +++ b/src/qldebugger/actions/lambda_.py @@ -16,8 +16,7 @@ def get_lambda_function(*, lambda_name: str) -> Callable[['SQSEvent', None], Any]: module_name, function_name = get_config().lambdas[lambda_name].handler logger.debug('Importing lambda_handler of %r...', lambda_name) - lambda_handler: Callable[['SQSEvent', None], Any] = \ - getattr(import_module(module_name), function_name) + lambda_handler: Callable[['SQSEvent', None], Any] = getattr(import_module(module_name), function_name) return lambda_handler diff --git a/src/qldebugger/actions/message.py b/src/qldebugger/actions/message.py index d604d51..1221b01 100644 --- a/src/qldebugger/actions/message.py +++ b/src/qldebugger/actions/message.py @@ -65,7 +65,8 @@ def delete_messages(*, queue_name: str, messages: 'ReceiveMessageResultTypeDef') { 'Id': message['MessageId'], 'ReceiptHandle': message['ReceiptHandle'], - } for message in messages['Messages'] + } + for message in messages['Messages'] ], ) logger.info('Deleted %d messages from %r queue', len(messages['Messages']), queue_name) diff --git a/src/qldebugger/cli.py b/src/qldebugger/cli.py index 9432082..5da6618 100644 --- a/src/qldebugger/cli.py +++ b/src/qldebugger/cli.py @@ -21,7 +21,7 @@ def cli() -> None: @cli.command() def init() -> None: - config = '''[aws] + config = """[aws] profile = "" access_key_id = "secret" secret_access_key = "secret" @@ -42,7 +42,7 @@ def init() -> None: [event_source_mapping] a = {queue = "myqueue", function_name = "print"} b = {queue = "myqueue", function_name = "fail", batch_size = 1, maximum_batching_window = 20} -''' +""" if CONFIG_FILENAME.exists(): click.echo('Configuration file already exists') return @@ -60,9 +60,9 @@ def run(event_source_mapping_name: str) -> None: # Infra + @cli.group() -def infra() -> None: - ... +def infra() -> None: ... @infra.command('create-secrets') @@ -100,9 +100,9 @@ def infra_subscribe_topics() -> None: # Msg + @cli.group() -def msg() -> None: - ... +def msg() -> None: ... @msg.command('publish') diff --git a/src/qldebugger/config/file_parser.py b/src/qldebugger/config/file_parser.py index 97a0538..f21d47b 100644 --- a/src/qldebugger/config/file_parser.py +++ b/src/qldebugger/config/file_parser.py @@ -16,8 +16,7 @@ class ConfigAWS(BaseModel): class ConfigSecret(BaseModel, ABC): @abstractmethod - def get_value(self) -> Union[str, bytes]: - ... + def get_value(self) -> Union[str, bytes]: ... class ConfigSecretString(ConfigSecret): @@ -44,8 +43,7 @@ class ConfigTopic(BaseModel): subscribers: List[ConfigTopicSubscriber] = Field(default_factory=list) -class ConfigQueue(BaseModel): - ... +class ConfigQueue(BaseModel): ... class NameHandlerTuple(NamedTuple): diff --git a/tests/qldebugger/actions/test_event_source_mapping.py b/tests/qldebugger/actions/test_event_source_mapping.py index 536e01f..57fa5d8 100644 --- a/tests/qldebugger/actions/test_event_source_mapping.py +++ b/tests/qldebugger/actions/test_event_source_mapping.py @@ -4,7 +4,6 @@ from qldebugger.actions.event_source_mapping import convert_sqs_messages_to_event, receive_messages_and_run_lambda from qldebugger.config.file_parser import ConfigEventSourceMapping - from tests.utils import randstr if TYPE_CHECKING: diff --git a/tests/qldebugger/actions/test_infra.py b/tests/qldebugger/actions/test_infra.py index 4263c9a..1e64e0a 100644 --- a/tests/qldebugger/actions/test_infra.py +++ b/tests/qldebugger/actions/test_infra.py @@ -2,6 +2,7 @@ from unittest.mock import Mock, patch from botocore.exceptions import ClientError + from qldebugger.actions.infra import create_queues, create_secrets, create_topics, subscribe_topics from qldebugger.config.file_parser import ( ConfigQueue, @@ -10,7 +11,6 @@ ConfigTopic, ConfigTopicSubscriber, ) - from tests.utils import randstr @@ -21,8 +21,7 @@ def test_create_string_secrets(self, mock_get_config: Mock, mock_get_client: Moc secrets = {randstr(): randstr() for _ in range(randint(2, 5))} mock_get_config.return_value.secrets = { - name: ConfigSecretString(string=value) - for name, value in secrets.items() + name: ConfigSecretString(string=value) for name, value in secrets.items() } mock_get_client.return_value.describe_secret.side_effect = ClientError({}, '') @@ -40,8 +39,7 @@ def test_create_binary_secrets(self, mock_get_config: Mock, mock_get_client: Moc secrets = {randstr(): randstr().encode() for _ in range(randint(2, 5))} mock_get_config.return_value.secrets = { - name: ConfigSecretBinary(binary=value) - for name, value in secrets.items() + name: ConfigSecretBinary(binary=value) for name, value in secrets.items() } mock_get_client.return_value.describe_secret.side_effect = ClientError({}, '') @@ -59,8 +57,7 @@ def test_update_string_secrets(self, mock_get_config: Mock, mock_get_client: Moc secrets = {randstr(): randstr() for _ in range(randint(2, 5))} mock_get_config.return_value.secrets = { - name: ConfigSecretString(string=value) - for name, value in secrets.items() + name: ConfigSecretString(string=value) for name, value in secrets.items() } create_secrets() @@ -77,8 +74,7 @@ def test_update_binary_secrets(self, mock_get_config: Mock, mock_get_client: Moc secrets = {randstr(): randstr().encode() for _ in range(randint(2, 5))} mock_get_config.return_value.secrets = { - name: ConfigSecretBinary(binary=value) - for name, value in secrets.items() + name: ConfigSecretBinary(binary=value) for name, value in secrets.items() } create_secrets() @@ -283,10 +279,11 @@ def test_remove_old_subscribers( ) -> None: subscriptions = [randstr() for _ in range(randint(2, 5))] - mock_get_client.return_value.list_subscriptions.return_value = {'Subscriptions': [ - {'SubscriptionArn': subscription, 'Endpoint': randstr()} - for subscription in subscriptions - ]} + mock_get_client.return_value.list_subscriptions.return_value = { + 'Subscriptions': [ + {'SubscriptionArn': subscription, 'Endpoint': randstr()} for subscription in subscriptions + ] + } subscribe_topics() diff --git a/tests/qldebugger/actions/test_lambda_.py b/tests/qldebugger/actions/test_lambda_.py index 3b39e70..29f4bbc 100644 --- a/tests/qldebugger/actions/test_lambda_.py +++ b/tests/qldebugger/actions/test_lambda_.py @@ -3,9 +3,9 @@ from unittest.mock import Mock, patch import pytest + from qldebugger.actions.lambda_ import get_lambda_function, run_lambda from qldebugger.config.file_parser import ConfigLambda - from tests.utils import randstr if TYPE_CHECKING: @@ -21,9 +21,11 @@ def test_run(self, mock_import_module: Mock, mock_get_config: Mock) -> None: module_name = randstr() function_name = randstr() - mock_get_config.return_value.lambdas = {lambda_name: ConfigLambda( - handler=f'{module_name}.{function_name}', - )} + mock_get_config.return_value.lambdas = { + lambda_name: ConfigLambda( + handler=f'{module_name}.{function_name}', + ) + } returned = get_lambda_function(lambda_name=lambda_name) @@ -78,6 +80,7 @@ def test_with_environment_variables( def lambda_function(event: 'ReceiveMessageResultTypeDef', context: None) -> None: import os + for k, v in environment.items(): assert os.environ[k] == v @@ -104,6 +107,7 @@ def test_with_aws_configuration_injection( def lambda_function(event: 'ReceiveMessageResultTypeDef', context: None) -> None: import boto3 + boto3.client( # type: ignore[call-overload] service_name=service_name, aws_access_key_id=aws_access_key_id, diff --git a/tests/qldebugger/actions/test_message.py b/tests/qldebugger/actions/test_message.py index 7e289e2..367c4ce 100644 --- a/tests/qldebugger/actions/test_message.py +++ b/tests/qldebugger/actions/test_message.py @@ -3,8 +3,8 @@ from unittest.mock import Mock, patch import pytest -from qldebugger.actions.message import delete_messages, publish_message, receive_message, send_message +from qldebugger.actions.message import delete_messages, publish_message, receive_message, send_message from tests.utils import randstr if TYPE_CHECKING: @@ -135,8 +135,7 @@ def test_run(self, mock_get_client: Mock) -> None: queue_url = randstr() messages: 'ReceiveMessageResultTypeDef' = { 'Messages': [ - {'MessageId': randstr(), 'ReceiptHandle': randstr(), 'Body': randstr()} - for _ in range(randint(1, 10)) + {'MessageId': randstr(), 'ReceiptHandle': randstr(), 'Body': randstr()} for _ in range(randint(1, 10)) ], 'ResponseMetadata': cast(Any, None), } @@ -153,6 +152,7 @@ def test_run(self, mock_get_client: Mock) -> None: { 'Id': message['MessageId'], 'ReceiptHandle': message['ReceiptHandle'], - } for message in messages['Messages'] + } + for message in messages['Messages'] ], ) diff --git a/tests/qldebugger/config/test_file_parser.py b/tests/qldebugger/config/test_file_parser.py index 0c4218c..1725aa0 100644 --- a/tests/qldebugger/config/test_file_parser.py +++ b/tests/qldebugger/config/test_file_parser.py @@ -5,6 +5,7 @@ import pytest from pydantic import ValidationError + from qldebugger.config.file_parser import ( Config, ConfigAWS, @@ -17,7 +18,6 @@ ConfigTopicSubscriber, NameHandlerTuple, ) - from tests.utils import randstr diff --git a/tests/qldebugger/config/test_init.py b/tests/qldebugger/config/test_init.py index 52bfa71..bc7f723 100644 --- a/tests/qldebugger/config/test_init.py +++ b/tests/qldebugger/config/test_init.py @@ -1,8 +1,8 @@ from unittest.mock import Mock, patch import pytest -from qldebugger.config import get_config, load_config +from qldebugger.config import get_config, load_config from tests.utils import randstr diff --git a/tests/qldebugger/example/test_lambdas.py b/tests/qldebugger/example/test_lambdas.py index 6429c19..56503d2 100644 --- a/tests/qldebugger/example/test_lambdas.py +++ b/tests/qldebugger/example/test_lambdas.py @@ -3,8 +3,8 @@ from unittest.mock import Mock, patch import pytest -from qldebugger.example.lambdas import LambdaCustomError, exec_fail, print_messages +from qldebugger.example.lambdas import LambdaCustomError, exec_fail, print_messages from tests.utils import randstr diff --git a/tests/qldebugger/test_aws.py b/tests/qldebugger/test_aws.py index fcd3cb0..2ab6dd9 100644 --- a/tests/qldebugger/test_aws.py +++ b/tests/qldebugger/test_aws.py @@ -2,9 +2,9 @@ from unittest.mock import Mock, patch import pytest + from qldebugger.aws import get_account_id, get_client, inject_aws_config_in_client from qldebugger.config.file_parser import ConfigAWS - from tests.utils import randstr From c384dc5c9f8ce5c340673dddf2c9cd6e5414a4c1 Mon Sep 17 00:00:00 2001 From: Eduardo Klosowski Date: Wed, 4 Sep 2024 21:21:07 -0300 Subject: [PATCH 5/6] Refactor read the docs --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 5fe3497..562ff94 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -6,7 +6,7 @@ build: python: "3.8" jobs: post_create_environment: - - curl -sSL https://install.python-poetry.org | python3 - + - curl -sSL https://install.python-poetry.org | python3 - --version 1.8.3 - $HOME/.local/bin/poetry config virtualenvs.create false pre_install: - $HOME/.local/bin/poetry export --only=docs -o requirements.txt From f94f0191f601d71aa19ee8e2d23fc4537cb2f584 Mon Sep 17 00:00:00 2001 From: Eduardo Klosowski Date: Wed, 4 Sep 2024 01:09:53 -0300 Subject: [PATCH 6/6] Update github actions --- .github/workflows/check-commit.yml | 44 ++++++++++++++---------------- .github/workflows/release.yml | 18 ++++++------ 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/.github/workflows/check-commit.yml b/.github/workflows/check-commit.yml index ae3121b..f2a1655 100644 --- a/.github/workflows/check-commit.yml +++ b/.github/workflows/check-commit.yml @@ -1,37 +1,33 @@ name: Check Commit on: + workflow_dispatch: push: - branches: - - "*" - tags: - - "*" pull_request: - types: [opened, synchronize, reopened] permissions: contents: read jobs: lint: - name: Lint - runs-on: ubuntu-latest + name: Check Lints + runs-on: ubuntu-22.04 strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup poetry - run: pipx install poetry + run: pipx install poetry==1.8.3 - name: Generate datefile run: echo "lint-$(date +%U)" > datefile - name: Setup python id: setup-python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} cache: poetry @@ -41,30 +37,30 @@ jobs: - name: Install dependencies if: steps.setup-python.outputs.cache-hit != 'true' - run: poetry install --only=main,type,dev + run: poetry install --sync --only=main,type,dev - name: Run lints run: make lint test: - name: Test - runs-on: ubuntu-latest + name: Check Test + runs-on: ubuntu-22.04 strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup poetry - run: pipx install poetry + run: pipx install poetry==1.8.3 - name: Generate datefile run: echo "test-$(date +%U)" > datefile - name: Setup python id: setup-python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} cache: poetry @@ -74,27 +70,27 @@ jobs: - name: Install dependencies if: steps.setup-python.outputs.cache-hit != 'true' - run: poetry install --only=main,dev + run: poetry install --sync --only=main,dev - name: Run tests run: make test docs: - name: Docs + name: Check Docs runs-on: ubuntu-22.04 steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup poetry - run: pipx install poetry + run: pipx install poetry==1.8.3 - name: Generate datefile run: echo "docs-$(date +%U)" > datefile - name: Setup python id: setup-python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.8" cache: poetry @@ -104,7 +100,7 @@ jobs: - name: Install dependencies if: steps.setup-python.outputs.cache-hit != 'true' - run: poetry install --only=docs + run: poetry install --sync --only=docs - name: Check build run: make docs-build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f246232..6ec59f6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,14 +11,14 @@ permissions: jobs: build-package: name: Build Package - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup python id: setup-python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.8" @@ -29,7 +29,7 @@ jobs: run: python -m build - name: Upload artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: packages path: dist @@ -38,18 +38,18 @@ jobs: github-release: name: Release on GitHub needs: build-package - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 permissions: contents: write steps: - name: Download artifacts - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: packages path: dist - name: Make release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: files: | dist/*.tar.gz @@ -59,7 +59,7 @@ jobs: pypi-publish: name: Publish on PyPI needs: github-release - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 environment: name: pypi url: https://pypi.org/p/qldebugger @@ -67,7 +67,7 @@ jobs: id-token: write steps: - name: Download artifacts - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: packages path: dist