From dc4839ebe3ad02bdad025b898fd0d4e7bc1d3974 Mon Sep 17 00:00:00 2001 From: Lennard Wolf <7870758+MultifokalHirn@users.noreply.github.com> Date: Thu, 7 Dec 2023 18:20:49 +0100 Subject: [PATCH] use pdm scripts --- .github/workflows/python-checks.yaml | 2 +- .pre-commit-config.yaml | 98 +++++++++++++--------------- Makefile | 53 ++++++--------- pyproject.toml | 25 +++++-- 4 files changed, 84 insertions(+), 94 deletions(-) diff --git a/.github/workflows/python-checks.yaml b/.github/workflows/python-checks.yaml index 8feb8ec..93701b7 100644 --- a/.github/workflows/python-checks.yaml +++ b/.github/workflows/python-checks.yaml @@ -27,7 +27,7 @@ jobs: max-parallel: 1 fail-fast: true matrix: - python-version: [3.8, 3.11, 3.12] + python-version: [3.9, 3.11, 3.12] steps: - uses: actions/checkout@v4 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 42a4fb9..9da8831 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,29 +13,19 @@ repos: - id: destroyed-symlinks # - id: check-json - id: detect-private-key - # - repo: https://github.com/pycqa/isort - # rev: "5.12.0" - # hooks: - # - id: isort - # name: isort (python) - # additional_dependencies: [toml] - # - repo: https://github.com/hhatto/autopep8 - # rev: "v2.0.4" - # hooks: - # - id: autopep8 - # - repo: https://github.com/PyCQA/flake8 - # rev: "6.1.0" - # hooks: - # - id: flake8 - repo: https://github.com/astral-sh/ruff-pre-commit - # Ruff version. rev: v0.1.7 hooks: - # Run the linter. - id: ruff - args: [--fix, --config=./pyproject.toml] - # Run the formatter. + args: [--config=./pyproject.toml] - id: ruff-format + args: + [ + --fix, + --exit-non-zero-on-fix, + --show-fixes, + --config=./pyproject.toml, + ] - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.7.1 hooks: @@ -44,16 +34,47 @@ repos: # ignore-missing-imports: true # disallow_any_unimported: false args: [--config-file=./pyproject.toml] - - repo: https://github.com/IamTheFij/docker-pre-commit - rev: v3.0.1 + - repo: https://github.com/codespell-project/codespell + rev: v2.2.6 + hooks: + - id: codespell + additional_dependencies: + - tomli + # - repo: https://github.com/guilatrova/tryceratops # requires python>=3.8 + # rev: v2.3.2 + # hooks: + # - id: tryceratops + - repo: https://github.com/asottile/pyupgrade + rev: v3.15.0 hooks: - - id: docker-compose-check - files: docker-compose.*.y[a]{0,1}ml$ + - id: pyupgrade + args: [--py39-plus] + # - repo: https://github.com/jendrikseipp/vulture + # rev: v2.3 + # hooks: + # - id: vulture + # - repo: https://github.com/dosisod/refurb # requires python>=3.10 + # rev: "v1.25.0" + # hooks: + # - id: refurb + - repo: https://codeberg.org/frnmst/md-toc + rev: "8.2.2" # or a specific git tag from md-toc + hooks: + - id: md-toc + args: [-p, "cmark", "-l6"] # CLI options + # - repo: https://github.com/mgedmin/check-manifest + # rev: "0.49" + # hooks: + # - id: check-manifest + # - repo: https://github.com/IamTheFij/docker-pre-commit + # rev: v3.0.1 + # hooks: + # - id: docker-compose-check + # files: docker-compose.*.y[a]{0,1}ml$ - repo: https://github.com/abravalheri/validate-pyproject rev: v0.15 hooks: - id: validate-pyproject - # export python requirements - repo: https://github.com/pdm-project/pdm rev: 2.10.4 hooks: @@ -68,39 +89,8 @@ repos: - id: pdm-export args: ["-o", "requirements-dev.txt", "--without-hashes", "--dev"] files: ^pdm.lock$ - - repo: https://github.com/codespell-project/codespell - rev: v2.2.6 - hooks: - - id: codespell - additional_dependencies: - - tomli - repo: https://github.com/commitizen-tools/commitizen rev: v3.13.0 hooks: - id: commitizen stages: [commit-msg] - - repo: https://github.com/guilatrova/tryceratops # requires python>=3.8 - rev: v2.3.2 - hooks: - - id: tryceratops - - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 - hooks: - - id: pyupgrade - # - repo: https://github.com/jendrikseipp/vulture - # rev: v2.3 - # hooks: - # - id: vulture - - repo: https://github.com/dosisod/refurb # requires python>=3.10 - rev: "v1.25.0" - hooks: - - id: refurb - - repo: https://codeberg.org/frnmst/md-toc - rev: "8.2.2" # or a specific git tag from md-toc - hooks: - - id: md-toc - args: [-p, "cmark", "-l6"] # CLI options - # - repo: https://github.com/mgedmin/check-manifest - # rev: "0.49" - # hooks: - # - id: check-manifest diff --git a/Makefile b/Makefile index 2901243..3b89425 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,6 @@ MAKEFLAGS += --no-builtin-rules # ENVIRONMENT_VARIABLE_FILE := .env -# all: venv - python-version: ## Show the python version # Show the python version @python --version @@ -24,24 +22,26 @@ bootstrap: python-version clean-venv venv ## fresh install of venv and dependenc prod: ## install prod dependencies # install prod dependencies - $(VENV)/pdm sync --fail-fast --prod -.PHONY: dev + $(VENV)/pdm install +.PHONY: prod dev: ## install all dependencies in lock file # install all dependencies in lock file - $(VENV)/pdm sync + $(VENV)/pdm install -G :all .PHONY: dev -ci: lint mypy test ## Run all checks (test, lint, typecheck) +ci: ## Runs ci +ci: + pdm run ci .PHONY: ci -app: ## Run the app service - $(VENV)/python -m app -.PHONY: app +# app: ## Run the app service +# $(VENV)/python -m app +# .PHONY: app update: venv ## update lock file if needed $(VENV)/pdm self update - $(VENV)/pdm lock + $(VENV)/pdm run lock .PHONY: update ## to add additional services, they should follow the same pattern as the example api service: @@ -49,31 +49,22 @@ update: venv ## update lock file if needed # $(VENV)/python -m api # .PHONY: api -run: app ## Run the application -.PHONY: run +# run: app ## Run the application +# .PHONY: run + -# lint-fix: venv ## Run autopep8 and isort -# lint-fix: -# # Run auto-formatters... -# $(VENV)/autopep8 **/*.py --in-place --recursive --aggressive --aggressive -# $(VENV)/isort **/*.py -# .PHONY: lint-fix -lint: ## Runs lint on src, exit if critical rules are broken +lint: ## Runs lint on src lint: - $(VENV)/ruff check src/ tests/ --config=./pyproject.toml + pdm run lint .PHONY: lint +format: ## Runs formatter on python files +format: + pdm run format +.PHONY: format -flake8: ## Runs flake8 on src, exit if critical rules are broken -flake8: - # Run flake8... - $(VENV)/flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --max-line-length=127 - $(VENV)/flake8 . --count --exit-zero --statistics -.PHONY: flake8 - -mypy: venv ## Runs mypy on src, exit if critical rules are broken +mypy: ## Runs mypy on src, exit if critical rules are broken mypy: - # Run type checks... pdm run mypy .PHONY: mypy @@ -84,10 +75,6 @@ test: pdm run test .PHONY: test -# clean: -# rm -rf __pycache__ -# .PHONY: clean - .DEFAULT_GOAL := help define find.functions diff --git a/pyproject.toml b/pyproject.toml index b3469eb..321a3b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -101,6 +101,8 @@ python_version = "3.11" show_error_codes = true strict = true warn_redundant_casts = true +warn_unused_ignores = false + [tool.coverage.run] branch = true @@ -204,18 +206,29 @@ source-includes = ["tests", "CHANGELOG.md", "LICENSE", "README.md"] [tool.pytest.ini_options] filterwarnings = ["ignore::DeprecationWarning"] +[project.scripts] +cli = "python_template_repo.cli:main" [tool.pdm.scripts] _.env_file = ".env" -format = {cmd = "ruff --config-file=./pyproject.toml --fix src/ tests/"} -lint = {cmd = "ruff check --config-file=./pyproject.toml src/ tests/"} +format = {shell = "echo 'formatting...' && .venv/bin/ruff --config=./pyproject.toml --fix src/ tests/"} +lint = {shell = "echo 'linting...' && .venv/bin/ruff check --config=./pyproject.toml src/ tests/"} lock = {shell = """\ - pdm lock -G :all \ - source .venv/bin/activate \ + pdm lock -G :all\ + && source .venv/bin/activate \ && pdm sync\ """} -mypy = {cmd = "mypy --config-file=./pyproject.toml src/"} -test = {cmd = "pytest tests/ -p no:logging -p no:warnings"} +mypy = {shell = "echo 'running typechecks...' && .venv/bin/mypy --config-file=./pyproject.toml src/"} +test = {shell = "echo 'running tests...' && .venv/bin/pytest tests/ -p no:logging -p no:warnings"} +tox = {cmd = ".venv/bin/tox"} +cli = {cmd = ".venv/bin/python -m python_template_repo.cli"} +docs = {cmd = ".venv/bin/sphinx-build -b html docs/ docs/_build"} +ci = {shell = """\ + pdm run format \ + && pdm run lint \ + && pdm run mypy \ + && pdm run test \ + """} # [tool.isort] # atomic = true # force_grid_wrap = 0