Skip to content

Commit 5c3b1af

Browse files
committed
Allow platforms to be excluded per Python version.
1 parent 6c24585 commit 5c3b1af

File tree

5 files changed

+107
-27
lines changed

5 files changed

+107
-27
lines changed

repo_helper/configuration/python_versions_.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,12 @@ def _is_experimental(version: str) -> bool:
148148
def validator(cls, value: Mapping[str, Any]) -> Dict[str, Dict[str, Any]]: # noqa: D102
149149
output = {}
150150

151+
# this package
152+
from repo_helper.configuration.packaging import platforms
153+
151154
for version, metadata in natsorted((str(k), v) for k, v in value.items() if k):
152155
metadata.setdefault("experimental", cls._is_experimental(version))
156+
metadata.setdefault("platforms", platforms.default)
153157
metadata.setdefault("matrix_exclude", {})
154158

155159
output[version] = metadata

repo_helper/files/ci_cd.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
# this package
3939
from repo_helper.configupdater2 import ConfigUpdater
4040
from repo_helper.configuration import get_tox_python_versions
41+
from repo_helper.configuration.packaging import platforms
4142
from repo_helper.files import management
4243
from repo_helper.files.packaging import DefaultDict
4344
from repo_helper.templates import Environment
@@ -159,7 +160,7 @@ def __init__(self, repo_path: pathlib.Path, templates: Environment):
159160

160161
self._code_file_filter = f"!({code_file_filter:|})"
161162

162-
def get_gh_actions_matrix(self) -> Dict[str, Tuple[str, Optional[str], bool]]:
163+
def get_gh_actions_matrix(self) -> Dict[str, Tuple[str, Optional[str], Dict[str, Any]]]:
163164
"""
164165
Determines the matrix of Python versions used in GitHub Actions.
165166
@@ -172,7 +173,7 @@ def get_gh_actions_matrix(self) -> Dict[str, Tuple[str, Optional[str], bool]]:
172173
tox_py_versions = get_tox_python_versions(config["python_versions"])
173174
third_party_version_matrix = config["third_party_version_matrix"]
174175

175-
output: Dict[str, Tuple[str, Optional[str], bool]] = {}
176+
output: Dict[str, Tuple[str, Optional[str], Dict[str, Any]]] = {}
176177

177178
for (py_version, metadata), gh_py_version, tox_py_version in zip(
178179
python_versions.items(),
@@ -210,7 +211,8 @@ def get_gh_actions_matrix(self) -> Dict[str, Tuple[str, Optional[str], bool]]:
210211
if not (py_version in {"3.6", "pypy36", "3.7", "pypy37"} and config["use_flit"]):
211212
envs.append("build")
212213

213-
output[str(gh_py_version)] = (','.join(envs), None, metadata["experimental"])
214+
metadata.setdefault("platforms", platforms.default)
215+
output[str(gh_py_version)] = (','.join(envs), None, metadata)
214216

215217
return output
216218

@@ -268,11 +270,15 @@ def make_macos(self) -> PathPlus:
268270
for version in gh_actions_versions:
269271
if version in {"pypy-3.7", "3.7", "pypy-3.6", "3.6"}:
270272
gh_actions_versions[version] = (
271-
gh_actions_versions[version][0], "13", gh_actions_versions[version][2]
273+
gh_actions_versions[version][0],
274+
"13",
275+
gh_actions_versions[version][2],
272276
)
273277
else:
274278
gh_actions_versions[version] = (
275-
gh_actions_versions[version][0], "14", gh_actions_versions[version][2]
279+
gh_actions_versions[version][0],
280+
"14",
281+
gh_actions_versions[version][2],
276282
)
277283

278284
ci_file.write_clean(

repo_helper/templates/github_ci.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ jobs:
2828
fail-fast: False
2929
matrix:
3030
config:{% for version in gh_actions_versions %}
31-
{%- set testenvs, os_ver, experimental = gh_actions_versions[version] %}
31+
{%- set testenvs, os_ver, metadata = gh_actions_versions[version] %}
32+
{%- if ci_name in metadata["platforms"] %}
3233
{%- if os_ver %}
33-
- {python-version: "{{ version }}", os-ver: "{{ os_ver }}", testenvs: "{{ testenvs }}", experimental: {{ experimental }}}
34+
- {python-version: "{{ version }}", os-ver: "{{ os_ver }}", testenvs: "{{ testenvs }}", experimental: {{ metadata["experimental"] }}}
3435
{%- else %}
35-
- {python-version: "{{ version }}", testenvs: "{{ testenvs }}", experimental: {{ experimental }}}
36-
{%- endif %}{% endfor %}
36+
- {python-version: "{{ version }}", testenvs: "{{ testenvs }}", experimental: {{ metadata["experimental"] }}}
37+
{%- endif %}{% endif %}{% endfor %}
3738

3839
steps:
3940
- name: Checkout 🛎️

tests/test_config_vars.py

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -602,51 +602,92 @@ def test_success(self):
602602
class Test_python_versions(DictTest):
603603
config_var = python_versions
604604
test_value = {"3.6": {"experimental": True}, "3.7": {}, "pypy3": {"option": "Value"}}
605-
default_value = {"3.8": {"experimental": False, "matrix_exclude": {}}}
605+
default_value = {
606+
"3.8": {
607+
"experimental": False,
608+
"matrix_exclude": {},
609+
"platforms": ["Windows", "macOS", "Linux"],
610+
}
611+
}
606612

607613
def test_success(self):
608614
value = ["3.6", 3.7, "pypy37", "pypy38", "pypy310"]
609615
assert self.config_var.get({self.config_var.__name__: value}) == {
610-
"3.6": {"experimental": False, "matrix_exclude": {}},
611-
"3.7": {"experimental": False, "matrix_exclude": {}},
612-
"pypy37": {"experimental": False, "matrix_exclude": {}},
613-
"pypy38": {"experimental": False, "matrix_exclude": {}},
614-
"pypy310": {"experimental": True, "matrix_exclude": {}},
616+
"3.6": {"experimental": False, "matrix_exclude": {}, "platforms": ["Windows", "macOS", "Linux"]},
617+
"3.7": {"experimental": False, "matrix_exclude": {}, "platforms": ["Windows", "macOS", "Linux"]},
618+
"pypy37": {
619+
"experimental": False,
620+
"matrix_exclude": {},
621+
"platforms": ["Windows", "macOS", "Linux"],
622+
},
623+
"pypy38": {
624+
"experimental": False,
625+
"matrix_exclude": {},
626+
"platforms": ["Windows", "macOS", "Linux"],
627+
},
628+
"pypy310": {
629+
"experimental": True,
630+
"matrix_exclude": {},
631+
"platforms": ["Windows", "macOS", "Linux"],
632+
},
615633
}
616634

617635
value2 = {
618-
"3.6": {"experimental": True, "matrix_exclude": {}},
619-
"3.7": {"experimental": False, "matrix_exclude": {}},
620-
"pypy3": {"option": "Value", "experimental": False, "matrix_exclude": {}}
636+
"3.6": {"experimental": True, "matrix_exclude": {}, "platforms": ["Windows", "macOS", "Linux"]},
637+
"3.7": {"experimental": False, "matrix_exclude": {}, "platforms": ["Windows", "macOS", "Linux"]},
638+
"pypy3": {
639+
"option": "Value",
640+
"experimental": False,
641+
"matrix_exclude": {},
642+
"platforms": ["Windows", "macOS", "Linux"],
643+
}
621644
}
622645
assert self.config_var.get({self.config_var.__name__: self.test_value}) == value2
623646
assert self.config_var.get({self.config_var.__name__: value2}) == value2
624647

625648
assert python_versions.get({"python_deploy_version": 3.8}) == {
626-
"3.8": {"experimental": False, "matrix_exclude": {}},
649+
"3.8": {"experimental": False, "matrix_exclude": {}, "platforms": ["Windows", "macOS", "Linux"]},
627650
}
628651
assert python_versions.get({"python_deploy_version": "3.8"}) == {
629-
"3.8": {"experimental": False, "matrix_exclude": {}},
652+
"3.8": {"experimental": False, "matrix_exclude": {}, "platforms": ["Windows", "macOS", "Linux"]},
630653
}
631654

632655
assert self.config_var.get({self.config_var.__name__: ["3.6", 3.7, "pypy3"]}) == {
633-
"3.6": {"experimental": False, "matrix_exclude": {}},
634-
"3.7": {"experimental": False, "matrix_exclude": {}},
635-
"pypy3": {"experimental": False, "matrix_exclude": {}},
656+
"3.6": {"experimental": False, "matrix_exclude": {}, "platforms": ["Windows", "macOS", "Linux"]},
657+
"3.7": {"experimental": False, "matrix_exclude": {}, "platforms": ["Windows", "macOS", "Linux"]},
658+
"pypy3": {"experimental": False, "matrix_exclude": {}, "platforms": ["Windows", "macOS", "Linux"]},
636659
}
637660
assert self.config_var.get({self.config_var.__name__: ["3.6", "3.7", "pypy3"]}) == {
638-
"3.6": {"experimental": False, "matrix_exclude": {}},
639-
"3.7": {"experimental": False, "matrix_exclude": {}},
640-
"pypy3": {"experimental": False, "matrix_exclude": {}},
661+
"3.6": {"experimental": False, "matrix_exclude": {}, "platforms": ["Windows", "macOS", "Linux"]},
662+
"3.7": {"experimental": False, "matrix_exclude": {}, "platforms": ["Windows", "macOS", "Linux"]},
663+
"pypy3": {"experimental": False, "matrix_exclude": {}, "platforms": ["Windows", "macOS", "Linux"]},
641664
}
642665

666+
assert self.config_var.get({
667+
self.config_var.__name__: {"3.6": {}, "3.7": None, "pypy3": {"platforms": ["macOS", "Linux"]}}
668+
}) == {
669+
"3.6": {
670+
"experimental": False,
671+
"matrix_exclude": {},
672+
"platforms": ["Windows", "macOS", "Linux"]
673+
},
674+
"3.7": {
675+
"experimental": False,
676+
"matrix_exclude": {},
677+
"platforms": ["Windows", "macOS", "Linux"]
678+
},
679+
"pypy3": {"experimental": False, "matrix_exclude": {}, "platforms": ["macOS", "Linux"]},
680+
}
681+
643682
assert self.config_var.get({self.config_var.__name__: {}}) == {}
644683
assert self.config_var.get(self.different_key_value) == self.default_value
645684

646685
assert self.config_var.get() == self.default_value
647686
assert self.config_var.get({}) == self.default_value
648687

649-
expected_3_6 = {"3.6": {"experimental": False, "matrix_exclude": {}}}
688+
expected_3_6 = {
689+
"3.6": {"experimental": False, "matrix_exclude": {}, "platforms": ["Windows", "macOS", "Linux"]}
690+
}
650691
assert self.config_var.get({**self.different_key_value, "python_versions": [3.6]}) == expected_3_6
651692

652693
def test_error_list_int(self):

tests/test_configuration_/test_parse_yaml.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,52 @@ python_versions:
9191
'3.10':
9292
experimental: false
9393
matrix_exclude: {}
94+
platforms:
95+
- Windows
96+
- macOS
97+
- Linux
9498
3.11-dev:
9599
experimental: true
96100
matrix_exclude: {}
101+
platforms:
102+
- Windows
103+
- macOS
104+
- Linux
97105
3.12-dev:
98106
experimental: true
99107
matrix_exclude: {}
108+
platforms:
109+
- Windows
110+
- macOS
111+
- Linux
100112
'3.6':
101113
experimental: false
102114
matrix_exclude: {}
115+
platforms:
116+
- Windows
117+
- macOS
118+
- Linux
103119
'3.7':
104120
experimental: false
105121
matrix_exclude: {}
122+
platforms:
123+
- Windows
124+
- macOS
125+
- Linux
106126
'3.8':
107127
experimental: false
108128
matrix_exclude: {}
129+
platforms:
130+
- Windows
131+
- macOS
132+
- Linux
109133
'3.9':
110134
experimental: false
111135
matrix_exclude: {}
136+
platforms:
137+
- Windows
138+
- macOS
139+
- Linux
112140
repo_name: repo_helper_demo
113141
requires_python: null
114142
rtfd_author: Dominic Davis-Foster

0 commit comments

Comments
 (0)