Skip to content

Commit

Permalink
Align scripts and Ruff configuration with the SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
vdusek committed Dec 6, 2023
1 parent a549404 commit 659bf80
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
21 changes: 18 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ classifiers = [
]

requires-python = ">=3.8"

# 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.5.1",
"mypy ~= 1.7.1",
"pre-commit ~= 3.4.0",
"pydoc-markdown ~= 4.8.2",
"pytest ~= 7.4.2",
Expand All @@ -36,7 +40,7 @@ dev = [
"pytest-timeout ~= 2.2.0",
"pytest-xdist ~= 3.3.1",
"respx ~= 0.20.1",
"ruff ~= 0.1.5",
"ruff ~= 0.1.6",
"twine ~= 4.0.2",
]

Expand All @@ -63,17 +67,27 @@ 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>: ...
"TID252", # Relative imports from parent modules are bannedRuff
"TRY003", # Avoid specifying long messages outside the exception class
Expand All @@ -97,8 +111,9 @@ indent-style = "space"
"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
"S101", # Use of assert detected
"T20", # flake8-print
"TRY301", # Abstract `raise` to an inner function
]

[tool.ruff.lint.flake8-quotes]
Expand Down
2 changes: 2 additions & 0 deletions scripts/check_version_availability.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3

from __future__ import annotations

from utils import get_current_package_version, get_published_package_versions

# Checks whether the current package version number was not already used in a published release.
Expand Down
2 changes: 2 additions & 0 deletions scripts/check_version_in_changelog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3

from __future__ import annotations

import re

from utils import REPO_ROOT, get_current_package_version
Expand Down
2 changes: 2 additions & 0 deletions scripts/print_current_package_version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3

from __future__ import annotations

from utils import get_current_package_version

# Print the current package version from the pyproject.toml file to stdout
Expand Down
2 changes: 2 additions & 0 deletions scripts/update_version_for_prerelease.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3

from __future__ import annotations

import re
import sys

Expand Down
11 changes: 6 additions & 5 deletions scripts/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import json
import pathlib
from urllib.error import HTTPError
Expand Down Expand Up @@ -27,11 +29,10 @@ def set_current_package_version(version: str) -> None:
updated_pyproject_toml_file_lines = []
version_string_found = False
for line in pyproject_toml_file:
processed_line = line
if line.startswith('version = '):
version_string_found = True
processed_line = f'version = "{version}"\n'
updated_pyproject_toml_file_lines.append(processed_line)
line = f'version = "{version}"\n' # noqa: PLW2901
updated_pyproject_toml_file_lines.append(line)

if not version_string_found:
raise RuntimeError('Unable to find version string.')
Expand All @@ -48,8 +49,8 @@ def get_published_package_versions() -> list:
package_data = json.load(urlopen(package_info_url)) # noqa: S310
published_versions = list(package_data['releases'].keys())
# If the URL returns 404, it means the package has no releases yet (which is okay in our case)
except HTTPError as e:
if e.code != 404:
except HTTPError as exc:
if exc.code != 404:
raise
published_versions = []
return published_versions

0 comments on commit 659bf80

Please sign in to comment.