From 6b7517919918faf72698aa4e2c135f2b59ca9465 Mon Sep 17 00:00:00 2001 From: A_D Date: Mon, 26 Oct 2020 18:48:28 +0200 Subject: [PATCH] switched to using SimpleSpec for constraints --- docs/Killswitches.md | 10 +++++----- killswitch.py | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/Killswitches.md b/docs/Killswitches.md index 5ea69268..f4ea5145 100644 --- a/docs/Killswitches.md +++ b/docs/Killswitches.md @@ -14,10 +14,10 @@ Killswitches are stored in a JSON file that is queried by EDMC on startup. The f The `kill_switches` array contains kill switch objects. Each contains two fields: -| Key | Type | Description | -| --------: | :----------------: | :---------------------------------------------------------------------- | -| `version` | `semantic version` | The version of EDMC these kill switches apply to (Must be valid semver) | -| `kills` | `Dict[str, str]` | The different keys to disable, and the reason for the disable | +| Key | Type | Description | +| --------: | :--------------: | :--------------------------------------------------------------------------- | +| `version` | `version spec` | The version of EDMC these kill switches apply to (Must be valid semver spec) | +| `kills` | `Dict[str, str]` | The different keys to disable, and the reason for the disable | An example follows: ```json @@ -37,7 +37,7 @@ An example follows: ### Versions -Versions are checked using equality checks on `semantic_version.Version` instances. Meaning that **all** fields are checked (ie, Major, Minor, Patch, Prerelease, and Build). +Versions are checked using contains checks on `semantic_version.SimpleSpec` instances. ## Plugin support diff --git a/killswitch.py b/killswitch.py index da56abd6..b2336111 100644 --- a/killswitch.py +++ b/killswitch.py @@ -18,7 +18,7 @@ _current_version: semantic_version.Version = semantic_version.Version(config.app class KillSwitch(NamedTuple): """One version's set of kill switches.""" - version: semantic_version.Version + version: semantic_version.SimpleSpec kills: Dict[str, str] @@ -44,7 +44,7 @@ class KillSwitchSet: :return: a namedtuple indicating status and reason, if any """ for ks in self.kill_switches: - if version != ks.version: + if version not in ks.version: continue return DisabledResult(id in ks.kills, ks.kills.get(id, "")) @@ -120,7 +120,7 @@ def parse_kill_switches(data: KILL_SWITCH_JSON_DICT) -> List[KillSwitch]: for idx, ks_data in enumerate(kill_switches): try: - ver = semantic_version.Version(ks_data['version']) + ver = semantic_version.SimpleSpec(ks_data['version']) except ValueError as e: logger.warning(f'could not parse killswitch idx {idx}: {e}')