Skip to content

Commit 45a937e

Browse files
committed
fix(windows): move helpers from sh to py
1 parent 4b3aaff commit 45a937e

6 files changed

Lines changed: 86 additions & 37 deletions

File tree

{{cookiecutter.project_name}}/Taskfile.yml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ vars:
1818
VERSION:
1919
sh: "{{ '{{.RUN_SCRIPT}}' }} python -c \"import sys; sys.path.insert(0, 'src'); from {{ '{{.PROJECT_SLUG}}' }} import __version__; print(__version__)\""
2020
LOCAL_PLATFORM:
21-
sh: "bash {{ '{{.SCRIPTS_DIR}}' }}/get_platform.sh"
21+
sh: "{{ '{{.RUN_SCRIPT}}' }} {{ '{{.SCRIPTS_DIR}}' }}/get_platform.py"
2222
# Use PLATFORM if specified, otherwise use LOCAL_PLATFORM
2323
PLATFORM: '{{ '{{if .PLATFORM}}' }}{{ '{{.PLATFORM}}' }}{{ '{{else}}' }}{{ '{{.LOCAL_PLATFORM}}' }}{{ '{{end}}' }}'
2424
# Output redirect based on CI environment
@@ -88,7 +88,7 @@ tasks:
8888
TIMESTAMP:
8989
sh: '{{ '{{.RUN_SCRIPT}}' }} {{ '{{.SCRIPTS_DIR}}' }}/get_rfc3339_timestamp.py'
9090
EPOCH:
91-
sh: 'bash {{ '{{.SCRIPTS_DIR}}' }}/get_epoch.sh'
91+
sh: '{{ '{{.RUN_SCRIPT}}' }} {{ '{{.SCRIPTS_DIR}}' }}/get_epoch.py'
9292
COMMIT_HASH:
9393
sh: git rev-parse HEAD
9494
BUILD_PLATFORM: '{{ '{{if eq .PLATFORM "all"}}' }}{{ '{{.SUPPORTED_PLATFORMS}}' }}{{ '{{else if .PLATFORM}}' }}{{ '{{.PLATFORM}}' }}{{ '{{else}}' }}{{ '{{.LOCAL_PLATFORM}}' }}{{ '{{end}}' }}'
@@ -187,18 +187,7 @@ tasks:
187187
clean:
188188
desc: Clean up build artifacts, cache files/directories, temp files, etc.
189189
cmds:
190-
- rm -rf .pytest_cache
191-
- rm -rf htmlcov
192-
- rm -rf .coverage
193-
- rm -rf dist
194-
- rm -rf build
195-
- rm -rf *.egg-info
196-
- rm -f sbom.*.json
197-
- rm -f vulns.*.json
198-
- rm -f license-check.*.json
199-
- rm -f {{ cookiecutter.github_org }}_{{ cookiecutter.project_slug }}_*_*.tar
200-
- find . -type d -name __pycache__ -exec rm -rf {} + || true
201-
- find . -type f -name '*.pyc' -delete || true
190+
- '{{ '{{.RUN_SCRIPT}}' }} {{ '{{.SCRIPTS_DIR}}' }}/clean.py'
202191

203192
release:
204193
desc: Cut a project release
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
"""Cross-platform cleanup of build artifacts, cache files, and temp files."""
3+
4+
import glob
5+
import shutil
6+
import sys
7+
from pathlib import Path
8+
9+
10+
def main() -> int:
11+
"""Remove build artifacts, cache directories, and temporary files."""
12+
root = Path(".")
13+
14+
# Paths to remove (may be files or directories)
15+
for name in [".pytest_cache", "htmlcov", ".coverage", "dist", "build"]:
16+
path = root / name
17+
if path.is_dir():
18+
shutil.rmtree(path)
19+
elif path.is_file():
20+
path.unlink()
21+
22+
# Glob patterns for directories
23+
for path in glob.glob("*.egg-info"):
24+
shutil.rmtree(path)
25+
26+
# Glob patterns for files
27+
for pattern in [
28+
"sbom.*.json",
29+
"vulns.*.json",
30+
"license-check.*.json",
31+
"{{ cookiecutter.github_org }}_{{ cookiecutter.project_slug }}_*_*.tar",
32+
]:
33+
for path in glob.glob(pattern):
34+
Path(path).unlink()
35+
36+
# Recursively remove __pycache__ directories
37+
for path in root.rglob("__pycache__"):
38+
if path.is_dir():
39+
shutil.rmtree(path)
40+
41+
# Recursively remove .pyc files
42+
for path in root.rglob("*.pyc"):
43+
path.unlink()
44+
45+
return 0
46+
47+
48+
if __name__ == "__main__":
49+
sys.exit(main())
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env python3
2+
"""Get the current Unix epoch timestamp."""
3+
4+
import time
5+
6+
print(int(time.time()))

{{cookiecutter.project_name}}/scripts/get_epoch.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
"""Get the Docker platform string for the current machine.
3+
4+
Always uses 'linux' as the OS since container builds target Linux.
5+
"""
6+
7+
import platform
8+
import sys
9+
10+
# Always use linux for container builds
11+
os_name = "linux"
12+
machine = platform.machine().lower()
13+
14+
# Inspired by https://github.com/containerd/containerd/blob/e0912c068b131b33798ae45fd447a1624a6faf0a/platforms/database.go#L76
15+
arch_map = {
16+
# AMD64
17+
"x86_64": "amd64",
18+
"amd64": "amd64",
19+
# ARM64
20+
"aarch64": "arm64",
21+
"arm64": "arm64",
22+
}
23+
24+
if machine not in arch_map:
25+
print(f"Unsupported architecture: {machine}", file=sys.stderr)
26+
sys.exit(1)
27+
28+
print(f"{os_name}/{arch_map[machine]}")

{{cookiecutter.project_name}}/scripts/get_platform.sh

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)