Skip to content

Commit

Permalink
use pdm scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
MultifokalHirn committed Dec 7, 2023
1 parent 74f405f commit dc4839e
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
98 changes: 44 additions & 54 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
53 changes: 20 additions & 33 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,56 +22,49 @@ 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:
# api: ## Run the api service
# $(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

Expand All @@ -84,10 +75,6 @@ test:
pdm run test
.PHONY: test

# clean:
# rm -rf __pycache__
# .PHONY: clean

.DEFAULT_GOAL := help

define find.functions
Expand Down
25 changes: 19 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit dc4839e

Please sign in to comment.