Skip to content

Commit a82888e

Browse files
committed
wip
1 parent b8c685e commit a82888e

File tree

8 files changed

+48
-16
lines changed

8 files changed

+48
-16
lines changed

.copier-answers.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changes here will be overwritten by Copier
2-
_commit: v0.0.31
2+
_commit: v0.0.31-2-g117b721
33
_src_path: gh:LabAutomationAndScreening/copier-base-template.git
44
description: Copier template for creating Python libraries and executables
55
python_ci_versions:

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@
5959
"initializeCommand": "sh .devcontainer/initialize-command.sh",
6060
"onCreateCommand": "sh .devcontainer/on-create-command.sh",
6161
"postStartCommand": "sh .devcontainer/post-start-command.sh"
62-
// Devcontainer context hash (do not manually edit this, it's managed by a pre-commit hook): bbebc7c9
62+
// Devcontainer context hash (do not manually edit this, it's managed by a pre-commit hook): 2308a2ae # spellchecker:disable-line
6363
}

.github/workflows/hash_git_files.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
" // Devcontainer context hash (do not manually edit this, it's managed by a pre-commit hook): "
1111
)
1212

13+
DEVCONTAINER_COMMENT_LINE_SUFFIX = (
14+
" # spellchecker:disable-line" # the typos hook can sometimes mess with the hash without this
15+
)
16+
1317

1418
def get_tracked_files(repo_path: Path) -> list[str]:
1519
"""Return a list of files tracked by Git in the given repository folder, using the 'git ls-files' command."""
@@ -76,9 +80,13 @@ def find_devcontainer_hash_line(lines: list[str]) -> tuple[int, str | None]:
7680
for i in range(len(lines) - 1, -1, -1):
7781
if lines[i].strip() == "}":
7882
# Check the line above it
79-
if i > 0 and lines[i - 1].startswith(DEVCONTAINER_COMMENT_LINE_PREFIX):
80-
current_hash = lines[i - 1].split(": ", 1)[1].strip()
81-
return i - 1, current_hash
83+
if i > 0:
84+
above_line = lines[i - 1]
85+
if above_line.startswith(DEVCONTAINER_COMMENT_LINE_PREFIX):
86+
part_after_prefix = above_line.split(": ", 1)[1]
87+
part_before_suffix = part_after_prefix.split("#")[0]
88+
current_hash = part_before_suffix.strip()
89+
return i - 1, current_hash
8290
return i, None
8391
return -1, None
8492

@@ -102,12 +110,13 @@ def update_devcontainer_context_hash(devcontainer_json_file: Path, new_hash: str
102110
lines = file.readlines()
103111

104112
line_index, current_hash = find_devcontainer_hash_line(lines)
113+
new_hash_line = f"{DEVCONTAINER_COMMENT_LINE_PREFIX}{new_hash}{DEVCONTAINER_COMMENT_LINE_SUFFIX}\n"
105114
if current_hash is not None:
106115
# Replace the old hash with the new hash
107-
lines[line_index] = f"{DEVCONTAINER_COMMENT_LINE_PREFIX}{new_hash}\n"
116+
lines[line_index] = new_hash_line
108117
else:
109118
# Insert the new hash line above the closing `}`
110-
lines.insert(line_index, f"{DEVCONTAINER_COMMENT_LINE_PREFIX}{new_hash}\n")
119+
lines.insert(line_index, new_hash_line)
111120

112121
# Write the updated lines back to the file
113122
with devcontainer_json_file.open("w", encoding="utf-8") as file:

_typos.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
[default]
2+
extend-ignore-re = [
3+
# Line ignore with trailing: # spellchecker:disable-line
4+
"(?Rm)^.*(#|//)\\s*spellchecker:disable-line$"
5+
]
6+
17
[default.extend-words]
28
# Words managed by the base template
39
# `astroid` is the name of a python library, and it is used in pylint configuration. should not be corrected to asteroid

extensions/context.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def hook(self, context: dict[Any, Any]) -> dict[Any, Any]:
5252
context["gha_setup_node"] = "v4.3.0"
5353
context["gha_action_gh_release"] = "v2.2.1"
5454
context["gha_mutex"] = "1ebad517141198e08d47cf72f3c0975316620a65 # v1.0.0-alpha.10"
55+
context["gha_pypi_publish"] = v1.12.4"
56+
context["gha_sleep"] = "v2.0.3"
5557
context["gha_linux_runner"] = "ubuntu-24.04"
5658
context["gha_windows_runner"] = "windows-2025"
5759

template/.github/workflows/hash_git_files.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
" // Devcontainer context hash (do not manually edit this, it's managed by a pre-commit hook): "
1111
)
1212

13+
DEVCONTAINER_COMMENT_LINE_SUFFIX = (
14+
" # spellchecker:disable-line" # the typos hook can sometimes mess with the hash without this
15+
)
16+
1317

1418
def get_tracked_files(repo_path: Path) -> list[str]:
1519
"""Return a list of files tracked by Git in the given repository folder, using the 'git ls-files' command."""
@@ -76,9 +80,13 @@ def find_devcontainer_hash_line(lines: list[str]) -> tuple[int, str | None]:
7680
for i in range(len(lines) - 1, -1, -1):
7781
if lines[i].strip() == "}":
7882
# Check the line above it
79-
if i > 0 and lines[i - 1].startswith(DEVCONTAINER_COMMENT_LINE_PREFIX):
80-
current_hash = lines[i - 1].split(": ", 1)[1].strip()
81-
return i - 1, current_hash
83+
if i > 0:
84+
above_line = lines[i - 1]
85+
if above_line.startswith(DEVCONTAINER_COMMENT_LINE_PREFIX):
86+
part_after_prefix = above_line.split(": ", 1)[1]
87+
part_before_suffix = part_after_prefix.split("#")[0]
88+
current_hash = part_before_suffix.strip()
89+
return i - 1, current_hash
8290
return i, None
8391
return -1, None
8492

@@ -102,12 +110,13 @@ def update_devcontainer_context_hash(devcontainer_json_file: Path, new_hash: str
102110
lines = file.readlines()
103111

104112
line_index, current_hash = find_devcontainer_hash_line(lines)
113+
new_hash_line = f"{DEVCONTAINER_COMMENT_LINE_PREFIX}{new_hash}{DEVCONTAINER_COMMENT_LINE_SUFFIX}\n"
105114
if current_hash is not None:
106115
# Replace the old hash with the new hash
107-
lines[line_index] = f"{DEVCONTAINER_COMMENT_LINE_PREFIX}{new_hash}\n"
116+
lines[line_index] = new_hash_line
108117
else:
109118
# Insert the new hash line above the closing `}`
110-
lines.insert(line_index, f"{DEVCONTAINER_COMMENT_LINE_PREFIX}{new_hash}\n")
119+
lines.insert(line_index, new_hash_line)
111120

112121
# Write the updated lines back to the file
113122
with devcontainer_json_file.open("w", encoding="utf-8") as file:

template/.github/workflows/publish.yaml.jinja

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ jobs:
171171

172172
{% endraw %}{% else %}{% raw %}
173173
- name: Publish distribution to Test PyPI
174-
uses: pypa/gh-action-pypi-publish@v1.12.4
174+
uses: pypa/gh-action-pypi-publish@{% endraw %}{{ gha_pypi_publish }}{% raw %}
175175
with:
176176
attestations: false
177177
repository-url: https://test.pypi.org/legacy/
@@ -189,7 +189,7 @@ jobs:
189189
python-version: {% endraw %}{{ python_version }}{% raw %}
190190
{% endraw %}{% if python_package_registry == "PyPI" %}{% raw %}
191191
- name: Sleep to allow PyPI Index to update before proceeding to the next step
192-
uses: juliangruber/sleep-action@v2.0.3
192+
uses: juliangruber/sleep-action@{% endraw %}{{ gha_sleep }}{% raw %}
193193
with:
194194
time: 60s{% endraw %}{% endif %}{% raw %}
195195
- name: Install from staging registry
@@ -245,7 +245,7 @@ jobs:
245245

246246
{% endraw %}{% else %}{% raw %}
247247
- name: Publish distribution to PyPI
248-
uses: pypa/gh-action-pypi-publish@v1.12.4
248+
uses: pypa/gh-action-pypi-publish@{% endraw %}{{ gha_pypi_publish }}{% raw %}
249249
with:
250250
attestations: false{% endraw %}{% endif %}{% raw %}
251251

@@ -261,7 +261,7 @@ jobs:
261261
python-version: {% endraw %}{{ python_version }}{% raw %}
262262
{% endraw %}{% if python_package_registry == "PyPI" %}{% raw %}
263263
- name: Sleep to allow PyPI Index to update before proceeding to the next step
264-
uses: juliangruber/sleep-action@v2.0.3
264+
uses: juliangruber/sleep-action@{% endraw %}{{ gha_sleep }}{% raw %}
265265
with:
266266
time: 60s{% endraw %}{% endif %}{% raw %}
267267
- name: Install from primary registry

template/_typos.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
[default]
2+
extend-ignore-re = [
3+
# Line ignore with trailing: # spellchecker:disable-line
4+
"(?Rm)^.*(#|//)\\s*spellchecker:disable-line$"
5+
]
6+
17
[default.extend-words]
28
# Words managed by the base template
39
# `astroid` is the name of a python library, and it is used in pylint configuration. should not be corrected to asteroid

0 commit comments

Comments
 (0)