Skip to content

Commit

Permalink
Tweak ruff config
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Oct 29, 2023
1 parent 2a87697 commit ea0f66a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
26 changes: 23 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,21 @@ exclude = [
[tool.ruff]
fix = true
extend-select = [
"UP",
"I",
"C",
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"C90", # mccabe
"E",
"F",
"I", # isort
"N", # pep8 naming
"PL", # pylint
"UP", # pyupgrade
"PERF",
"RUF",
"S", # flake8-bandit
"T100", # flake8-debugger
"TRY",
"W",
]
target-version = "py37"
ignore = [
Expand All @@ -75,6 +87,14 @@ exclude = [
"mk_core_addons",
]

[tool.ruff.per-file-ignores]
"tests/*.py" = [
"S101", # use of assert detected
"S603", # `subprocess` call: check for execution of untrusted input
"S607", # Starting a process with a partial executable path
]


[tool.ruff.isort]
known-first-party = ["manifestoo_core"]

Expand Down
2 changes: 1 addition & 1 deletion src/manifestoo_core/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def external_dependencies(self) -> Dict[str, List[str]]:
)

@property
def license(self) -> Optional[str]: # noqa: A003
def license(self) -> Optional[str]:
return self._get("license", _check_optional_str, default=None)

@property
Expand Down
9 changes: 4 additions & 5 deletions src/manifestoo_core/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
get_git_postversion,
)
from .manifest import Manifest
from .odoo_series import OdooSeries
from .odoo_series import MIN_VERSION_PARTS, OdooSeries

ODOO_ADDON_DIST_RE = re.compile(
r"^(odoo(\d{1,2})?[-_]addon[-_].*|odoo$|odoo[^a-zA-Z0-9._-]+)",
Expand All @@ -37,7 +37,6 @@
r"^odoo(\d{1,2})?[-_]addon[-_](?P<addon_name>[a-z0-9_-]+)$",
)


__all__ = [
"POST_VERSION_STRATEGY_DOT_N",
"POST_VERSION_STRATEGY_NINETYNINE_DEVN",
Expand Down Expand Up @@ -417,7 +416,7 @@ def _make_classifiers(odoo_series: OdooSeries, manifest: Manifest) -> List[str]:
"GNU Lesser General Public License v3 or later (LGPLv3+)"
),
}
license = manifest.license # noqa: A001 `license` is shadowing a python builtin
license = manifest.license # `license` is shadowing a python builtin
if license:
license_classifier = licenses.get(license.lower())
if license_classifier:
Expand Down Expand Up @@ -496,10 +495,10 @@ def _get_version(
version = "0.0.0"
if not odoo_series_override:
version_parts = version.split(".")
if len(version_parts) < 5:
if len(version_parts) < MIN_VERSION_PARTS:
msg = (
f"Version in manifest must have at least "
f"5 components and start with "
f"{MIN_VERSION_PARTS} components and start with "
f"the Odoo series number (in {addon.path})"
)
raise UnsupportedManifestVersion(msg)
Expand Down
5 changes: 4 additions & 1 deletion src/manifestoo_core/odoo_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
]


MIN_VERSION_PARTS = 5


class OdooSeries(str, Enum):
"""Enum representing an Odoo Series (also known as Version)."""

Expand Down Expand Up @@ -55,7 +58,7 @@ def detect_from_addon_version(version: str) -> Optional[OdooSeries]:
Returns ``None`` if the version is not recognized.
"""
parts = version.split(".")
if len(parts) < 5:
if len(parts) < MIN_VERSION_PARTS:
return None
try:
return OdooSeries(".".join(parts[:2]))
Expand Down
6 changes: 3 additions & 3 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _m( # noqa: PLR0913 too many arguments
external_dependencies: Optional[Dict[str, List[str]]] = None,
website: Optional[str] = None,
author: Optional[str] = None,
license: Optional[str] = None, # noqa: A002
license: Optional[str] = None,
development_status: Optional[str] = None,
# options
depends_override: Optional[Dict[str, str]] = None,
Expand Down Expand Up @@ -429,7 +429,7 @@ def test_classifiers(tmp_path: Path, odoo_series: str) -> None:
)
def test_classifiers_license(
tmp_path: Path,
license: str, # noqa: A002 shadowing Python builtin
license: str, # shadowing Python builtin
expected_license: str,
) -> None:
assert expected_license in _m(tmp_path, license=license)["classifier"]
Expand Down Expand Up @@ -457,7 +457,7 @@ def test_classifiers_development_status(
)


def test_license(tmp_path: Path, license: str = "AGPL-3") -> None: # noqa: A002
def test_license(tmp_path: Path, license: str = "AGPL-3") -> None:
assert _m(tmp_path, license=license)["license"] == license


Expand Down

0 comments on commit ea0f66a

Please sign in to comment.