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
13 changes: 12 additions & 1 deletion .github/workflows/run_code_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@ name: Run code checks

on:
# Trigger code checks on opening a new pull request.
# Secrets are only made available to the integration tests job, with a manual approval
# step required for PRs from forks. This prevents their potential exposure.
pull_request:
workflow_call:

# Pushing to the master branch triggers code checks
push:
branches:
- master
tags-ignore:
- "**" # Ignore all tags to prevent duplicate checks when tags are pushed.

# It should also be possible to trigger checks manually
workflow_dispatch:

jobs:
lint_check:
Expand Down
12 changes: 3 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
repos:
- repo: local
hooks:
- id: lint
name: Lint codebase
- id: lint-check
name: Lint check
entry: make lint
language: system
pass_filenames: false

- id: type-check
name: Type-check codebase
name: Type check
entry: make type-check
language: system
pass_filenames: false

- id: unit-tests
name: Run unit tests
entry: make unit-tests
language: system
pass_filenames: false
18 changes: 8 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
.PHONY: clean install-dev build publish-to-pypi lint unit-tests unit-tests-cov \
type-check check-code format

DIRS_WITH_CODE = src tests
type-check check-code format

clean:
rm -rf build dist .mypy_cache .pytest_cache .ruff_cache src/*.egg-info __pycache__ htmlcov .coverage
rm -rf .mypy_cache .pytest_cache .ruff_cache build dist htmlcov .coverage

install-dev:
uv sync --all-extras
uv run pre-commit install

build:
uv build --verbose
Expand All @@ -18,8 +15,8 @@ publish-to-pypi:
uv publish --verbose --token "${APIFY_PYPI_TOKEN_CRAWLEE}"

lint:
uv run ruff format --check $(DIRS_WITH_CODE)
uv run ruff check $(DIRS_WITH_CODE)
uv run ruff format --check
uv run ruff check

unit-tests:
uv run pytest --numprocesses=auto --verbose --cov=src/apify_shared tests/unit
Expand All @@ -28,11 +25,12 @@ unit-tests-cov:
uv run pytest --numprocesses=auto --verbose --cov=src/apify_shared --cov-report=html tests/unit

type-check:
uv run mypy $(DIRS_WITH_CODE)
uv run mypy

# The check-code target runs a series of checks equivalent to those performed by pre-commit hooks
# and the run_checks.yaml GitHub Actions workflow.
check-code: lint type-check unit-tests

format:
uv run ruff check --fix $(DIRS_WITH_CODE)
uv run ruff format $(DIRS_WITH_CODE)
uv run ruff check --fix
uv run ruff format
13 changes: 0 additions & 13 deletions mypy.ini

This file was deleted.

151 changes: 69 additions & 82 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "apify_shared"
version = "1.5.1"
description = "Tools and constants shared across Apify projects."
readme = "README.md"
license = { text = "Apache Software License" }
authors = [{ name = "Apify Technologies s.r.o.", email = "[email protected]" }]
keywords = ["apify", "api", "shared", "scraping", "automation"]

license = { file = "LICENSE" }
readme = "README.md"
requires-python = ">=3.10"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
Expand All @@ -19,110 +22,94 @@ classifiers = [
"Programming Language :: Python :: 3.13",
"Topic :: Software Development :: Libraries",
]

requires-python = ">=3.10"

# We use inclusive ordered comparison clause for non-Apify packages intentionally in order to enhance the Apify
# packages's compatibility with a wide range of external packages. This decision was discussed in detail in
# the following PR: https://github.com/apify/apify-sdk-python/pull/154
dependencies = []

[project.optional-dependencies]
dev = [
"build ~= 1.0.3",
"filelock ~= 3.12.4",
"mypy ~= 1.7.1",
"pre-commit ~= 3.4.0",
"pydoc-markdown ~= 4.8.2",
"pytest ~= 7.4.2",
"pytest-asyncio ~= 0.21.0",
"pytest-cov ~= 4.1.0",
"pytest-only ~= 2.0.0",
"pytest-timeout ~= 2.2.0",
"pytest-xdist ~= 3.3.1",
"respx ~= 0.20.1",
"ruff ~= 0.1.13",
"setuptools >= 68.0.0",
"twine ~= 5.1.1",
keywords = [
"apify",
"automation",
"chrome",
"crawlee",
"crawler",
"headless",
"scraper",
"scraping",
]
dependencies = []

[project.urls]
"Apify Homepage" = "https://apify.com"
"Changelog" = "https://github.com/apify/apify-shared-python/blob/master/CHANGELOG.md"
"Issue tracker" = "https://github.com/apify/apify-shared-python/issues"
"Source" = "https://github.com/apify/apify-shared-python"

[build-system]
build-backend = "setuptools.build_meta"
requires = ["setuptools>=68.0.0", "wheel"]
"Discord" = "https://discord.com/invite/jyEM2PRvMU"
"Issue Tracker" = "https://github.com/apify/apify-shared-python/issues"
"Source Code" = "https://github.com/apify/apify-shared-python"

[tool.setuptools.packages.find]
include = ["apify_shared*"]
where = ["src"]
[dependency-groups]
dev = [
"dycw-pytest-only~=2.1.0",
"mypy~=1.17.0",
"pre-commit~=4.3.0",
"pytest-asyncio~=1.1.0",
"pytest-cov~=6.2.0",
"pytest-timeout~=2.4.0",
"pytest-xdist~=3.8.0",
"pytest~=8.4.0",
"ruff~=0.12.0",
"setuptools", # setuptools are used by pytest, but not explicitly required

[tool.setuptools.package-data]
apify_shared = ["py.typed"]
]

[tool.ruff]
line-length = 120
include = ["src/**/*.py", "tests/**/*.py"]

[tool.ruff.lint]
select = ["ALL"]
ignore = [
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed in {filename}
"BLE001", # Do not catch blind exception
"C901", # `{name}` is too complex
"COM812", # This rule may cause conflicts when used with the formatter
"D100", # Missing docstring in public module
"D104", # Missing docstring in public package
"EM", # flake8-errmsg
"G004", # Logging statement uses f-string
"ISC001", # This rule may cause conflicts when used with the formatter
"FIX", # flake8-fixme
"PGH003", # Use specific rule codes when ignoring type issues
"PLR0911", # Too many return statements
"PLR0913", # Too many arguments in function definition
"PLR0915", # Too many statements
"PTH", # flake8-use-pathlib
"PYI034", # `__aenter__` methods in classes like `{name}` usually return `self` at runtime
"PYI036", # The second argument in `__aexit__` should be annotated with `object` or `BaseException | None`
"S102", # Use of `exec` detected
"S105", # Possible hardcoded password assigned to
"S106", # Possible hardcoded password assigned to argument: "{name}"
"S301", # `pickle` and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue
"S303", # Use of insecure MD2, MD4, MD5, or SHA1 hash function
"S311", # Standard pseudo-random generators are not suitable for cryptographic purposes
"TD002", # Missing author in TODO; try: `# TODO(<author_name>): ...` or `# TODO @<author_name>: ...
"TRY003", # Avoid specifying long messages outside the exception class
"COM812", # This rule may cause conflicts when used with the formatter
"D100", # Missing docstring in public module
"D104", # Missing docstring in public package
"D107", # Missing docstring in `__init__`
"D203", # One blank line required before class docstring
"D213", # Multi-line docstring summary should start at the second line
"D413", # Missing blank line after last section
"EM", # flake8-errmsg
"ISC001", # This rule may cause conflicts when used with the formatter
"S105", # Possible hardcoded password assigned to
"TRY003", # Avoid specifying long messages outside the exception class
]

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

[tool.ruff.lint.per-file-ignores]
"**/__init__.py" = [
"F401", # Unused imports
]
"**/{scripts}/*" = [
"D", # Everything from the pydocstyle
"INP001", # File {filename} is part of an implicit namespace package, add an __init__.py
"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable
"T20", # flake8-print
]
"**/{tests}/*" = [
"D", # Everything from the pydocstyle
"INP001", # File {filename} is part of an implicit namespace package, add an __init__.py
"PLR2004", # Magic value used in comparison, consider replacing {value} with a constant variable
"S101", # Use of assert detected
"T20", # flake8-print
"TRY301", # Abstract `raise` to an inner function
]

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

[tool.ruff.lint.flake8-quotes]
docstring-quotes = "double"
inline-quotes = "single"

[tool.ruff.lint.isort]
known-local-folder = ["apify_shared"]
[tool.pytest.ini_options]
addopts = "-ra"
asyncio_default_fixture_loop_scope = "function"
asyncio_mode = "auto"
timeout = 300

[tool.ruff.lint.pydocstyle]
convention = "google"
[tool.mypy]
python_version = "3.10"
files = ["src", "tests"]
check_untyped_defs = true
disallow_incomplete_defs = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
disallow_untyped_defs = true
no_implicit_optional = true
warn_redundant_casts = true
warn_return_any = true
warn_unreachable = true
warn_unused_ignores = true
3 changes: 0 additions & 3 deletions pytest.ini

This file was deleted.

Loading
Loading