|
15 | 15 | import functools |
16 | 16 | import importlib |
17 | 17 | import inspect |
18 | | -import operator |
19 | | -import re |
20 | | -from enum import Enum |
21 | 18 | from functools import lru_cache |
22 | | -from typing import Callable |
23 | 19 |
|
24 | 20 | from packaging.requirements import Requirement |
25 | | -from packaging.version import Version |
26 | 21 |
|
27 | 22 |
|
28 | 23 | class Extras(enum.Enum): |
@@ -98,39 +93,6 @@ def __getattribute__(cls, key): |
98 | 93 | raise_if_package_not_available(backend) |
99 | 94 |
|
100 | 95 |
|
101 | | -class VersionComparison(Enum): |
102 | | - EQUAL = operator.eq |
103 | | - NOT_EQUAL = operator.ne |
104 | | - GREATER_THAN = operator.gt |
105 | | - LESS_THAN = operator.lt |
106 | | - GREATER_THAN_OR_EQUAL = operator.ge |
107 | | - LESS_THAN_OR_EQUAL = operator.le |
108 | | - |
109 | | - @staticmethod |
110 | | - def from_string(version_string: str) -> Callable[[int | Version, int | Version], bool]: |
111 | | - string_to_operator = { |
112 | | - "=": VersionComparison.EQUAL.value, |
113 | | - "==": VersionComparison.EQUAL.value, |
114 | | - "!=": VersionComparison.NOT_EQUAL.value, |
115 | | - ">": VersionComparison.GREATER_THAN.value, |
116 | | - "<": VersionComparison.LESS_THAN.value, |
117 | | - ">=": VersionComparison.GREATER_THAN_OR_EQUAL.value, |
118 | | - "<=": VersionComparison.LESS_THAN_OR_EQUAL.value, |
119 | | - } |
120 | | - |
121 | | - return string_to_operator[version_string] |
122 | | - |
123 | | - |
124 | | -@lru_cache |
125 | | -def split_package_version(package_version_str) -> tuple[str, str, str]: |
126 | | - pattern = r"([a-zA-Z0-9_-]+)([!<>=~]+)([0-9.]+)" |
127 | | - match = re.match(pattern, package_version_str) |
128 | | - if match: |
129 | | - return (match.group(1), match.group(2), match.group(3)) |
130 | | - else: |
131 | | - raise ValueError(f"Invalid package version string: {package_version_str}") |
132 | | - |
133 | | - |
134 | 96 | def requires(*backends): |
135 | 97 | """ |
136 | 98 | Decorator to raise an ImportError if the decorated object (function or class) requires a dependency |
|
0 commit comments