Skip to content

Instantly share code, notes, and snippets.

@koepnick
Last active August 20, 2024 16:10
Show Gist options
  • Save koepnick/d5459c5d1ed60fd14063c098cbf45ad7 to your computer and use it in GitHub Desktop.
Save koepnick/d5459c5d1ed60fd14063c098cbf45ad7 to your computer and use it in GitHub Desktop.
Commonly Used Poetry Configurations (in pyproject.toml)

This is simply a dump of the various pyproject.toml entries that I commonly use.

Libraries Referenced

Static Checking: MyPy

Code Complexity: Wily

Maintainability: Radon

Cyclomatic Complexity: Xenon

Docstring Coverage: Interrogate

Code Coverage: Coverage.py

Linting: Ruff

Linting: PyLint

Note: Please do not simply dump these into your project without trying to understand it.

These configurations do NOT represent a proper project. Not every tool listed is needed for every project, in fact, there is a great deal of replication in function between them. E.g: PyLint is good enough for most projects, Ruff is faster (being written in Rust) and has the ability to offer fixes.

[tool.poetry]
name = "SomePackage"
version = "0.1.0"
description = "Some Package"
authors = ["Inigo Montoya <inigo@localhost>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.10"
[tool.poetry.group.dev.dependencies]
pdbp = "^1.5.3"
pudb = "^2024.1.2"
mypy = "^1.11.1"
pylint = "^3.2.6"
coverage = "^7.6.1"
xenon = "^0.9.1"
radon = {extras = ["toml"], version = "^6.0.1"}
interrogate = "^1.7.0"
sphinx = "^8.0.2"
perflint = "^0.8.1"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.pytest.ini_options]
testpaths = [
"tests"
]
[tool.pylint.format]
max-line-length = 120
[tool.pylint.MASTER]
fail-under = 9.0
ignore-patterns = ''
jobs = 0
ignore = '.git'
[tool.pylint."MESSAGES CONTROL"]
disable = 'E,W,C,R'
enable = 'W0511'
#enable = 'W0612,W0611,W0120,C0115,C0116,C0114'
[tool.pylint.REPORTS]
output-format = 'json'
[tool.pylint.REFACTORING]
max-nested-blocks = 3
never-returning-functions = 'sys.exit'
[tool.pylint.LOGGING]
logging-format-style = 'new'
logging-modules = 'logging'
[tool.pylint.MISCELLANEOUS]
notes = '''FIXME,
TODO,
'''
notes-rgx = '[A-Z]+:.*'
[tool.mypy]
disallow_untyped_defs = true
disallow_incomplete_defs = true
disallow_untyped_calls = true
#exclude = []
#ignore_missing_imports = true
[tool.coverage.run]
branch = true
sigterm = false # Always return 0
[tool.coverage.report]
ignore_errors = true
exclude_also = [
"raise AssertionError",
"raise NotImplementedError"
]
[tool.wily]
operators = "halstaed,maintainability,cyclomatic"
max_revisions = 50
path = "src"
cache = ".wily"
[tool.interrogate]
exclude = ["tests/", "entrypoint.py", ".environment", "_scripts"]
import-module = false
ignore-nested-classes = true
ignore-nested-functions = true
ignore-private = true
ignore-property-decorators = true
ignore-semiprivate = true
fail-under = 10
verbose = 1
[tool.ruff]
exclude = [
".direnv",
".git",
".git-rewrite",
".ipynb_checkpoints",
".mypy_cache",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".tox",
".env",
".environment",
"__pypackages__",
"_build",
"build",
"artifacts",
"tests",
"dist",
"node_modules",
"site-packages",
"venv",
]
# I prefer slightly wider lines
line-length = 120
indent-width = 4
# Assume Python 3.12
target-version = "py312"
# Everything below this is verbatin from the Ruff docs (https://docs.astral.sh/ruff/configuration/)
[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F"]
ignore = []
# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
[tool.ruff.format]
# Compatibility with Black
# Use double quotes for strings.
quote-style = "double"
# Indent with spaces
indent-style = "space"
# Respect magic trailing commas.
skip-magic-trailing-comma = false
line-ending = "auto"
# Enable auto-formatting of code examples in docstrings. Markdown,
# reStructuredText code/literal blocks and doctests are all supported.
#
# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
docstring-code-format = false
docstring-code-line-length = "dynamic"
[tool.ruff.lint]
# Enable flake8-bugbear (`B`) rules, in addition to the defaults.
select = ["E4", "E7", "E9", "F", "B"]
# Avoid enforcing line-length violations (`E501`)
ignore = ["E501"]
# Avoid trying to fix flake8-bugbear (`B`) violations.
unfixable = ["B"]
# Ignore `E402` (import violations) in all `__init__.py` files, and in selected subdirectories.
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["E402"]
"**/{tests,docs,tools}/*" = ["E402"]
[tool.ruff.format]
# 5. Use single quotes in `ruff format`.
quote-style = "single"
[tool.ruff.lint]
# Add "Q" to the list of enabled codes.
select = ["E4", "E7", "E9", "F", "Q"]
[tool.ruff.lint.flake8-quotes]
docstring-quotes = "double"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment