Skip to content
Open
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
27 changes: 14 additions & 13 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,23 @@ jobs:
# run: |
# tox -e lint-git

# lint:
lint:
# name: "Linting and type checking"
# runs-on: ubuntu-24.04
name: "Linting"
runs-on: ubuntu-24.04
# strategy:
# fail-fast: true
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-python@v5
# with:
# python-version: "3.13"
# - name: "Install tox"
# run: |
# pip install tox
# - name: "Lint formatting"
# run: |
# tox -e lint-py
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: "Install tox"
run: |
pip install tox
- name: "Lint formatting"
run: |
tox -e lint-py
# - name: "Type checking"
# run: |
# tox -e lint-mypy
Expand Down
261 changes: 178 additions & 83 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,26 @@ homepage = "https://github.com/ivankorobkov/python-inject"
source = "https://github.com/ivankorobkov/python-inject"
issues = "https://github.com/ivankorobkov/python-inject/issues"


[dependency-groups]
dev = [
"ipython",
"ruff",
"mypy",
"yamllint",
{ include-group = "tests" },
]

tests = [
"pytest",
"pytest-cov",
]

dev = [
"ipython",
{ include-group = "tests" },
]

[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[tool.black]
line-length = 120
skip-string-normalization = true
target_version = ["py39", "py310", "py311"]
include = '\.pyi?$'
exclude = '''
/(
\.eggs
| \.git
| \.github
| \.hg
| \.idea
| \.mypy_cache
| \.tox
| \.pyre_configuration
| \.venv
| _build
| build
| dist
| var
)
'''

[tool.hatch.build.hooks.vcs]
version-file = "src/inject/_version.py"
Expand All @@ -78,13 +61,15 @@ packages = ["src/inject"]
[tool.hatch.version]
source = "vcs"


[tool.isort]
case_sensitive = true
include_trailing_comma = true
line_length = 120
multi_line_output = 3
profile = "black"


[tool.mypy]
check_untyped_defs = true
disallow_any_generics = true
Expand All @@ -103,6 +88,8 @@ warn_unused_ignores = true
#strict = true # TODO(pyctrl): improve typings and enable strict mode
exclude = ["tests", ".venv"]


# TODO(pyctrl): deprecate pyright — stay with mypy
[tool.pyright]
defineConstant = { DEBUG = true }
exclude = []
Expand All @@ -114,69 +101,133 @@ pythonVersion = "3.11"
reportMissingImports = true
reportMissingTypeStubs = false


[tool.ruff]
ignore = [
"B027", # Allow non-abstract empty methods in abstract base classes
"FBT003", # Allow boolean positional values in function calls, like `dict.get(... True)`
# Ignore checks for possible passwords
"S105",
"S106",
"S107",
# Ignore complexity
"C901",
"PLR0911",
"PLR0912",
"PLR0913",
"PLR0915",
"PLC1901", # empty string comparisons
"PLW2901", # `for` loop variable overwritten
"SIM114", # Combine `if` branches using logical `or` operator
line-length = 88
extend-exclude = [".git", ".venv", "docs"]

[tool.ruff.lint]
preview = true
extend-select = ["ALL"]
extend-ignore = [
"D10", # missing documentation
"D203", # 1 of conflicting code-styles
"D212", # 1 of conflicting code-styles
"C408", # allow `dict()` instead of literal
"TD003", # don't require issue link
# Completely disable
"FIX",
"CPY",
# formatter conflict rules
"W191",
"E111",
"E114",
"E117",
"EM101",
"EM102",
"ERA001", # commented code
"D206",
"D300",
"DOC201",
"DOC402",
"Q000",
"Q001",
"Q002",
"Q003",
"COM812",
"COM819",
"ISC001",
"ISC002",
"N818", # Exception name should be named with an Error suffix
"TRY003",
"UP006",
"UP007",
"UP035",
"UP045",
"FA100",
]
line-length = 120
select = [
"A",
"B",
"C",
"DTZ",
"E",
"EM",
"F",
"FBT",
"I",
"ICN",
"ISC",
"N",
"PLC",
"PLE",
"PLR",
"PLW",
"Q",
"RUF",
"S",
"SIM",
"T",
"TID",
"UP",
"W",
"YTT",
]
target-version = ["py39", "py310", "py311"]
unfixable = [
"F401", # Don't touch unused imports

[tool.ruff.lint.extend-per-file-ignores]
"**/tests/**/test_*.py" = [
"ANN", # annotations not required in tests
"E731", # Do not assign a `lambda` expression, use a `def`
"PLC2701", # Private name import
"PLR0913", # Too many arguments in function definition
"PLR0917", # Too many positional arguments
"PLR2004", # allow "magic" values in tests
"PLR6301", # Method could be a function, class method, or static method
"PT017", # Found assertion on exception `except` block, use `pytest.raises()` instead
"PT027", # Use `pytest.raises` instead of unittest-style `assertRaisesRegex`
"S101", # allow asserts
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
"SLF001", # allow private member access
]
"/**/tests/__init__.py" = ["PLR6301"]

[tool.ruff.flake8-quotes]
inline-quotes = "single"
[tool.ruff.lint.flake8-import-conventions.extend-aliases]
"typing" = "t"

[tool.ruff.flake8-tidy-imports]
ban-relative-imports = "all"
[tool.ruff.lint.flake8-import-conventions]
banned-from = ["dataclasses", "inject", "typing"]

[tool.ruff.isort]
[tool.ruff.lint.isort]
force-single-line = true
known-first-party = ["inject"]

[tool.ruff.per-file-ignores]
# Tests can use magic values, assertions, and relative imports
"/**/test_*.py" = ["PLR2004", "S101", "TID252"]
[tool.ruff.lint.flake8-tidy-imports]
ban-relative-imports = "all"

[tool.ruff.format]
quote-style = "double"
indent-style = "space"

#ignore = [
# "B027", # Allow non-abstract empty methods in abstract base classes
# "FBT003", # Allow boolean positional values in function calls, like `dict.get(... True)`
# # Ignore checks for possible passwords
# "S105",
# "S106",
# "S107",
# # Ignore complexity
# "C901",
# "PLR0911",
# "PLR0912",
# "PLR0913",
# "PLR0915",
# "PLC1901", # empty string comparisons
# "PLW2901", # `for` loop variable overwritten
# "SIM114", # Combine `if` branches using logical `or` operator
#]
#select = [
# "A",
# "B",
# "C",
# "DTZ",
# "E",
# "EM",
# "F",
# "FBT",
# "I",
# "ICN",
# "ISC",
# "N",
# "PLC",
# "PLE",
# "PLR",
# "PLW",
# "Q",
# "RUF",
# "S",
# "SIM",
# "T",
# "TID",
# "UP",
# "W",
# "YTT",
#]
#unfixable = [
# "F401", # Don't touch unused imports
#]


#### Pytest & Coverage ####
Expand Down Expand Up @@ -219,20 +270,23 @@ env_list = [
"py311",
"py312",
"py313",
"fmt-py",
"fmt-toml",
"lint-py",
#"lint-mypy", # TODO(pyctrl): make it green & uncomment
"lint-toml",
"lint-yaml",
#"lint-git",
"coverage",
]

[tool.tox.labels]
fmt = [
# "fmt-py",
"fmt-py",
"fmt-toml",
]
lint = [
#"lint-py",
"lint-py",
#"lint-mypy", # TODO(pyctrl): make it green & uncomment
"lint-toml",
"lint-yaml",
Expand All @@ -247,6 +301,28 @@ dependency_groups = ["tests"]
commands = [["pytest", { replace = "posargs", extend = true }]]

# tox envs
[tool.tox.env.lint-py]
description = "Lint python files"
deps = ["ruff"]
skip_install = true
commands = [
[
"ruff",
"format",
"--diff",
{ replace = "posargs", default = [
"{tox_root}",
], extend = true },
],
[
"ruff",
"check",
{ replace = "posargs", default = [
"{tox_root}",
], extend = true },
],
]

[tool.tox.env.lint-mypy]
description = "Type checking"
deps = ["mypy"]
Expand Down Expand Up @@ -275,6 +351,25 @@ commands = [
],
]

[tool.tox.env.fmt-py]
description = "Format python files"
deps = ["ruff"]
skip_install = true
commands = [
[
"ruff",
"format",
{ replace = "posargs", default = ["{tox_root}"], extend = true },
],
[
"ruff",
"check",
"--fix",
"--show-fixes",
{ replace = "posargs", default = ["{tox_root}"], extend = true },
],
]

[tool.tox.env.fmt-toml]
description = "Format TOML files"
allowlist_externals = ["taplo"]
Expand Down
Loading
Loading