cleepcli 1.49.6__tar.gz → 1.49.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. {cleepcli-1.49.6/cleepcli.egg-info → cleepcli-1.49.8}/PKG-INFO +1 -1
  2. {cleepcli-1.49.6 → cleepcli-1.49.8}/bin/ccli +22 -8
  3. {cleepcli-1.49.6 → cleepcli-1.49.8}/bin/cleep-cli +22 -8
  4. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/pico.py +284 -53
  5. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/version.py +1 -1
  6. {cleepcli-1.49.6 → cleepcli-1.49.8/cleepcli.egg-info}/PKG-INFO +1 -1
  7. {cleepcli-1.49.6 → cleepcli-1.49.8}/tests/test_pico.py +69 -4
  8. {cleepcli-1.49.6 → cleepcli-1.49.8}/LICENSE +0 -0
  9. {cleepcli-1.49.6 → cleepcli-1.49.8}/MANIFEST.in +0 -0
  10. {cleepcli-1.49.6 → cleepcli-1.49.8}/README.md +0 -0
  11. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/__init__.py +0 -0
  12. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/check.py +0 -0
  13. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/ci.py +0 -0
  14. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/cleepapi.py +0 -0
  15. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/config.py +0 -0
  16. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/console.py +0 -0
  17. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/docs.py +0 -0
  18. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/file.py +0 -0
  19. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/git.py +0 -0
  20. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/module.py +0 -0
  21. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/package.py +0 -0
  22. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/systemd/cleep-watch.service +0 -0
  23. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/test.py +0 -0
  24. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/tools.py +0 -0
  25. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/watch.py +0 -0
  26. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli/watchsvc.py +0 -0
  27. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli.egg-info/SOURCES.txt +0 -0
  28. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli.egg-info/dependency_links.txt +0 -0
  29. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli.egg-info/requires.txt +0 -0
  30. {cleepcli-1.49.6 → cleepcli-1.49.8}/cleepcli.egg-info/top_level.txt +0 -0
  31. {cleepcli-1.49.6 → cleepcli-1.49.8}/pyproject.toml +0 -0
  32. {cleepcli-1.49.6 → cleepcli-1.49.8}/requirements.txt +0 -0
  33. {cleepcli-1.49.6 → cleepcli-1.49.8}/setup.cfg +0 -0
  34. {cleepcli-1.49.6 → cleepcli-1.49.8}/setup.py +0 -0
  35. {cleepcli-1.49.6 → cleepcli-1.49.8}/tests/test_check.py +0 -0
  36. {cleepcli-1.49.6 → cleepcli-1.49.8}/tests/test_config.py +0 -0
  37. {cleepcli-1.49.6 → cleepcli-1.49.8}/tests/test_console.py +0 -0
  38. {cleepcli-1.49.6 → cleepcli-1.49.8}/tests/test_coverage.py +0 -0
  39. {cleepcli-1.49.6 → cleepcli-1.49.8}/tests/test_docs_breaking.py +0 -0
  40. {cleepcli-1.49.6 → cleepcli-1.49.8}/tests/test_file_sync_all.py +0 -0
  41. {cleepcli-1.49.6 → cleepcli-1.49.8}/tests/test_module_scaffold.py +0 -0
  42. {cleepcli-1.49.6 → cleepcli-1.49.8}/tests/test_watch.py +0 -0
  43. {cleepcli-1.49.6 → cleepcli-1.49.8}/tests/test_watchsvc.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cleepcli
3
- Version: 1.49.6
3
+ Version: 1.49.8
4
4
  Summary: Cleep-cli helps developers to build great Cleep applications from command line.
5
5
  Home-page: https://github.com/CleepDevice/cleep-cli
6
6
  Author: Tanguy Bonneau
@@ -1013,11 +1013,17 @@ def pico_sdk():
1013
1013
 
1014
1014
 
1015
1015
  @pico_sdk.command('install')
1016
+ @click.option(
1017
+ '--version',
1018
+ 'version',
1019
+ required=True,
1020
+ help='Git tag or ref to install (caller-chosen; e.g. 2.1.1).',
1021
+ )
1016
1022
  @click.option('--json', 'as_json', is_flag=True, help='Print JSON metadata.')
1017
- def pico_sdk_install(as_json):
1018
- """Install toolchain packages and clone the Pico SDK."""
1023
+ def pico_sdk_install(version, as_json):
1024
+ """Install toolchain packages and clone the Pico SDK at --version."""
1019
1025
  try:
1020
- meta = Pico().sdk_install()
1026
+ meta = Pico().sdk_install(version)
1021
1027
  except PicoError as error:
1022
1028
  logging.error(str(error))
1023
1029
  sys.exit(1)
@@ -1026,20 +1032,27 @@ def pico_sdk_install(as_json):
1026
1032
  click.echo(json.dumps(meta, separators=(',', ':')))
1027
1033
  else:
1028
1034
  logging.info(
1029
- 'SDK installed=%s version=%s revision=%s toolchain_ok=%s',
1035
+ 'SDK installed=%s version=%s revision=%s requested=%s toolchain_ok=%s',
1030
1036
  meta.get('installed'),
1031
1037
  meta.get('version'),
1032
1038
  meta.get('revision'),
1039
+ meta.get('requested_version'),
1033
1040
  meta.get('toolchain_ok'),
1034
1041
  )
1035
1042
 
1036
1043
 
1037
1044
  @pico_sdk.command('update')
1045
+ @click.option(
1046
+ '--version',
1047
+ 'version',
1048
+ required=True,
1049
+ help='Git tag or ref to checkout (caller-chosen; e.g. 2.1.1).',
1050
+ )
1038
1051
  @click.option('--json', 'as_json', is_flag=True, help='Print JSON metadata.')
1039
- def pico_sdk_update(as_json):
1040
- """Update the Pico SDK checkout."""
1052
+ def pico_sdk_update(version, as_json):
1053
+ """Checkout the Pico SDK at --version and refresh submodules."""
1041
1054
  try:
1042
- meta = Pico().sdk_update()
1055
+ meta = Pico().sdk_update(version)
1043
1056
  except PicoError as error:
1044
1057
  logging.error(str(error))
1045
1058
  sys.exit(1)
@@ -1047,9 +1060,10 @@ def pico_sdk_update(as_json):
1047
1060
  click.echo(json.dumps(meta, separators=(',', ':')))
1048
1061
  else:
1049
1062
  logging.info(
1050
- 'SDK updated version=%s revision=%s',
1063
+ 'SDK updated version=%s revision=%s requested=%s',
1051
1064
  meta.get('version'),
1052
1065
  meta.get('revision'),
1066
+ meta.get('requested_version'),
1053
1067
  )
1054
1068
 
1055
1069
 
@@ -1013,11 +1013,17 @@ def pico_sdk():
1013
1013
 
1014
1014
 
1015
1015
  @pico_sdk.command('install')
1016
+ @click.option(
1017
+ '--version',
1018
+ 'version',
1019
+ required=True,
1020
+ help='Git tag or ref to install (caller-chosen; e.g. 2.1.1).',
1021
+ )
1016
1022
  @click.option('--json', 'as_json', is_flag=True, help='Print JSON metadata.')
1017
- def pico_sdk_install(as_json):
1018
- """Install toolchain packages and clone the Pico SDK."""
1023
+ def pico_sdk_install(version, as_json):
1024
+ """Install toolchain packages and clone the Pico SDK at --version."""
1019
1025
  try:
1020
- meta = Pico().sdk_install()
1026
+ meta = Pico().sdk_install(version)
1021
1027
  except PicoError as error:
1022
1028
  logging.error(str(error))
1023
1029
  sys.exit(1)
@@ -1026,20 +1032,27 @@ def pico_sdk_install(as_json):
1026
1032
  click.echo(json.dumps(meta, separators=(',', ':')))
1027
1033
  else:
1028
1034
  logging.info(
1029
- 'SDK installed=%s version=%s revision=%s toolchain_ok=%s',
1035
+ 'SDK installed=%s version=%s revision=%s requested=%s toolchain_ok=%s',
1030
1036
  meta.get('installed'),
1031
1037
  meta.get('version'),
1032
1038
  meta.get('revision'),
1039
+ meta.get('requested_version'),
1033
1040
  meta.get('toolchain_ok'),
1034
1041
  )
1035
1042
 
1036
1043
 
1037
1044
  @pico_sdk.command('update')
1045
+ @click.option(
1046
+ '--version',
1047
+ 'version',
1048
+ required=True,
1049
+ help='Git tag or ref to checkout (caller-chosen; e.g. 2.1.1).',
1050
+ )
1038
1051
  @click.option('--json', 'as_json', is_flag=True, help='Print JSON metadata.')
1039
- def pico_sdk_update(as_json):
1040
- """Update the Pico SDK checkout."""
1052
+ def pico_sdk_update(version, as_json):
1053
+ """Checkout the Pico SDK at --version and refresh submodules."""
1041
1054
  try:
1042
- meta = Pico().sdk_update()
1055
+ meta = Pico().sdk_update(version)
1043
1056
  except PicoError as error:
1044
1057
  logging.error(str(error))
1045
1058
  sys.exit(1)
@@ -1047,9 +1060,10 @@ def pico_sdk_update(as_json):
1047
1060
  click.echo(json.dumps(meta, separators=(',', ':')))
1048
1061
  else:
1049
1062
  logging.info(
1050
- 'SDK updated version=%s revision=%s',
1063
+ 'SDK updated version=%s revision=%s requested=%s',
1051
1064
  meta.get('version'),
1052
1065
  meta.get('revision'),
1066
+ meta.get('requested_version'),
1053
1067
  )
1054
1068
 
1055
1069
 
@@ -27,6 +27,9 @@ class Pico:
27
27
 
28
28
  # Machine-readable step markers for developer UI progress (stdout).
29
29
  STEP_MARKER_PREFIX = "CLEEP_PICO_STEP:"
30
+ # Installed tree ~700 MiB; leave headroom for clone tmp + apt when needed.
31
+ DISK_FREE_TOOLCHAIN_OK_BYTES = 1024 * 1024 * 1024 # 1 GiB
32
+ DISK_FREE_TOOLCHAIN_MISSING_BYTES = 2 * 1024 * 1024 * 1024 # 2 GiB
30
33
  INSTALL_STEPS = (
31
34
  ("toolchain", "Install apt toolchain (cmake, arm-none-eabi)"),
32
35
  ("clone", "Clone pico-sdk"),
@@ -35,8 +38,8 @@ class Pico:
35
38
  )
36
39
  UPDATE_STEPS = (
37
40
  ("toolchain", "Check apt toolchain"),
38
- ("fetch", "Fetch latest pico-sdk"),
39
- ("reset", "Reset pico-sdk to origin/master"),
41
+ ("fetch", "Fetch requested pico-sdk ref"),
42
+ ("checkout", "Checkout requested pico-sdk ref"),
40
43
  ("submodules", "Update pico-sdk submodules"),
41
44
  )
42
45
 
@@ -102,8 +105,154 @@ class Pico:
102
105
  detail = args if isinstance(args, str) else " ".join(args)
103
106
  raise PicoError("%s (exit %s): %s" % (prefix, returncode, detail))
104
107
 
108
+ @staticmethod
109
+ def _arm_lib_ok(libname: str) -> bool:
110
+ """
111
+ True when arm-none-eabi-gcc can resolve a real archive (e.g. libc.a).
112
+
113
+ Without libnewlib-arm-none-eabi, the compiler is on PATH but link fails
114
+ with ``cannot find -lc`` / ``-lg``.
115
+ """
116
+ gcc = shutil.which("arm-none-eabi-gcc")
117
+ if not gcc:
118
+ return False
119
+ try:
120
+ out = subprocess.check_output(
121
+ [gcc, "-print-file-name=%s" % libname],
122
+ text=True,
123
+ stderr=subprocess.DEVNULL,
124
+ ).strip()
125
+ except (OSError, subprocess.CalledProcessError):
126
+ return False
127
+ # Missing libs are echoed back as the bare name (not a filesystem path).
128
+ return bool(out) and out != libname and os.path.isfile(out)
129
+
105
130
  def _toolchain_ok(self) -> bool:
106
- return bool(shutil.which("cmake") and shutil.which("arm-none-eabi-gcc"))
131
+ return bool(
132
+ shutil.which("cmake")
133
+ and shutil.which("arm-none-eabi-gcc")
134
+ and self._arm_lib_ok("libc.a")
135
+ and self._arm_lib_ok("libg.a")
136
+ )
137
+
138
+ def _toolchain_fingerprint(self) -> str:
139
+ """Stable id for the apt toolchain (path + dumpversion)."""
140
+ gcc = shutil.which("arm-none-eabi-gcc") or ""
141
+ cmake = shutil.which("cmake") or ""
142
+ gcc_ver = ""
143
+ if gcc:
144
+ try:
145
+ gcc_ver = subprocess.check_output(
146
+ [gcc, "-dumpversion"],
147
+ text=True,
148
+ stderr=subprocess.DEVNULL,
149
+ ).strip()
150
+ except (OSError, subprocess.CalledProcessError):
151
+ gcc_ver = ""
152
+ return "%s|%s|%s" % (gcc, gcc_ver, cmake)
153
+
154
+ def _cmake_env_path(self, build_root: str) -> str:
155
+ return os.path.join(build_root, "cmake-env.json")
156
+
157
+ def _build_cmake_env(self, *, board: str, sdk: dict[str, Any]) -> dict[str, Any]:
158
+ return {
159
+ "pico_board": board,
160
+ "sdk_path": config.PICO_SDK_DIR,
161
+ "sdk_revision": sdk.get("revision") or "",
162
+ "sdk_version": sdk.get("version") or "",
163
+ "toolchain": self._toolchain_fingerprint(),
164
+ }
165
+
166
+ def _load_cmake_env(self, build_root: str) -> dict[str, Any] | None:
167
+ path = self._cmake_env_path(build_root)
168
+ if not os.path.isfile(path):
169
+ return None
170
+ try:
171
+ with open(path, "r", encoding="utf-8") as handle:
172
+ data = json.load(handle)
173
+ except (OSError, UnicodeDecodeError, json.JSONDecodeError):
174
+ return None
175
+ return data if isinstance(data, dict) else None
176
+
177
+ def _write_cmake_env(self, build_root: str, env: dict[str, Any]) -> None:
178
+ os.makedirs(build_root, exist_ok=True)
179
+ path = self._cmake_env_path(build_root)
180
+ with open(path, "w", encoding="utf-8") as handle:
181
+ json.dump(env, handle, indent=4, ensure_ascii=False, sort_keys=True)
182
+ handle.write("\n")
183
+
184
+ def _cmake_env_matches(
185
+ self, saved: dict[str, Any] | None, wanted: dict[str, Any]
186
+ ) -> bool:
187
+ if not saved:
188
+ return False
189
+ for key in ("pico_board", "sdk_path", "sdk_revision", "toolchain"):
190
+ if saved.get(key) != wanted.get(key):
191
+ return False
192
+ return True
193
+
194
+ @staticmethod
195
+ def _disk_free_bytes(path: str) -> int:
196
+ """Return free bytes on the filesystem that holds ``path`` (or its parent)."""
197
+ probe = path
198
+ while probe and not os.path.exists(probe):
199
+ parent = os.path.dirname(probe)
200
+ if parent == probe:
201
+ break
202
+ probe = parent
203
+ if not probe or not os.path.exists(probe):
204
+ probe = "/"
205
+ try:
206
+ usage = os.statvfs(probe)
207
+ except OSError:
208
+ return 0
209
+ return int(usage.f_bavail * usage.f_frsize)
210
+
211
+ def _disk_required_bytes(self) -> int:
212
+ if self._toolchain_ok():
213
+ return self.DISK_FREE_TOOLCHAIN_OK_BYTES
214
+ return self.DISK_FREE_TOOLCHAIN_MISSING_BYTES
215
+
216
+ def _disk_status(self) -> dict[str, Any]:
217
+ free = self._disk_free_bytes(config.PICO_SDK_DIR)
218
+ required = self._disk_required_bytes()
219
+ return {
220
+ "disk_free_bytes": free,
221
+ "disk_required_bytes": required,
222
+ "disk_ok": free >= required,
223
+ }
224
+
225
+ @staticmethod
226
+ def _format_bytes(num: int) -> str:
227
+ value = float(max(num, 0))
228
+ for unit in ("B", "KiB", "MiB", "GiB", "TiB"):
229
+ if value < 1024.0 or unit == "TiB":
230
+ if unit == "B":
231
+ return "%d %s" % (int(value), unit)
232
+ return "%.1f %s" % (value, unit)
233
+ value /= 1024.0
234
+ return "%d B" % num
235
+
236
+ def _ensure_disk_space(self) -> None:
237
+ status = self._disk_status()
238
+ if status["disk_ok"]:
239
+ self._emit(
240
+ "Disk space OK: %s free (need %s)."
241
+ % (
242
+ self._format_bytes(status["disk_free_bytes"]),
243
+ self._format_bytes(status["disk_required_bytes"]),
244
+ )
245
+ )
246
+ return
247
+ raise PicoError(
248
+ "Not enough free disk space to install the Pico SDK: "
249
+ "%s free, %s required under %s"
250
+ % (
251
+ self._format_bytes(status["disk_free_bytes"]),
252
+ self._format_bytes(status["disk_required_bytes"]),
253
+ os.path.dirname(config.PICO_SDK_DIR) or config.PICO_SDK_DIR,
254
+ )
255
+ )
107
256
 
108
257
  def _git_revision(self, sdk_dir: str) -> str:
109
258
  try:
@@ -152,7 +301,7 @@ class Pico:
152
301
  def _load_meta(self) -> dict[str, Any]:
153
302
  if not os.path.isfile(config.PICO_SDK_META):
154
303
  installed = os.path.isdir(os.path.join(config.PICO_SDK_DIR, ".git"))
155
- return {
304
+ data = {
156
305
  "installed": installed,
157
306
  "path": config.PICO_SDK_DIR,
158
307
  "revision": self._git_revision(config.PICO_SDK_DIR) if installed else "",
@@ -160,19 +309,21 @@ class Pico:
160
309
  "updated_at": None,
161
310
  "toolchain_ok": self._toolchain_ok(),
162
311
  }
163
- try:
164
- with open(config.PICO_SDK_META, "r", encoding="utf-8") as handle:
165
- data = json.load(handle)
166
- except (OSError, json.JSONDecodeError):
167
- data = {}
168
- if not isinstance(data, dict):
169
- data = {}
170
- data.setdefault("path", config.PICO_SDK_DIR)
171
- data["toolchain_ok"] = self._toolchain_ok()
172
- data["installed"] = bool(
173
- data.get("installed")
174
- or os.path.isdir(os.path.join(config.PICO_SDK_DIR, ".git"))
175
- )
312
+ else:
313
+ try:
314
+ with open(config.PICO_SDK_META, "r", encoding="utf-8") as handle:
315
+ data = json.load(handle)
316
+ except (OSError, json.JSONDecodeError):
317
+ data = {}
318
+ if not isinstance(data, dict):
319
+ data = {}
320
+ data.setdefault("path", config.PICO_SDK_DIR)
321
+ data["toolchain_ok"] = self._toolchain_ok()
322
+ data["installed"] = bool(
323
+ data.get("installed")
324
+ or os.path.isdir(os.path.join(config.PICO_SDK_DIR, ".git"))
325
+ )
326
+ data.update(self._disk_status())
176
327
  return data
177
328
 
178
329
  def _ensure_toolchain(self, *, emit_steps: bool = False, step_index: int = 1, step_total: int = 4) -> None:
@@ -188,8 +339,16 @@ class Pico:
188
339
  if emit_steps:
189
340
  self._emit_step(step_index, step_total, "toolchain", label)
190
341
  if self._toolchain_ok():
191
- self._emit("Toolchain already present (cmake, arm-none-eabi-gcc) — skipping apt.")
342
+ self._emit(
343
+ "Toolchain already present "
344
+ "(cmake, arm-none-eabi-gcc, newlib) — skipping apt."
345
+ )
192
346
  return
347
+ if shutil.which("arm-none-eabi-gcc") and not self._arm_lib_ok("libc.a"):
348
+ self._emit(
349
+ "Toolchain incomplete: arm-none-eabi-gcc is installed but newlib "
350
+ "is missing (linker cannot find -lc/-lg). Installing apt packages…"
351
+ )
193
352
  packages = " ".join(config.PICO_TOOLCHAIN_PACKAGES)
194
353
  self._emit("Installing Pico toolchain packages via apt: %s" % packages)
195
354
  self._emit("(This step alone can take several minutes on a Raspberry Pi.)")
@@ -201,8 +360,8 @@ class Pico:
201
360
  self._run_streamed(cmd, "Failed to install toolchain packages", shell=True)
202
361
  if not self._toolchain_ok():
203
362
  raise PicoError(
204
- "Toolchain still missing after apt install "
205
- "(need cmake and arm-none-eabi-gcc on PATH)"
363
+ "Toolchain still incomplete after apt install "
364
+ "(need cmake, arm-none-eabi-gcc, and newlib libc/libg)"
206
365
  )
207
366
  self._emit("Toolchain install complete.")
208
367
 
@@ -210,35 +369,103 @@ class Pico:
210
369
  """Return SDK installation metadata."""
211
370
  return self._load_meta()
212
371
 
213
- def sdk_install(self) -> dict[str, Any]:
214
- """Install toolchain packages + clone pico-sdk with submodules."""
372
+ @staticmethod
373
+ def _require_version(version: str) -> str:
374
+ """Caller-chosen git tag/branch/ref (CLI does not pick a default)."""
375
+ ref = (version or "").strip()
376
+ if not ref:
377
+ raise PicoError(
378
+ "Pico SDK version/ref is required "
379
+ '(e.g. cleep-cli pico sdk install --version 2.1.1)'
380
+ )
381
+ return ref
382
+
383
+ def _fetch_ref(self, sdk_dir: str, version: str) -> None:
384
+ """
385
+ Shallow-fetch ``version`` (tag or branch) into FETCH_HEAD.
386
+
387
+ Trusts the caller-provided ref; probes ``git fetch … tag`` quietly,
388
+ then falls back to a plain ref fetch for branches.
389
+ """
390
+ self._emit("Fetching %s (quiet)…" % version)
391
+ tag_cmd = [
392
+ "git",
393
+ "-C",
394
+ sdk_dir,
395
+ "fetch",
396
+ "--depth",
397
+ "1",
398
+ "origin",
399
+ "tag",
400
+ version,
401
+ ]
402
+ tag_probe = subprocess.run(
403
+ tag_cmd,
404
+ stdout=subprocess.DEVNULL,
405
+ stderr=subprocess.DEVNULL,
406
+ check=False,
407
+ )
408
+ if tag_probe.returncode == 0:
409
+ return
410
+ self._emit("Not a tag — fetching as branch/ref %s…" % version)
411
+ self._run_streamed(
412
+ [
413
+ "git",
414
+ "-C",
415
+ sdk_dir,
416
+ "fetch",
417
+ "--depth",
418
+ "1",
419
+ "origin",
420
+ version,
421
+ ],
422
+ "SDK fetch failed",
423
+ )
424
+
425
+ def _checkout_fetch_head(self, sdk_dir: str) -> None:
426
+ self._run_streamed(
427
+ ["git", "-C", sdk_dir, "checkout", "--force", "--detach", "FETCH_HEAD"],
428
+ "SDK checkout failed",
429
+ )
430
+
431
+ def sdk_install(self, version: str) -> dict[str, Any]:
432
+ """Install toolchain packages + clone pico-sdk at ``version``."""
433
+ version = self._require_version(version)
215
434
  total = len(self.INSTALL_STEPS)
216
435
  self._emit(
217
- "Pico SDK install started (often 10+ minutes on first run — "
218
- "apt toolchain + git clone + submodules)."
436
+ "Pico SDK install started (ref %s — often 10+ minutes on first run — "
437
+ "apt toolchain + git clone + submodules)." % version
219
438
  )
439
+ self._ensure_disk_space()
220
440
  self._ensure_toolchain(emit_steps=True, step_index=1, step_total=total)
221
441
 
222
442
  sdk_dir = config.PICO_SDK_DIR
223
443
  if os.path.isdir(os.path.join(sdk_dir, ".git")):
224
- self._emit("Pico SDK already installed at %s — switching to update." % sdk_dir)
225
- return self.sdk_update()
444
+ self._emit(
445
+ "Pico SDK already installed at %s — switching to update (%s)."
446
+ % (sdk_dir, version)
447
+ )
448
+ return self.sdk_update(version)
226
449
 
227
450
  os.makedirs(os.path.dirname(sdk_dir), exist_ok=True)
228
451
  if os.path.exists(sdk_dir):
229
452
  shutil.rmtree(sdk_dir)
230
453
 
231
454
  self._emit_step(2, total, "clone", self.INSTALL_STEPS[1][1])
232
- self._emit("Cloning %s into %s" % (config.PICO_SDK_REPO, sdk_dir))
455
+ # No --progress: percent spam floods the developer RPC bus.
456
+ # --branch accepts tags and branch names.
457
+ self._emit(
458
+ "Cloning %s @ %s into %s (quiet — can take several minutes)…"
459
+ % (config.PICO_SDK_REPO, version, sdk_dir)
460
+ )
233
461
  self._run_streamed(
234
462
  [
235
463
  "git",
236
464
  "clone",
237
- "--progress",
238
465
  "--depth",
239
466
  "1",
240
467
  "--branch",
241
- "master",
468
+ version,
242
469
  config.PICO_SDK_REPO,
243
470
  sdk_dir,
244
471
  ],
@@ -246,6 +473,8 @@ class Pico:
246
473
  )
247
474
 
248
475
  self._emit_step(3, total, "submodules", self.INSTALL_STEPS[2][1])
476
+ # No --progress: submodule file spam freezes the developer UI console.
477
+ self._emit("Initializing submodules (quiet — can take several minutes)…")
249
478
  self._run_streamed(
250
479
  [
251
480
  "git",
@@ -254,16 +483,15 @@ class Pico:
254
483
  "submodule",
255
484
  "update",
256
485
  "--init",
257
- "--progress",
258
486
  ],
259
487
  "git submodule update failed",
260
488
  )
261
489
 
262
490
  self._emit_step(4, total, "finalize", self.INSTALL_STEPS[3][1])
263
- meta = self._write_meta()
491
+ meta = self._write_meta(requested_version=version)
264
492
  self._emit(
265
- "Pico SDK installed (%s / %s)"
266
- % (meta.get("version"), meta.get("revision"))
493
+ "Pico SDK installed (%s / %s) [requested %s]"
494
+ % (meta.get("version"), meta.get("revision"), version)
267
495
  )
268
496
  self._emit(
269
497
  "%s%s/%s:done:Install complete"
@@ -271,29 +499,24 @@ class Pico:
271
499
  )
272
500
  return meta
273
501
 
274
- def sdk_update(self) -> dict[str, Any]:
275
- """Pull latest pico-sdk and refresh submodules."""
502
+ def sdk_update(self, version: str) -> dict[str, Any]:
503
+ """Checkout pico-sdk ``version`` and refresh submodules."""
504
+ version = self._require_version(version)
276
505
  total = len(self.UPDATE_STEPS)
277
- self._emit("Pico SDK update started.")
506
+ self._emit("Pico SDK update started (ref %s)." % version)
278
507
  self._ensure_toolchain(emit_steps=True, step_index=1, step_total=total)
279
508
 
280
509
  sdk_dir = config.PICO_SDK_DIR
281
510
  if not os.path.isdir(os.path.join(sdk_dir, ".git")):
282
- return self.sdk_install()
511
+ return self.sdk_install(version)
283
512
 
284
513
  self._emit_step(2, total, "fetch", self.UPDATE_STEPS[1][1])
285
- self._run_streamed(
286
- ["git", "-C", sdk_dir, "fetch", "--progress", "--depth", "1", "origin", "master"],
287
- "SDK fetch failed",
288
- )
289
-
290
- self._emit_step(3, total, "reset", self.UPDATE_STEPS[2][1])
291
- self._run_streamed(
292
- ["git", "-C", sdk_dir, "reset", "--hard", "origin/master"],
293
- "SDK reset failed",
294
- )
514
+ self._fetch_ref(sdk_dir, version)
515
+ self._emit_step(3, total, "checkout", self.UPDATE_STEPS[2][1])
516
+ self._checkout_fetch_head(sdk_dir)
295
517
 
296
518
  self._emit_step(4, total, "submodules", self.UPDATE_STEPS[3][1])
519
+ self._emit("Updating submodules (quiet — can take several minutes)…")
297
520
  self._run_streamed(
298
521
  [
299
522
  "git",
@@ -303,15 +526,14 @@ class Pico:
303
526
  "update",
304
527
  "--init",
305
528
  "--recursive",
306
- "--progress",
307
529
  ],
308
530
  "SDK submodule update failed",
309
531
  )
310
532
 
311
- meta = self._write_meta()
533
+ meta = self._write_meta(requested_version=version)
312
534
  self._emit(
313
- "Pico SDK updated (%s / %s)"
314
- % (meta.get("version"), meta.get("revision"))
535
+ "Pico SDK updated (%s / %s) [requested %s]"
536
+ % (meta.get("version"), meta.get("revision"), version)
315
537
  )
316
538
  self._emit(
317
539
  "%s%s/%s:done:Update complete"
@@ -440,15 +662,23 @@ class Pico:
440
662
 
441
663
  build_root = build_dir_path(source_dir)
442
664
  cmake_dir = os.path.join(build_root, "cmake")
443
- if os.path.isdir(cmake_dir):
665
+ wanted_env = self._build_cmake_env(board=board, sdk=sdk)
666
+ saved_env = self._load_cmake_env(build_root)
667
+ need_clean = not self._cmake_env_matches(saved_env, wanted_env)
668
+ if need_clean and os.path.isdir(cmake_dir):
669
+ self.logger.info(
670
+ 'Firmware "%s": cmake env changed — wiping build cache',
671
+ source["slug"],
672
+ )
444
673
  shutil.rmtree(cmake_dir)
445
674
  os.makedirs(cmake_dir, exist_ok=True)
446
675
 
447
676
  self.logger.info(
448
- 'Building firmware "%s" (board=%s, version=%s)',
677
+ 'Building firmware "%s" (board=%s, version=%s%s)',
449
678
  source["slug"],
450
679
  board,
451
680
  data["version"],
681
+ ", incremental" if not need_clean else ", clean",
452
682
  )
453
683
  configure = [
454
684
  "cmake",
@@ -465,6 +695,7 @@ class Pico:
465
695
  cwd=source_dir,
466
696
  env=env,
467
697
  )
698
+ self._write_cmake_env(build_root, wanted_env)
468
699
 
469
700
  uf2_path = self._find_built_uf2(cmake_dir)
470
701
  if not uf2_path:
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- VERSION = "1.49.6"
4
+ VERSION = "1.49.8"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cleepcli
3
- Version: 1.49.6
3
+ Version: 1.49.8
4
4
  Summary: Cleep-cli helps developers to build great Cleep applications from command line.
5
5
  Home-page: https://github.com/CleepDevice/cleep-cli
6
6
  Author: Tanguy Bonneau
@@ -31,9 +31,34 @@ class PicoSdkTests(unittest.TestCase):
31
31
 
32
32
  def test_sdk_info_not_installed(self):
33
33
  with patch.object(self.pico, "_toolchain_ok", return_value=True):
34
- info = self.pico.sdk_info()
34
+ with patch.object(self.pico, "_disk_free_bytes", return_value=2 * 1024 * 1024 * 1024):
35
+ info = self.pico.sdk_info()
35
36
  self.assertFalse(info["installed"])
36
37
  self.assertTrue(info["toolchain_ok"])
38
+ self.assertTrue(info["disk_ok"])
39
+ self.assertEqual(info["disk_required_bytes"], Pico.DISK_FREE_TOOLCHAIN_OK_BYTES)
40
+
41
+ def test_ensure_disk_space_raises(self):
42
+ with patch.object(self.pico, "_toolchain_ok", return_value=True):
43
+ with patch.object(self.pico, "_disk_free_bytes", return_value=10 * 1024 * 1024):
44
+ with self.assertRaises(PicoError) as ctx:
45
+ self.pico._ensure_disk_space()
46
+ self.assertIn("Not enough free disk space", str(ctx.exception))
47
+
48
+ def test_arm_lib_ok_rejects_echoed_name(self):
49
+ with patch("cleepcli.pico.shutil.which", return_value="/usr/bin/arm-none-eabi-gcc"):
50
+ with patch("cleepcli.pico.subprocess.check_output", return_value="libc.a\n"):
51
+ with patch("cleepcli.pico.os.path.isfile", return_value=False):
52
+ self.assertFalse(self.pico._arm_lib_ok("libc.a"))
53
+
54
+ def test_arm_lib_ok_accepts_realpath(self):
55
+ with patch("cleepcli.pico.shutil.which", return_value="/usr/bin/arm-none-eabi-gcc"):
56
+ with patch(
57
+ "cleepcli.pico.subprocess.check_output",
58
+ return_value="/usr/lib/arm-none-eabi/newlib/libc.a\n",
59
+ ):
60
+ with patch("cleepcli.pico.os.path.isfile", return_value=True):
61
+ self.assertTrue(self.pico._arm_lib_ok("libc.a"))
37
62
 
38
63
  def test_sdk_uninstall_removes_meta(self):
39
64
  os.makedirs(self.sdk_dir)
@@ -45,11 +70,19 @@ class PicoSdkTests(unittest.TestCase):
45
70
  self.assertFalse(os.path.isfile(self.meta))
46
71
  self.assertFalse(info["installed"])
47
72
 
73
+ def test_require_version_rejects_empty(self):
74
+ with self.assertRaises(PicoError):
75
+ self.pico._require_version("")
76
+ with self.assertRaises(PicoError):
77
+ self.pico._require_version(" ")
78
+
48
79
  @patch.object(Pico, "_run_streamed")
49
80
  @patch.object(Pico, "_ensure_toolchain")
50
- def test_sdk_install_clones(self, _toolchain, streamed_mock):
81
+ @patch.object(Pico, "_ensure_disk_space")
82
+ def test_sdk_install_clones(self, _disk, _toolchain, streamed_mock):
51
83
  def _streamed(args, error_prefix, shell=False):
52
84
  if isinstance(args, list) and args[0:2] == ["git", "clone"]:
85
+ self.assertEqual(args[args.index("--branch") + 1], "2.1.1")
53
86
  os.makedirs(os.path.join(self.sdk_dir, ".git"), exist_ok=True)
54
87
 
55
88
  streamed_mock.side_effect = _streamed
@@ -59,10 +92,11 @@ class PicoSdkTests(unittest.TestCase):
59
92
  shutil.rmtree(self.sdk_dir)
60
93
 
61
94
  with patch.object(self.pico, "_git_revision", return_value="deadbee"):
62
- with patch.object(self.pico, "_git_describe", return_value="2.0.0"):
95
+ with patch.object(self.pico, "_git_describe", return_value="2.1.1"):
63
96
  with patch.object(self.pico, "_toolchain_ok", return_value=True):
64
- meta = self.pico.sdk_install()
97
+ meta = self.pico.sdk_install("2.1.1")
65
98
  self.assertTrue(meta["installed"])
99
+ self.assertEqual(meta["requested_version"], "2.1.1")
66
100
  self.assertTrue(os.path.isfile(self.meta))
67
101
  self.assertGreaterEqual(streamed_mock.call_count, 2)
68
102
 
@@ -86,6 +120,37 @@ class PicoSdkTests(unittest.TestCase):
86
120
  self.pico.build_firmware("demo")
87
121
  self.assertIn("not installed", str(ctx.exception))
88
122
 
123
+ def test_cmake_env_matches_board_sdk_toolchain(self):
124
+ wanted = {
125
+ "pico_board": "pico_w",
126
+ "sdk_path": "/sdk",
127
+ "sdk_revision": "abc",
128
+ "sdk_version": "2.1.1",
129
+ "toolchain": "gcc|8|cmake",
130
+ }
131
+ self.assertTrue(self.pico._cmake_env_matches(dict(wanted), wanted))
132
+ self.assertFalse(
133
+ self.pico._cmake_env_matches({**wanted, "pico_board": "pico"}, wanted)
134
+ )
135
+ self.assertFalse(
136
+ self.pico._cmake_env_matches({**wanted, "sdk_revision": "zzz"}, wanted)
137
+ )
138
+ self.assertFalse(self.pico._cmake_env_matches(None, wanted))
139
+
140
+ def test_cmake_env_roundtrip(self):
141
+ build_root = os.path.join(self.root, "fw-build")
142
+ env = {
143
+ "pico_board": "pico_w",
144
+ "sdk_path": "/sdk",
145
+ "sdk_revision": "deadbee",
146
+ "sdk_version": "2.1.1",
147
+ "toolchain": "gcc|8|cmake",
148
+ }
149
+ self.pico._write_cmake_env(build_root, env)
150
+ loaded = self.pico._load_cmake_env(build_root)
151
+ self.assertEqual(loaded, env)
152
+ self.assertTrue(self.pico._cmake_env_matches(loaded, env))
153
+
89
154
 
90
155
  if __name__ == "__main__":
91
156
  unittest.main()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes