Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
*.pyc
*.py[co]
.venv/
__pycache__/
*.pdb
*.db

*.log
*.sqlite
*.sqlite3

*.egg-info/
.ruff_cache
.mypy_cache
.pytest_cache
.coverage
Expand Down
48 changes: 8 additions & 40 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,54 +19,22 @@ repos:
- id: double-quote-string-fixer
exclude: manage.py
- id: name-tests-test
- repo: https://github.com/psf/black
rev: 25.1.0
hooks:
- id: black
exclude: migrations/
args: ['--verbose']
# It is recommended to specify the latest version of Python
# supported by your project here, or alternatively use
# pre-commit's default_language_version, see
# https://pre-commit.com/#top_level-default_language_version
language_version: python3.12
- repo: https://github.com/pycqa/isort
rev: 6.0.1

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.8
hooks:
- id: isort
name: isort (python)
language_version: python3.12
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.15.0
hooks:
- id: mypy
additional_dependencies: [pydantic, types-redis, aiomqtt]
language_version: python3.12
- repo: https://github.com/PyCQA/pylint
rev: v3.3.7
hooks:
- id: pylint
additional_dependencies:
[
pydantic,
pydantic-settings,
pylint-pydantic,
fastapi,
uvicorn,
motor,
redis,
types-redis,
aiomqtt,
]
language_version: python3.12
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
hooks:
- id: pyupgrade

default_language_version:
# force all unspecified python hooks to run python3
python: python3
python: 'python3.12'

ci:
autofix_prs: true
Expand Down
34 changes: 17 additions & 17 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
{
"files.exclude": {
"**/__pycache__": true,
"**/.mypy_cache": true
"**/.ruff_cache": true,
"**/.mypy_cache": true,
"**/*.egg-info": true,
"**/.pytest_cache": true,
"**/.coverage": true
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit",
"source.fixAll": "explicit"
}
},
"python.analysis.importFormat": "absolute",
"black-formatter.args": [
"--line-length=88",
"--skip-string-normalization"
"ruff.lineLength": 100,
"ruff.lint.select": [
"B",
"C4",
"E",
"F",
"I",
"SIM",
"TID",
"UP",
"W"
],
"isort.args": [
"--profile=black"
],
"isort.severity": {
"E": "Error"
},
"mypy-type-checker.args": [
"--enable-incomplete-feature=NewGenericSyntax"
],
"pylint.args": [
"--py-version=3.12",
"--load-plugins=pylint.extensions.bad_builtin,pylint_pydantic",
"--ignore=CVS,.git,__pycache__,.mypy_cache,tests",
"--disable=no-self-argument",
],
"python.testing.pytestEnabled": false
}
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,11 @@
### Project

- [Project: `pyproject.toml`](https://lucas-six.github.io/python-cookbook/cookbook/build/project)
- `black`
- `isort`
- `mypy`
- `pylint`
- `Ruff` - Linter and Code Formatter
- `black` - Code Formatter
- `isort` - Sort Imports
- `mypy` - Type Checker
- `pylint` - Linter

### Test

Expand Down
111 changes: 78 additions & 33 deletions cookbook/build/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

```bash
uv init --python 3.12
uv add --dev black isort mypy pylint
uv add --dev ruff mypy
```

### `Pipenv`
Expand Down Expand Up @@ -75,11 +75,84 @@ py-modules = ['src', 'app']
url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
default = true

[dependency-groups]
dev = [
"mypy>=1.15.0",
"ruff>=0.11.8",
]

[tool.ruff]
line-length = 100
lint.extend-safe-fixes = [
# non-pep585-annotation
"UP006",
]
lint.select = [
# flake8-bugbear
"B",
# flake8-comprehensions
"C4",
# pycodestyle
"E",
# Pyflakes errors
"F",
# isort
"I",
# flake8-simplify
"SIM",
# flake8-tidy-imports
"TID",
# pyupgrade
"UP",
# Pyflakes warnings
"W",
]
lint.ignore = []

[tool.ruff.format]
quote-style = "single"

[tool.mypy]
python_version = "3.12"
exclude = [
"test_main.py",
]
follow_imports = "silent"
warn_redundant_casts = true
warn_unused_ignores = true
warn_unused_configs = true
disallow_any_generics = false
check_untyped_defs = true
no_implicit_reexport = true
disallow_untyped_defs = true

[tool.pyright]
include = [
"src",
]
exclude = [
".git",
"**/__pycache__",
"**/.venv",
"**/.tox",
"**/.mypy_cache",
"**/.pytest_cache",
]
reportGeneralTypeIssues = "none"
reportUnboundVariable = "none"
stubPath = ""
pythonVersion = "3.12"
```

### `black` + `isort` + `pylint`

```toml
# pyproject.toml

[dependency-groups]
dev = [
"black>=25.1.0",
"isort>=6.0.1",
"mypy>=1.15.0",
"pylint>=3.3.6",
]

Expand Down Expand Up @@ -121,20 +194,6 @@ extend_skip = [".gitignore", ".env", ".dockerignore"]
# skip_glob = []
extend_skip_glob = []

[tool.mypy]
python_version = "3.12"
exclude = [
"test_main.py",
]
follow_imports = "silent"
warn_redundant_casts = true
warn_unused_ignores = true
warn_unused_configs = true
disallow_any_generics = false
check_untyped_defs = true
no_implicit_reexport = true
disallow_untyped_defs = true

[tool.pylint.main]
recursive = true
py-version = 3.12
Expand Down Expand Up @@ -180,23 +239,6 @@ max-locals = 25

[tool.pylint.deprecated_builtins]
bad-functions = ["map", "filter"]

[tool.pyright]
include = [
"src",
]
exclude = [
".git",
"**/__pycache__",
"**/.venv",
"**/.tox",
"**/.mypy_cache",
"**/.pytest_cache",
]
reportGeneralTypeIssues = "none"
reportUnboundVariable = "none"
stubPath = ""
pythonVersion = "3.12"
```

## More
Expand All @@ -210,9 +252,12 @@ pythonVersion = "3.12"
- [PEP 517 - A build-system independent format for source trees](https://peps.python.org/pep-0517/)
- [PEP 301 – Package Index and Metadata for Distutils](https://peps.python.org/pep-0301/)
- [PEP 518 – Specifying Minimum Build System Requirements for Python Projects](https://peps.python.org/pep-0518/)
- [PEP 621 – Storing project metadata in pyproject.toml](https://peps.python.org/pep-0621/)
- [Package Classifiers](https://pypi.org/classifiers/)
- [TOML Documentation](https://toml.io/en/)
- [`black` Documentation](https://black.readthedocs.io/en/stable/)
- [`isort` Documentation](https://pycqa.github.io/isort/)
- [`mypy` Documentation](https://mypy.readthedocs.io/en/stable/)
- [`pylint` Documentation](https://pylint.pycqa.org/en/latest/)
- [`Ruff` Documentation](https://docs.astral.sh/ruff/)
- [`pre-commit` Documentation](https://pre-commit.com/)
Loading