Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better typing of post_version_strategy_override #82

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
7 changes: 5 additions & 2 deletions src/manifestoo_core/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dataclasses import dataclass
from email.message import Message
from pathlib import Path
from typing import Dict, Iterator, List, Optional, Sequence, Set, Tuple, Union
from typing import Dict, Iterator, List, Literal, Optional, Sequence, Set, Tuple, Union

if sys.version_info >= (3, 8):
from typing import TypedDict
Expand Down Expand Up @@ -37,11 +37,14 @@
r"^odoo(\d{1,2})?[-_]addon[-_](?P<addon_name>[a-zA-Z0-9_-]+)$",
)

PostVersionStrategyOverrideStr = Literal[".N", "none", ".99.devN", "+1.devN"]

__all__ = [
"POST_VERSION_STRATEGY_DOT_N",
"POST_VERSION_STRATEGY_NINETYNINE_DEVN",
"POST_VERSION_STRATEGY_NONE",
"POST_VERSION_STRATEGY_P1_DEVN",
"PostVersionStrategyOverrideStr",
"metadata_from_addon_dir",
"addon_name_to_distribution_name",
"addon_name_to_requirement",
Expand Down Expand Up @@ -79,7 +82,7 @@ class MetadataOptions(TypedDict, total=False):
external_dependencies_only: Optional[bool]
odoo_series_override: Optional[str]
odoo_version_override: Optional[str]
post_version_strategy_override: Optional[str]
post_version_strategy_override: Optional[PostVersionStrategyOverrideStr]


def metadata_from_addon_dir(
Expand Down
13 changes: 7 additions & 6 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
POST_VERSION_STRATEGY_NINETYNINE_DEVN,
POST_VERSION_STRATEGY_NONE,
POST_VERSION_STRATEGY_P1_DEVN,
PostVersionStrategyOverrideStr,
_author_email,
_filter_odoo_addon_dependencies,
_no_nl,
Expand Down Expand Up @@ -54,7 +55,7 @@ def _m( # noqa: PLR0913 too many arguments
external_dependencies_only: Optional[bool] = None,
odoo_series_override: Optional[str] = None,
odoo_version_override: Optional[str] = None,
post_version_strategy_override: Optional[str] = None,
post_version_strategy_override: Optional[PostVersionStrategyOverrideStr] = None,
precomputed_metadata_file: Optional[Path] = None,
) -> Dict[str, Any]:
addon_dir = tmp_path / addon_dir_name
Expand Down Expand Up @@ -554,7 +555,7 @@ def test_git_post_version(
tmp_path: Path,
manifest_version: str,
post_commits: int,
post_version_strategy_override: Optional[str],
post_version_strategy_override: Optional[PostVersionStrategyOverrideStr],
expected_version: str,
) -> None:
addon_dir = _make_git_addon(
Expand Down Expand Up @@ -589,7 +590,7 @@ def test_git_post_version_uncommitted_change(
tmp_path: Path,
manifest_version: str,
post_commits: int,
post_version_strategy_override: str,
post_version_strategy_override: PostVersionStrategyOverrideStr,
expected_version: str,
) -> None:
addon_dir = _make_git_addon(
Expand Down Expand Up @@ -618,7 +619,7 @@ def test_git_post_version_uncommitted_change(
)
def test_git_post_version_bad_manifest_in_history(
tmp_path: Path,
post_version_strategy_override: str,
post_version_strategy_override: PostVersionStrategyOverrideStr,
) -> None:
addon_dir = _make_git_addon(tmp_path, manifest_version="16.0.1.1.0")
addon_dir.joinpath("__manifest__.py").write_text(
Expand Down Expand Up @@ -651,7 +652,7 @@ def test_git_post_version_bad_manifest_in_history(
)
def test_git_post_version_good_manifest_in_history(
tmp_path: Path,
post_version_strategy_override: str,
post_version_strategy_override: PostVersionStrategyOverrideStr,
) -> None:
addon_dir = _make_git_addon(tmp_path, manifest_version="16.0.1.1.0")
addon_dir.joinpath("__manifest__.py").write_text(
Expand Down Expand Up @@ -679,7 +680,7 @@ def test_git_post_version_good_manifest_in_history(
)
def test_git_post_version_no_manifest_in_history(
tmp_path: Path,
post_version_strategy_override: str,
post_version_strategy_override: PostVersionStrategyOverrideStr,
) -> None:
addon_dir = _make_git_addon(tmp_path, manifest_version="16.0.1.1.0")
subprocess.check_call(["git", "rm", "__manifest__.py"], cwd=addon_dir)
Expand Down
Loading