25
25
#
26
26
27
27
# stdlib
28
+ import platform
28
29
import re
29
30
import sys
30
31
from typing import TYPE_CHECKING , Any , List , NamedTuple , Pattern , Union
35
36
if TYPE_CHECKING :
36
37
37
38
# stdlib
38
- from sys import _version_info as VersionInfo
39
+ from sys import _version_info as VersionInfo # pragma: no cover (typing only)
39
40
40
41
__author__ : str = "Dominic Davis-Foster"
41
42
__copyright__ : str = "2020 Dominic Davis-Foster"
@@ -65,12 +66,16 @@ class Version(NamedTuple):
65
66
serial : str
66
67
67
68
68
- def make_regexes (version_tuple : Union ["Version" , "VersionInfo" ]) -> List [Pattern ]:
69
+ def make_regexes (version_tuple : Union ["Version" , "VersionInfo" ], current_platform : str , current_implementation : str ) -> List [Pattern ]:
69
70
"""
70
71
Generate a list of regular expressions to match all valid ignores for the given Python version.
71
72
72
73
:param version_tuple: The Python version.
73
74
:type version_tuple: :class:`~typing.NamedTuple` with the attributes ``major`` and ``minor``.
75
+ :param current_platform:
76
+ :type current_platform: str
77
+ :param current_implementation:
78
+ :type current_implementation: str
74
79
75
80
:return: List of regular expressions.
76
81
"""
@@ -84,15 +89,19 @@ def make_regexes(version_tuple: Union["Version", "VersionInfo"]) -> List[Pattern
84
89
less_equal_versions = [str (version_tuple .minor ), * less_than_versions ]
85
90
exact_versions = [str (version_tuple .minor )]
86
91
92
+ wrong_platforms_string = fr"(?!.*!{ current_platform } )" # (?!.*Windows)(?!.*Darwin)
93
+ wrong_implementations_string = fr"(?!.*!{ current_implementation } )" # (?!.*Windows)(?!.*Darwin)
94
+ # correct_platforms_string = r"(?=\s*(Linux)?)"
95
+
87
96
# Add regular expressions for relevant python versions
88
97
# We do it with re.compile to get the syntax highlighting in PyCharm
89
98
excludes = [
90
- re .compile (fr"{ regex_main } \s*\(<(py|PY|Py)3({ '|' .join (less_than_versions )} )\)" ),
91
- re .compile (fr"{ regex_main } \s*\(<=(py|PY|Py)3({ '|' .join (less_equal_versions )} )\)" ),
92
- re .compile (fr"{ regex_main } \s*\(>(py|PY|Py)3({ '|' .join (greater_than_versions )} )\)" ),
93
- re .compile (fr"{ regex_main } \s*\((py|PY|Py)3({ '|' .join (greater_than_versions )} )\+\)" ),
94
- re .compile (fr"{ regex_main } \s*\(>=(py|PY|Py)3({ '|' .join (greater_equal_versions )} )\)" ),
95
- re .compile (fr"{ regex_main } \s*\((py|PY|Py)3({ '|' .join (exact_versions )} )\)" ),
99
+ re .compile (fr"{ regex_main } \s*\((?=\s* <(py|PY|Py)3({ '|' .join (less_than_versions )} )) { wrong_platforms_string } { wrong_implementations_string } .* \)" ),
100
+ re .compile (fr"{ regex_main } \s*\((?=\s* <=(py|PY|Py)3({ '|' .join (less_equal_versions )} )) { wrong_platforms_string } { wrong_implementations_string } .* \)" ),
101
+ re .compile (fr"{ regex_main } \s*\((?=\s* >(py|PY|Py)3({ '|' .join (greater_than_versions )} )) { wrong_platforms_string } { wrong_implementations_string } .* \)" ),
102
+ re .compile (fr"{ regex_main } \s*\((?=\s*( py|PY|Py)3({ '|' .join (greater_equal_versions )} )\+) { wrong_platforms_string } { wrong_implementations_string } .* \)" ),
103
+ re .compile (fr"{ regex_main } \s*\((?=\s* >=(py|PY|Py)3({ '|' .join (greater_equal_versions )} )) { wrong_platforms_string } { wrong_implementations_string } .* \)" ),
104
+ re .compile (fr"{ regex_main } \s*\((?=\s*( py|PY|Py)3({ '|' .join (exact_versions )} )) { wrong_platforms_string } { wrong_implementations_string } .* \)" ),
96
105
]
97
106
98
107
return excludes
@@ -120,7 +129,7 @@ def configure(self, config: Any) -> None:
120
129
# Remove standard "pragma: no cover" regex
121
130
config .exclude_list .remove (regex_main )
122
131
123
- excludes = make_regexes (sys .version_info )
132
+ excludes = make_regexes (sys .version_info , platform . system (), platform . python_implementation () )
124
133
for exc_pattern in excludes :
125
134
config .exclude_list .append (exc_pattern .pattern )
126
135
0 commit comments