|
27 | 27 | from typing import SupportsIndex |
28 | 28 |
|
29 | 29 |
|
| 30 | +def main() -> None: |
| 31 | + """Run the migration steps.""" |
| 32 | + # Add a separation line like this one after each migration step. |
| 33 | + print("=" * 72) |
| 34 | + |
| 35 | + |
30 | 36 | def apply_patch(patch_content: str) -> None: |
31 | 37 | """Apply a patch using the patch utility.""" |
32 | 38 | subprocess.run(["patch", "-p1"], input=patch_content.encode(), check=True) |
@@ -92,132 +98,6 @@ def replace_file_contents_atomically( # noqa; DOC501 |
92 | 98 | raise |
93 | 99 |
|
94 | 100 |
|
95 | | -def add_pylint_checks() -> None: |
96 | | - """Add new pylint checks to the project.""" |
97 | | - pyproject_toml = Path("pyproject.toml") |
98 | | - print( |
99 | | - f"{pyproject_toml}: Skip some flaky pylint checks that are checked better by mypy." |
100 | | - ) |
101 | | - marker = ' "no-member",\n' |
102 | | - pyproject_toml_content = pyproject_toml.read_text(encoding="utf-8") |
103 | | - if pyproject_toml_content.find(marker) == -1: |
104 | | - manual_step( |
105 | | - f"""\ |
106 | | -{pyproject_toml}: We couldn't find the marker {marker!r} in the file. |
107 | | -Please add the following lines to the file manually in the |
108 | | -`[tool.pylint.messages_control]` section, under the `disable` key (ideally below other |
109 | | -checks that are disabled because `mypy` already checks them) if they are missing: |
110 | | - "no-name-in-module", |
111 | | - "possibly-used-before-assignment", |
112 | | -""" |
113 | | - ) |
114 | | - return |
115 | | - |
116 | | - replacement = "" |
117 | | - if pyproject_toml_content.find("possibly-used-before-assignment") == -1: |
118 | | - replacement += ' "possibly-used-before-assignment",\n' |
119 | | - if pyproject_toml_content.find("no-name-in-module") == -1: |
120 | | - replacement += ' "no-name-in-module",\n' |
121 | | - |
122 | | - if not replacement: |
123 | | - print(f"{pyproject_toml}: seems to be already up-to-date.") |
124 | | - return |
125 | | - |
126 | | - replace_file_contents_atomically( |
127 | | - pyproject_toml, marker, marker + replacement, content=pyproject_toml_content |
128 | | - ) |
129 | | - |
130 | | - |
131 | | -def fix_default_fixture_scope() -> None: |
132 | | - """Fix the default scope of fixtures to 'function'.""" |
133 | | - pyproject_toml = Path("pyproject.toml") |
134 | | - print(f"{pyproject_toml}: Fix the default scope of fixtures to 'function'.") |
135 | | - marker = 'asyncio_mode = "auto"\n' |
136 | | - pyproject_toml_content = pyproject_toml.read_text(encoding="utf-8") |
137 | | - if pyproject_toml_content.find(marker) == -1: |
138 | | - manual_step( |
139 | | - f"""\ |
140 | | -{pyproject_toml}: We couldn't find the marker {marker!r} in the file. |
141 | | -Please add the following line to the file manually in the |
142 | | -`[tool.pytest.ini_options]` section if it is missing: |
143 | | -asyncio_default_fixture_loop_scope = "function" |
144 | | -""" |
145 | | - ) |
146 | | - return |
147 | | - |
148 | | - replacement = 'asyncio_default_fixture_loop_scope = "function"\n' |
149 | | - if pyproject_toml_content.find(replacement) >= 0: |
150 | | - print(f"{pyproject_toml}: seems to be already up-to-date.") |
151 | | - return |
152 | | - replace_file_contents_atomically( |
153 | | - pyproject_toml, marker, marker + replacement, content=pyproject_toml_content |
154 | | - ) |
155 | | - |
156 | | - |
157 | | -def main() -> None: |
158 | | - """Run the migration steps.""" |
159 | | - # Dependabot patch |
160 | | - dependabot_yaml = Path(".github/dependabot.yml") |
161 | | - print(f"{dependabot_yaml}: Add new grouping for actions/*-artifact updates.") |
162 | | - if dependabot_yaml.read_text(encoding="utf-8").find("actions/*-artifact") == -1: |
163 | | - apply_patch( |
164 | | - """\ |
165 | | ---- a/.github/dependabot.yml |
166 | | -+++ b/.github/dependabot.yml |
167 | | -@@ -39,3 +39,11 @@ updates: |
168 | | - labels: |
169 | | - - "part:tooling" |
170 | | - - "type:tech-debt" |
171 | | -+ groups: |
172 | | -+ compatible: |
173 | | -+ update-types: |
174 | | -+ - "minor" |
175 | | -+ - "patch" |
176 | | -+ artifacts: |
177 | | -+ patterns: |
178 | | -+ - "actions/*-artifact" |
179 | | -""" |
180 | | - ) |
181 | | - else: |
182 | | - print(f"{dependabot_yaml}: seems to be already up-to-date.") |
183 | | - print("=" * 72) |
184 | | - |
185 | | - # Fix labeler configuration |
186 | | - labeler_yml = ".github/labeler.yml" |
187 | | - print(f"{labeler_yml}: Fix the labeler configuration example.") |
188 | | - replace_file_contents_atomically( |
189 | | - labeler_yml, "all-glob-to-all-file", "all-globs-to-all-files" |
190 | | - ) |
191 | | - print("=" * 72) |
192 | | - |
193 | | - # Add new pylint checks |
194 | | - add_pylint_checks() |
195 | | - print("=" * 72) |
196 | | - |
197 | | - # Remove redundant --platform from the dockerfile |
198 | | - dockerfile = Path(".github/containers/test-installation/Dockerfile") |
199 | | - print(f"{dockerfile}: Removing redundant --platform.") |
200 | | - if dockerfile.is_file(): |
201 | | - replace_file_contents_atomically( |
202 | | - dockerfile, "--platform=${TARGETPLATFORM} ", "" |
203 | | - ) |
204 | | - else: |
205 | | - print(f"{dockerfile}: Not found.") |
206 | | - print("=" * 72) |
207 | | - |
208 | | - # Make sure `edit_uri` points to the default branch |
209 | | - manual_step( |
210 | | - "Make sure that the `edit_uri` in the `mkdocs.yml` file points to the default branch." |
211 | | - ) |
212 | | - print("=" * 72) |
213 | | - |
214 | | - # Fix the default scope of fixtures to 'function' |
215 | | - fix_default_fixture_scope() |
216 | | - |
217 | | - # Add a separation line like this one after each migration step. |
218 | | - print("=" * 72) |
219 | | - |
220 | | - |
221 | 101 | def manual_step(message: str) -> None: |
222 | 102 | """Print a manual step message in yellow.""" |
223 | 103 | print(f"\033[0;33m>>> {message}\033[0m") |
|
0 commit comments