2525#
2626
2727# stdlib
28+ import platform
2829import re
2930import sys
3031from typing import TYPE_CHECKING , Any , List , NamedTuple , Pattern , Union
3536if TYPE_CHECKING :
3637
3738 # stdlib
38- from sys import _version_info as VersionInfo
39+ from sys import _version_info as VersionInfo # pragma: no cover (typing only)
3940
4041__author__ : str = "Dominic Davis-Foster"
4142__copyright__ : str = "2020 Dominic Davis-Foster"
@@ -65,12 +66,16 @@ class Version(NamedTuple):
6566 serial : str
6667
6768
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 ]:
6970 """
7071 Generate a list of regular expressions to match all valid ignores for the given Python version.
7172
7273 :param version_tuple: The Python version.
7374 :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
7479
7580 :return: List of regular expressions.
7681 """
@@ -84,15 +89,19 @@ def make_regexes(version_tuple: Union["Version", "VersionInfo"]) -> List[Pattern
8489 less_equal_versions = [str (version_tuple .minor ), * less_than_versions ]
8590 exact_versions = [str (version_tuple .minor )]
8691
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+
8796 # Add regular expressions for relevant python versions
8897 # We do it with re.compile to get the syntax highlighting in PyCharm
8998 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 } .* \)" ),
96105 ]
97106
98107 return excludes
@@ -120,7 +129,7 @@ def configure(self, config: Any) -> None:
120129 # Remove standard "pragma: no cover" regex
121130 config .exclude_list .remove (regex_main )
122131
123- excludes = make_regexes (sys .version_info )
132+ excludes = make_regexes (sys .version_info , platform . system (), platform . python_implementation () )
124133 for exc_pattern in excludes :
125134 config .exclude_list .append (exc_pattern .pattern )
126135
0 commit comments