Skip to content
Draft
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
30 changes: 0 additions & 30 deletions .flake8

This file was deleted.

31 changes: 8 additions & 23 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.13.2
hooks:
- id: ruff-check
args: [ --fix ]
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- hooks:
- id: black
exclude: test_mypy\.py$ # https://github.com/davidfritzsche/pytest-mypy-testing/issues/29
language_version: python3
repo: https://github.com/psf/black
rev: 24.10.0
- hooks:
- id: isort
language_version: python3
repo: https://github.com/timothycrosley/isort
rev: 5.13.2
- hooks:
- id: flake8
language_version: python3
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
- flake8-debugger
- flake8-string-format
repo: https://github.com/pycqa/flake8
rev: 7.1.1
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.19.0
rev: 1.19.1
hooks:
- id: blacken-docs
additional_dependencies:
- black==24.10.0
- black==25.1.0
- repo: local
hooks:
- id: no-colon-comments
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_copyright(attribution, *, first_year):

def get_version_and_release():
try:
import zyte_common_items # noqa: F401
import zyte_common_items # noqa: F401, PLC0415
except ImportError:
return "", ""
version_bytes = pkgutil.get_data("zyte_common_items", "VERSION") or b""
Expand All @@ -23,7 +23,7 @@ def get_version_and_release():


project = "zyte-common-items"
copyright = get_copyright("Zyte Group Ltd", first_year=2022)
project_copyright = get_copyright("Zyte Group Ltd", first_year=2022)
version, release = get_version_and_release()

extensions = [
Expand Down
9 changes: 5 additions & 4 deletions pre-commit-scripts/no_colon_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def check_file_for_colon_comment(file_path):
with open(file_path, "r", encoding="utf-8") as f:
with Path(file_path).open(encoding="utf-8") as f:
for i, line in enumerate(f, 1):
if "test_file" in file_path:
raise ValueError(f"{line=}")
Expand All @@ -23,9 +23,10 @@ def check_file_for_colon_comment(file_path):
def main():
failed = False
for file in sys.argv[1:]:
if Path(file).suffix in PYTHON_FILE_EXTENSIONS:
if check_file_for_colon_comment(file):
failed = True
if Path(file).suffix in PYTHON_FILE_EXTENSIONS and check_file_for_colon_comment(
file
):
failed = True
if failed:
print(
"\nERROR: Sphinx-style comments detected. Please use docstrings for documentation."
Expand Down
161 changes: 154 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ zyte_common_items = ["py.typed","VERSION"]
include = ["zyte_common_items*"]
namespaces = false

[tool.black]
exclude = 'test_mypy\.py' # https://github.com/davidfritzsche/pytest-mypy-testing/issues/29

[tool.isort]
profile = "black"
multi_line_output = 3

[tool.mypy]
check_untyped_defs = true
ignore_missing_imports = true
Expand All @@ -82,3 +75,157 @@ regex = true

[[tool.bumpversion.files]]
filename = "zyte_common_items/VERSION"

[tool.ruff.format]
exclude = [
"tests/test_mypy.py", # https://github.com/davidfritzsche/pytest-mypy-testing/issues/29
]

[tool.ruff.lint]
extend-select = [
# flake8-builtins
"A",
# flake8-async
"ASYNC",
# flake8-bugbear
"B",
# flake8-comprehensions
"C4",
# flake8-commas
"COM",
# pydocstyle
"D",
# flake8-future-annotations
"FA",
# flynt
"FLY",
# refurb
"FURB",
# isort
"I",
# flake8-implicit-str-concat
"ISC",
# flake8-logging
"LOG",
# Perflint
"PERF",
# pygrep-hooks
"PGH",
# flake8-pie
"PIE",
# pylint
"PL",
# flake8-pytest-style
"PT",
# flake8-use-pathlib
"PTH",
# flake8-pyi
"PYI",
# flake8-quotes
"Q",
# flake8-return
"RET",
# flake8-raise
"RSE",
# Ruff-specific rules
"RUF",
# flake8-bandit
"S",
# flake8-simplify
"SIM",
# flake8-slots
"SLOT",
# flake8-debugger
"T10",
# flake8-type-checking
"TC",
# flake8-tidy-imports
"TID",
# pyupgrade
"UP",
# pycodestyle warnings
"W",
# flake8-2020
"YTT",
]
ignore = [
# Trailing comma missing
"COM812",
# Missing docstring in public module
"D100",
# Missing docstring in public class
"D101",
# Missing docstring in public method
"D102",
# Missing docstring in public function
"D103",
# Missing docstring in public package
"D104",
# Missing docstring in magic method
"D105",
# Missing docstring in public nested class
"D106",
# Missing docstring in __init__
"D107",
# One-line docstring should fit on one line with quotes
"D200",
# No blank lines allowed after function docstring
"D202",
# 1 blank line required between summary line and description
"D205",
# Multi-line docstring closing quotes should be on a separate line
"D209",
# First line should end with a period
"D400",
# First line should be in imperative mood; try rephrasing
"D401",
# First line should not be the function's "signature"
"D402",
# Too many return statements
"PLR0911",
# Too many branches
"PLR0912",
# Too many arguments in function definition
"PLR0913",
# Too many statements
"PLR0915",
# Magic value used in comparison
"PLR2004",
# String contains ambiguous {}.
"RUF001",
# Docstring contains ambiguous {}.
"RUF002",
# Comment contains ambiguous {}.
"RUF003",
# Mutable class attributes should be annotated with `typing.ClassVar`
"RUF012",
# Use of `assert` detected
"S101",
# Prefer absolute imports over relative imports from parent modules
"TID252",
# Add `from __future__ import annotations` to simplify
# (The fix can break andi.)
"FA100",
]

[tool.ruff.lint.flake8-type-checking]
runtime-evaluated-decorators = ["attrs.define"]

[tool.ruff.lint.isort]
split-on-trailing-comma = false

[tool.ruff.lint.per-file-ignores]
"zyte_common_items/__init__.py" = ["F401"]
"zyte_common_items/components/__init__.py" = ["F401"]
"zyte_common_items/items/__init__.py" = ["F401"]
"zyte_common_items/pages/__init__.py" = ["F401"]
# Skip PEP 604 suggestions for files with attr classes
"zyte_common_items/components/*.py" = ["UP007", "UP045"]
"zyte_common_items/items/*.py" = ["UP007", "UP045"]
# ”module level import not at the top of file“ caused by pytest.importorskip
"tests/test_ae_pipeline.py" = ["E402"]
"tests/test_pipelines.py" = ["E402"]
"tests/*" = ["S", "B018"]

[tool.ruff.lint.pydocstyle]
convention = "pep257"
27 changes: 3 additions & 24 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,16 @@
import contextlib
import json
import os
import random


def load_fixture(name):
path = os.path.join(os.path.dirname(__file__), f"fixtures/{name}")
with open(path, "r") as f:
return json.loads(f.read())


@contextlib.contextmanager
def temp_seed(seed):
state = random.getstate()
random.seed(seed)
try:
yield
finally:
random.setstate(state)


def crazy_monkey_nullify(data, drop_prob=0.5):
"""Make some attributes None or [] recursively"""

def nullify(value):
if drop_prob <= random.random():
return [] if isinstance(value, list) else None
else:
return crazy_monkey_nullify(value, drop_prob)
return crazy_monkey_nullify(value, drop_prob)

if isinstance(data, list):
return [crazy_monkey_nullify(value, drop_prob) for value in data]
elif isinstance(data, dict):
if isinstance(data, dict):
return {k: nullify(v) for k, v in data.items()}
else:
return data
return data
Loading
Loading