snakemake-interface-common 1.2.0__tar.gz → 1.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: snakemake-interface-common
3
- Version: 1.2.0
3
+ Version: 1.3.1
4
4
  Summary: Common functions and classes for Snakemake and its plugins
5
5
  Author: Johannes Koester
6
6
  Author-email: johannes.koester@uni-due.de
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "snakemake-interface-common"
3
- version = "1.2.0"
3
+ version = "1.3.1"
4
4
  description = "Common functions and classes for Snakemake and its plugins"
5
5
  authors = ["Johannes Koester <johannes.koester@uni-due.de>"]
6
6
  readme = "README.md"
@@ -0,0 +1,38 @@
1
+ from enum import Enum
2
+ from typing import List, Set, TypeVar, Union
3
+
4
+ TSettingsEnumBase = TypeVar("TSettingsEnumBase", bound="SettingsEnumBase")
5
+
6
+
7
+ class SettingsEnumBase(Enum):
8
+ @classmethod
9
+ def choices(cls) -> List[str]:
10
+ return sorted(item.item_to_choice() for item in cls)
11
+
12
+ @classmethod
13
+ def all(cls) -> Set[TSettingsEnumBase]:
14
+ return {item for item in cls}
15
+
16
+ @classmethod
17
+ def parse_choices_list(self, choices: List[str]) -> List[TSettingsEnumBase]:
18
+ return self._parse_choices_into(choices, list)
19
+
20
+ @classmethod
21
+ def parse_choices_set(self, choices: List[str]) -> Set[TSettingsEnumBase]:
22
+ return self._parse_choices_into(choices, set)
23
+
24
+ @classmethod
25
+ def _parse_choices_into(
26
+ cls, choices: str, container: Union[List, Set]
27
+ ) -> List[TSettingsEnumBase]:
28
+ return container(cls.parse_choice(choice) for choice in choices)
29
+
30
+ @classmethod
31
+ def parse_choice(cls, choice: str) -> TSettingsEnumBase:
32
+ return cls[choice.replace("-", "_").upper()]
33
+
34
+ def item_to_choice(self) -> str:
35
+ return self.name.replace("_", "-").lower()
36
+
37
+ def __str__(self):
38
+ return self.item_to_choice()
@@ -1,47 +0,0 @@
1
- from abc import ABC, abstractmethod
2
- from enum import Enum
3
- from typing import List, Self, Set
4
-
5
-
6
- class ParseChoicesType(Enum):
7
- SET = 0
8
- LIST = 1
9
-
10
-
11
- class SettingsEnumBase(ABC):
12
- parse_choices_type: ParseChoicesType = ParseChoicesType.SET
13
-
14
- @classmethod
15
- def choices(cls) -> List[str]:
16
- return sorted(item.item_to_choice() for item in cls)
17
-
18
- @classmethod
19
- def all(cls) -> Set[Self]:
20
- return {item for item in cls}
21
-
22
- @classmethod
23
- def parse_choices(cls, choices: str) -> List[Self]:
24
- container = set if cls.parse_choices_type == ParseChoicesType.SET else list
25
- return container(cls.parse_choice(choice) for choice in choices)
26
-
27
- @classmethod
28
- def parse_choice(cls, choice: str) -> Self:
29
- return choice.replace("-", "_").upper()
30
-
31
- def item_to_choice(self) -> str:
32
- return self.name.replace("_", "-").lower()
33
-
34
- def __str__(self):
35
- return self.item_to_choice()
36
-
37
- @abstractmethod
38
- def __iter__(self):
39
- ...
40
-
41
- @abstractmethod
42
- def name(self) -> str:
43
- ...
44
-
45
- @abstractmethod
46
- def value(self) -> str:
47
- ...