Skip to content

Commit e0eeebd

Browse files
committed
python
1 parent 2f57b39 commit e0eeebd

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
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.7-40-gba2c9c5
2+
_commit: v0.0.7-41-ge3d7a12
33
_src_path: gh:LabAutomationAndScreening/copier-base-template.git
44
description: Copier template for creating Python libraries and executables
55
python_ci_versions:

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ jobs:
113113
UV_NO_CACHE: 'true'
114114
run: |
115115
# Remove any specification of a Python repository having a default other than PyPI...because in this CI pipeline we can only install from PyPI
116-
find . -maxdepth 3 -type f -name "pyproject.toml" -exec sed -i '/^\[\[tool\.uv\.index\]\]/, /^\[\[/{s/^\(default = true\)$/\1\nname = "pypi"\nurl = "https:\/\/pypi.org\/simple\/"\n[[tool.uv.index]]/}' {} +
116+
python .github/workflows/replace_private_package_registries.py
117117
cat pyproject.toml
118118
sh .devcontainer/manual-setup-deps.sh ${{ matrix.python-version }} --skip-lock
119119
# Add everything to git so that pre-commit recognizes the files and runs on them
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""Update any project files that point to a private package registry to use public ones.
2+
3+
Since the CI pipelines for testing these copier templates don't have access to private registries, we can't test installing from them as part of CI.
4+
5+
Seems minimal risk, since the only problem we'd be missing is if the pyproject.toml (or similar config files) had syntax errors that would have been
6+
caught by pre-commit.
7+
"""
8+
9+
import re
10+
from pathlib import Path
11+
12+
13+
def process_file(file_path: Path):
14+
# Read the entire file content
15+
content = file_path.read_text()
16+
17+
# Regex to match a block starting with [[tool.uv.index]]
18+
# until the next block header (a line starting with [[) or the end of the file.
19+
pattern = re.compile(r"(\[\[tool\.uv\.index\]\].*?)(?=\n\[\[|$)", re.DOTALL)
20+
21+
# Find all uv.index blocks.
22+
blocks = pattern.findall(content)
23+
24+
# Check if any block contains "default = true"
25+
if not any("default = true" in block for block in blocks):
26+
print(f"No changes in: {file_path}")
27+
return
28+
29+
# If at least one block contains "default = true", remove all uv.index blocks.
30+
new_content = pattern.sub("", content)
31+
32+
# Ensure file ends with a newline before appending the new block.
33+
if not new_content.endswith("\n"):
34+
new_content += "\n"
35+
36+
# Append the new block.
37+
new_block = '[[tool.uv.index]]\nname = "pypi"\nurl = "https://pypi.org/simple/"\n'
38+
new_content += new_block
39+
40+
# Write the updated content back to the file.
41+
_ = file_path.write_text(new_content)
42+
print(f"Updated file: {file_path}")
43+
44+
45+
def main():
46+
base_dir = Path(".")
47+
# Use rglob to find all pyproject.toml files recursively.
48+
for file_path in base_dir.rglob("pyproject.toml"):
49+
# Check if the file is at most two levels deep.
50+
# The relative path's parts count should be <= 3 (e.g. "pyproject.toml" is 1 part,
51+
# "subdir/pyproject.toml" is 2 parts, and "subdir/subsubdir/pyproject.toml" is 3 parts).
52+
if len(file_path.relative_to(base_dir).parts) <= 3:
53+
process_file(file_path)
54+
55+
56+
if __name__ == "__main__":
57+
main()

0 commit comments

Comments
 (0)