Skip to content

Commit b792156

Browse files
committed
use a single cache with multiplexing
1 parent 51d40bd commit b792156

File tree

4 files changed

+61
-14
lines changed

4 files changed

+61
-14
lines changed

.riot/requirements/c26db9d.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.10
3+
# by the following command:
4+
#
5+
# pip-compile --allow-unsafe --no-annotate .riot/requirements/c26db9d.in
6+
#
7+
attrs==25.3.0
8+
cmake==4.0.3
9+
coverage[toml]==7.9.1
10+
cython==3.1.2
11+
exceptiongroup==1.3.0
12+
hypothesis==6.45.0
13+
iniconfig==2.1.0
14+
lxml==5.4.0
15+
mock==5.2.0
16+
opentracing==2.4.0
17+
packaging==25.0
18+
pluggy==1.6.0
19+
pygments==2.19.1
20+
pytest==8.4.0
21+
pytest-cov==6.2.1
22+
pytest-mock==3.14.1
23+
ruamel-yaml==0.18.14
24+
ruamel-yaml-clib==0.2.12
25+
semantic-version==2.10.0
26+
setuptools-rust==1.11.1
27+
sortedcontainers==2.4.0
28+
tomli==2.2.1
29+
typing-extensions==4.14.0
30+
31+
# The following packages are considered to be unsafe in a requirements file:
32+
setuptools==80.9.0

riotfile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ def select_pys(min_version: str = MIN_PYTHON_VERSION, max_version: str = MAX_PYT
122122
pkgs={
123123
"ruamel.yaml": latest,
124124
"lxml": latest,
125+
"cmake": latest,
126+
"setuptools_rust": latest,
127+
"Cython": latest,
125128
},
126129
),
127130
Venv(

scripts/gen_gitlab_config.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# file. The function will be called automatically when this script is run.
77

88
from dataclasses import dataclass
9+
import datetime
910
import os
1011
import subprocess
1112
import typing as t
@@ -251,19 +252,29 @@ def check(name: str, command: str, paths: t.Set[str]) -> None:
251252
def gen_build_base_venvs() -> None:
252253
"""Generate the list of base jobs for building virtual environments."""
253254
output = subprocess.check_output([sys.executable, ROOT / "setup.py", "ext_hashes", "--inplace"])
254-
ext_cache = ""
255-
touch_list = []
255+
cached_files = []
256256
for line in output.decode().splitlines():
257257
if not line.startswith("#EXTHASH:"):
258258
continue
259259
ext_name, ext_hash, ext_target = eval(line.split(":", 1)[-1].strip())
260-
touch_list.append(f" test -f {ext_target} && touch {ext_target} || true")
261-
ext_cache += f"""
262-
- key: v1-build_base_venvs-${{PYTHON_VERSION}}-ext-{ext_name}-{ext_hash}
263-
paths:
264-
- {Path(ext_target).relative_to(ROOT)}"""
260+
cached_files.append((f".ext_cache/{ext_name}/{ext_hash}/{Path(ext_target).name}", ext_target))
261+
262+
restore_ext_cache = "\n".join(
263+
[
264+
f" test -f {cached_file} && (cp {cached_file} {dest} && touch {dest}) || true"
265+
for cached_file, dest in cached_files
266+
]
267+
)
268+
269+
save_ext_cache = "\n".join(
270+
[
271+
f" test -f {cached_file} || mkdir -p {Path(cached_file).parent} && cp {dest} {cached_file}"
272+
for cached_file, dest in cached_files
273+
]
274+
)
275+
276+
current_month = datetime.datetime.now().month
265277

266-
touch = "\n".join(touch_list).strip() if touch_list else ""
267278
with TESTS_GEN.open("a") as f:
268279
f.write(
269280
f"""
@@ -292,17 +303,19 @@ def gen_build_base_venvs() -> None:
292303
set -e -o pipefail
293304
apt update && apt install -y sccache
294305
pip install riot==0.20.1
295-
pip install cmake setuptools_rust Cython # :(
296-
{touch}
306+
{restore_ext_cache}
297307
riot -P -v generate --python=$PYTHON_VERSION
298308
echo "Running smoke tests"
299309
riot -v run -s --python=$PYTHON_VERSION smoke_test
310+
{save_ext_cache}
300311
cache:
301312
# Share pip/sccache between jobs of the same Python version
302313
- key: v1-build_base_venvs-${{PYTHON_VERSION}}-cache
303314
paths:
304315
- .cache
305-
{ext_cache}
316+
- key: v1-build_base_venvs-${{PYTHON_VERSION}}-ext-{current_month}
317+
paths:
318+
- .ext_cache
306319
artifacts:
307320
name: venv_$PYTHON_VERSION
308321
paths:

setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,10 @@ def run(self):
191191
)
192192

193193
sources_hash = hashlib.sha256()
194-
for source in sources:
194+
for source in sorted(sources):
195195
sources_hash.update(source.read_bytes())
196196

197-
print("#EXTHASH:", (ext.name, sources_hash.hexdigest(), full_path))
197+
print("#EXTHASH:", (ext.name, sources_hash.hexdigest(), str(full_path)))
198198

199199

200200
class LibraryDownload:
@@ -873,7 +873,6 @@ def get_exts_for(name):
873873
"PY_MICRO_VERSION": sys.version_info.micro,
874874
"PY_VERSION_HEX": sys.hexversion,
875875
},
876-
force=True,
877876
annotate=os.getenv("_DD_CYTHON_ANNOTATE") == "1",
878877
compiler_directives={"language_level": "3"},
879878
)

0 commit comments

Comments
 (0)