cleepcli 1.49.5__tar.gz → 1.49.7__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.5/cleepcli.egg-info → cleepcli-1.49.7}/PKG-INFO +1 -1
  2. {cleepcli-1.49.5 → cleepcli-1.49.7}/bin/ccli +22 -8
  3. {cleepcli-1.49.5 → cleepcli-1.49.7}/bin/cleep-cli +22 -8
  4. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/pico.py +237 -75
  5. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/version.py +1 -1
  6. {cleepcli-1.49.5 → cleepcli-1.49.7/cleepcli.egg-info}/PKG-INFO +1 -1
  7. {cleepcli-1.49.5 → cleepcli-1.49.7}/tests/test_pico.py +38 -4
  8. {cleepcli-1.49.5 → cleepcli-1.49.7}/LICENSE +0 -0
  9. {cleepcli-1.49.5 → cleepcli-1.49.7}/MANIFEST.in +0 -0
  10. {cleepcli-1.49.5 → cleepcli-1.49.7}/README.md +0 -0
  11. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/__init__.py +0 -0
  12. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/check.py +0 -0
  13. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/ci.py +0 -0
  14. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/cleepapi.py +0 -0
  15. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/config.py +0 -0
  16. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/console.py +0 -0
  17. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/docs.py +0 -0
  18. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/file.py +0 -0
  19. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/git.py +0 -0
  20. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/module.py +0 -0
  21. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/package.py +0 -0
  22. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/systemd/cleep-watch.service +0 -0
  23. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/test.py +0 -0
  24. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/tools.py +0 -0
  25. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/watch.py +0 -0
  26. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli/watchsvc.py +0 -0
  27. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli.egg-info/SOURCES.txt +0 -0
  28. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli.egg-info/dependency_links.txt +0 -0
  29. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli.egg-info/requires.txt +0 -0
  30. {cleepcli-1.49.5 → cleepcli-1.49.7}/cleepcli.egg-info/top_level.txt +0 -0
  31. {cleepcli-1.49.5 → cleepcli-1.49.7}/pyproject.toml +0 -0
  32. {cleepcli-1.49.5 → cleepcli-1.49.7}/requirements.txt +0 -0
  33. {cleepcli-1.49.5 → cleepcli-1.49.7}/setup.cfg +0 -0
  34. {cleepcli-1.49.5 → cleepcli-1.49.7}/setup.py +0 -0
  35. {cleepcli-1.49.5 → cleepcli-1.49.7}/tests/test_check.py +0 -0
  36. {cleepcli-1.49.5 → cleepcli-1.49.7}/tests/test_config.py +0 -0
  37. {cleepcli-1.49.5 → cleepcli-1.49.7}/tests/test_console.py +0 -0
  38. {cleepcli-1.49.5 → cleepcli-1.49.7}/tests/test_coverage.py +0 -0
  39. {cleepcli-1.49.5 → cleepcli-1.49.7}/tests/test_docs_breaking.py +0 -0
  40. {cleepcli-1.49.5 → cleepcli-1.49.7}/tests/test_file_sync_all.py +0 -0
  41. {cleepcli-1.49.5 → cleepcli-1.49.7}/tests/test_module_scaffold.py +0 -0
  42. {cleepcli-1.49.5 → cleepcli-1.49.7}/tests/test_watch.py +0 -0
  43. {cleepcli-1.49.5 → cleepcli-1.49.7}/tests/test_watchsvc.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cleepcli
3
- Version: 1.49.5
3
+ Version: 1.49.7
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
 
@@ -59,7 +62,14 @@ class Pico:
59
62
  )
60
63
  self._emit("=== [%s/%s] %s ===" % (index, total, label))
61
64
 
62
- def _run_streamed(self, args: list[str] | str, error_prefix: str, shell: bool = False) -> None:
65
+ def _run_streamed(
66
+ self,
67
+ args: list[str] | str,
68
+ error_prefix: str | None = None,
69
+ shell: bool = False,
70
+ cwd: str | None = None,
71
+ env: dict[str, str] | None = None,
72
+ ) -> None:
63
73
  """
64
74
  Run a command and stream combined stdout/stderr line by line.
65
75
 
@@ -67,11 +77,15 @@ class Pico:
67
77
  args: argv list, or shell command string when shell=True
68
78
  error_prefix: message prefix on non-zero exit
69
79
  shell: pass command through the shell
80
+ cwd: optional working directory
81
+ env: optional environment (defaults to a copy of os.environ)
70
82
  """
71
- env = os.environ.copy()
72
- env["GIT_TERMINAL_PROMPT"] = "0"
83
+ run_env = dict(env) if env is not None else os.environ.copy()
84
+ run_env.setdefault("GIT_TERMINAL_PROMPT", "0")
73
85
  # Make apt less chatty about progress bars that redraw the same line.
74
- env.setdefault("DEBIAN_FRONTEND", "noninteractive")
86
+ run_env.setdefault("DEBIAN_FRONTEND", "noninteractive")
87
+ if isinstance(args, list):
88
+ self.logger.debug("$ %s", " ".join(args))
75
89
  proc = subprocess.Popen(
76
90
  args,
77
91
  stdout=subprocess.PIPE,
@@ -79,17 +93,110 @@ class Pico:
79
93
  text=True,
80
94
  bufsize=1,
81
95
  shell=shell,
82
- env=env,
96
+ cwd=cwd,
97
+ env=run_env,
83
98
  )
84
99
  assert proc.stdout is not None
85
100
  for line in proc.stdout:
86
101
  print(line, end="", flush=True)
87
102
  returncode = proc.wait()
88
103
  if returncode != 0:
89
- raise PicoError("%s (exit %s)" % (error_prefix, returncode))
104
+ prefix = error_prefix or "Command failed"
105
+ detail = args if isinstance(args, str) else " ".join(args)
106
+ raise PicoError("%s (exit %s): %s" % (prefix, returncode, detail))
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)
90
129
 
91
130
  def _toolchain_ok(self) -> bool:
92
- 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
+ @staticmethod
139
+ def _disk_free_bytes(path: str) -> int:
140
+ """Return free bytes on the filesystem that holds ``path`` (or its parent)."""
141
+ probe = path
142
+ while probe and not os.path.exists(probe):
143
+ parent = os.path.dirname(probe)
144
+ if parent == probe:
145
+ break
146
+ probe = parent
147
+ if not probe or not os.path.exists(probe):
148
+ probe = "/"
149
+ try:
150
+ usage = os.statvfs(probe)
151
+ except OSError:
152
+ return 0
153
+ return int(usage.f_bavail * usage.f_frsize)
154
+
155
+ def _disk_required_bytes(self) -> int:
156
+ if self._toolchain_ok():
157
+ return self.DISK_FREE_TOOLCHAIN_OK_BYTES
158
+ return self.DISK_FREE_TOOLCHAIN_MISSING_BYTES
159
+
160
+ def _disk_status(self) -> dict[str, Any]:
161
+ free = self._disk_free_bytes(config.PICO_SDK_DIR)
162
+ required = self._disk_required_bytes()
163
+ return {
164
+ "disk_free_bytes": free,
165
+ "disk_required_bytes": required,
166
+ "disk_ok": free >= required,
167
+ }
168
+
169
+ @staticmethod
170
+ def _format_bytes(num: int) -> str:
171
+ value = float(max(num, 0))
172
+ for unit in ("B", "KiB", "MiB", "GiB", "TiB"):
173
+ if value < 1024.0 or unit == "TiB":
174
+ if unit == "B":
175
+ return "%d %s" % (int(value), unit)
176
+ return "%.1f %s" % (value, unit)
177
+ value /= 1024.0
178
+ return "%d B" % num
179
+
180
+ def _ensure_disk_space(self) -> None:
181
+ status = self._disk_status()
182
+ if status["disk_ok"]:
183
+ self._emit(
184
+ "Disk space OK: %s free (need %s)."
185
+ % (
186
+ self._format_bytes(status["disk_free_bytes"]),
187
+ self._format_bytes(status["disk_required_bytes"]),
188
+ )
189
+ )
190
+ return
191
+ raise PicoError(
192
+ "Not enough free disk space to install the Pico SDK: "
193
+ "%s free, %s required under %s"
194
+ % (
195
+ self._format_bytes(status["disk_free_bytes"]),
196
+ self._format_bytes(status["disk_required_bytes"]),
197
+ os.path.dirname(config.PICO_SDK_DIR) or config.PICO_SDK_DIR,
198
+ )
199
+ )
93
200
 
94
201
  def _git_revision(self, sdk_dir: str) -> str:
95
202
  try:
@@ -138,7 +245,7 @@ class Pico:
138
245
  def _load_meta(self) -> dict[str, Any]:
139
246
  if not os.path.isfile(config.PICO_SDK_META):
140
247
  installed = os.path.isdir(os.path.join(config.PICO_SDK_DIR, ".git"))
141
- return {
248
+ data = {
142
249
  "installed": installed,
143
250
  "path": config.PICO_SDK_DIR,
144
251
  "revision": self._git_revision(config.PICO_SDK_DIR) if installed else "",
@@ -146,19 +253,21 @@ class Pico:
146
253
  "updated_at": None,
147
254
  "toolchain_ok": self._toolchain_ok(),
148
255
  }
149
- try:
150
- with open(config.PICO_SDK_META, "r", encoding="utf-8") as handle:
151
- data = json.load(handle)
152
- except (OSError, json.JSONDecodeError):
153
- data = {}
154
- if not isinstance(data, dict):
155
- data = {}
156
- data.setdefault("path", config.PICO_SDK_DIR)
157
- data["toolchain_ok"] = self._toolchain_ok()
158
- data["installed"] = bool(
159
- data.get("installed")
160
- or os.path.isdir(os.path.join(config.PICO_SDK_DIR, ".git"))
161
- )
256
+ else:
257
+ try:
258
+ with open(config.PICO_SDK_META, "r", encoding="utf-8") as handle:
259
+ data = json.load(handle)
260
+ except (OSError, json.JSONDecodeError):
261
+ data = {}
262
+ if not isinstance(data, dict):
263
+ data = {}
264
+ data.setdefault("path", config.PICO_SDK_DIR)
265
+ data["toolchain_ok"] = self._toolchain_ok()
266
+ data["installed"] = bool(
267
+ data.get("installed")
268
+ or os.path.isdir(os.path.join(config.PICO_SDK_DIR, ".git"))
269
+ )
270
+ data.update(self._disk_status())
162
271
  return data
163
272
 
164
273
  def _ensure_toolchain(self, *, emit_steps: bool = False, step_index: int = 1, step_total: int = 4) -> None:
@@ -174,8 +283,16 @@ class Pico:
174
283
  if emit_steps:
175
284
  self._emit_step(step_index, step_total, "toolchain", label)
176
285
  if self._toolchain_ok():
177
- self._emit("Toolchain already present (cmake, arm-none-eabi-gcc) — skipping apt.")
286
+ self._emit(
287
+ "Toolchain already present "
288
+ "(cmake, arm-none-eabi-gcc, newlib) — skipping apt."
289
+ )
178
290
  return
291
+ if shutil.which("arm-none-eabi-gcc") and not self._arm_lib_ok("libc.a"):
292
+ self._emit(
293
+ "Toolchain incomplete: arm-none-eabi-gcc is installed but newlib "
294
+ "is missing (linker cannot find -lc/-lg). Installing apt packages…"
295
+ )
179
296
  packages = " ".join(config.PICO_TOOLCHAIN_PACKAGES)
180
297
  self._emit("Installing Pico toolchain packages via apt: %s" % packages)
181
298
  self._emit("(This step alone can take several minutes on a Raspberry Pi.)")
@@ -187,8 +304,8 @@ class Pico:
187
304
  self._run_streamed(cmd, "Failed to install toolchain packages", shell=True)
188
305
  if not self._toolchain_ok():
189
306
  raise PicoError(
190
- "Toolchain still missing after apt install "
191
- "(need cmake and arm-none-eabi-gcc on PATH)"
307
+ "Toolchain still incomplete after apt install "
308
+ "(need cmake, arm-none-eabi-gcc, and newlib libc/libg)"
192
309
  )
193
310
  self._emit("Toolchain install complete.")
194
311
 
@@ -196,35 +313,103 @@ class Pico:
196
313
  """Return SDK installation metadata."""
197
314
  return self._load_meta()
198
315
 
199
- def sdk_install(self) -> dict[str, Any]:
200
- """Install toolchain packages + clone pico-sdk with submodules."""
316
+ @staticmethod
317
+ def _require_version(version: str) -> str:
318
+ """Caller-chosen git tag/branch/ref (CLI does not pick a default)."""
319
+ ref = (version or "").strip()
320
+ if not ref:
321
+ raise PicoError(
322
+ "Pico SDK version/ref is required "
323
+ '(e.g. cleep-cli pico sdk install --version 2.1.1)'
324
+ )
325
+ return ref
326
+
327
+ def _fetch_ref(self, sdk_dir: str, version: str) -> None:
328
+ """
329
+ Shallow-fetch ``version`` (tag or branch) into FETCH_HEAD.
330
+
331
+ Trusts the caller-provided ref; probes ``git fetch … tag`` quietly,
332
+ then falls back to a plain ref fetch for branches.
333
+ """
334
+ self._emit("Fetching %s (quiet)…" % version)
335
+ tag_cmd = [
336
+ "git",
337
+ "-C",
338
+ sdk_dir,
339
+ "fetch",
340
+ "--depth",
341
+ "1",
342
+ "origin",
343
+ "tag",
344
+ version,
345
+ ]
346
+ tag_probe = subprocess.run(
347
+ tag_cmd,
348
+ stdout=subprocess.DEVNULL,
349
+ stderr=subprocess.DEVNULL,
350
+ check=False,
351
+ )
352
+ if tag_probe.returncode == 0:
353
+ return
354
+ self._emit("Not a tag — fetching as branch/ref %s…" % version)
355
+ self._run_streamed(
356
+ [
357
+ "git",
358
+ "-C",
359
+ sdk_dir,
360
+ "fetch",
361
+ "--depth",
362
+ "1",
363
+ "origin",
364
+ version,
365
+ ],
366
+ "SDK fetch failed",
367
+ )
368
+
369
+ def _checkout_fetch_head(self, sdk_dir: str) -> None:
370
+ self._run_streamed(
371
+ ["git", "-C", sdk_dir, "checkout", "--force", "--detach", "FETCH_HEAD"],
372
+ "SDK checkout failed",
373
+ )
374
+
375
+ def sdk_install(self, version: str) -> dict[str, Any]:
376
+ """Install toolchain packages + clone pico-sdk at ``version``."""
377
+ version = self._require_version(version)
201
378
  total = len(self.INSTALL_STEPS)
202
379
  self._emit(
203
- "Pico SDK install started (often 10+ minutes on first run — "
204
- "apt toolchain + git clone + submodules)."
380
+ "Pico SDK install started (ref %s — often 10+ minutes on first run — "
381
+ "apt toolchain + git clone + submodules)." % version
205
382
  )
383
+ self._ensure_disk_space()
206
384
  self._ensure_toolchain(emit_steps=True, step_index=1, step_total=total)
207
385
 
208
386
  sdk_dir = config.PICO_SDK_DIR
209
387
  if os.path.isdir(os.path.join(sdk_dir, ".git")):
210
- self._emit("Pico SDK already installed at %s — switching to update." % sdk_dir)
211
- return self.sdk_update()
388
+ self._emit(
389
+ "Pico SDK already installed at %s — switching to update (%s)."
390
+ % (sdk_dir, version)
391
+ )
392
+ return self.sdk_update(version)
212
393
 
213
394
  os.makedirs(os.path.dirname(sdk_dir), exist_ok=True)
214
395
  if os.path.exists(sdk_dir):
215
396
  shutil.rmtree(sdk_dir)
216
397
 
217
398
  self._emit_step(2, total, "clone", self.INSTALL_STEPS[1][1])
218
- self._emit("Cloning %s into %s" % (config.PICO_SDK_REPO, sdk_dir))
399
+ # No --progress: percent spam floods the developer RPC bus.
400
+ # --branch accepts tags and branch names.
401
+ self._emit(
402
+ "Cloning %s @ %s into %s (quiet — can take several minutes)…"
403
+ % (config.PICO_SDK_REPO, version, sdk_dir)
404
+ )
219
405
  self._run_streamed(
220
406
  [
221
407
  "git",
222
408
  "clone",
223
- "--progress",
224
409
  "--depth",
225
410
  "1",
226
411
  "--branch",
227
- "master",
412
+ version,
228
413
  config.PICO_SDK_REPO,
229
414
  sdk_dir,
230
415
  ],
@@ -232,6 +417,8 @@ class Pico:
232
417
  )
233
418
 
234
419
  self._emit_step(3, total, "submodules", self.INSTALL_STEPS[2][1])
420
+ # No --progress: submodule file spam freezes the developer UI console.
421
+ self._emit("Initializing submodules (quiet — can take several minutes)…")
235
422
  self._run_streamed(
236
423
  [
237
424
  "git",
@@ -240,16 +427,15 @@ class Pico:
240
427
  "submodule",
241
428
  "update",
242
429
  "--init",
243
- "--progress",
244
430
  ],
245
431
  "git submodule update failed",
246
432
  )
247
433
 
248
434
  self._emit_step(4, total, "finalize", self.INSTALL_STEPS[3][1])
249
- meta = self._write_meta()
435
+ meta = self._write_meta(requested_version=version)
250
436
  self._emit(
251
- "Pico SDK installed (%s / %s)"
252
- % (meta.get("version"), meta.get("revision"))
437
+ "Pico SDK installed (%s / %s) [requested %s]"
438
+ % (meta.get("version"), meta.get("revision"), version)
253
439
  )
254
440
  self._emit(
255
441
  "%s%s/%s:done:Install complete"
@@ -257,29 +443,24 @@ class Pico:
257
443
  )
258
444
  return meta
259
445
 
260
- def sdk_update(self) -> dict[str, Any]:
261
- """Pull latest pico-sdk and refresh submodules."""
446
+ def sdk_update(self, version: str) -> dict[str, Any]:
447
+ """Checkout pico-sdk ``version`` and refresh submodules."""
448
+ version = self._require_version(version)
262
449
  total = len(self.UPDATE_STEPS)
263
- self._emit("Pico SDK update started.")
450
+ self._emit("Pico SDK update started (ref %s)." % version)
264
451
  self._ensure_toolchain(emit_steps=True, step_index=1, step_total=total)
265
452
 
266
453
  sdk_dir = config.PICO_SDK_DIR
267
454
  if not os.path.isdir(os.path.join(sdk_dir, ".git")):
268
- return self.sdk_install()
455
+ return self.sdk_install(version)
269
456
 
270
457
  self._emit_step(2, total, "fetch", self.UPDATE_STEPS[1][1])
271
- self._run_streamed(
272
- ["git", "-C", sdk_dir, "fetch", "--progress", "--depth", "1", "origin", "master"],
273
- "SDK fetch failed",
274
- )
275
-
276
- self._emit_step(3, total, "reset", self.UPDATE_STEPS[2][1])
277
- self._run_streamed(
278
- ["git", "-C", sdk_dir, "reset", "--hard", "origin/master"],
279
- "SDK reset failed",
280
- )
458
+ self._fetch_ref(sdk_dir, version)
459
+ self._emit_step(3, total, "checkout", self.UPDATE_STEPS[2][1])
460
+ self._checkout_fetch_head(sdk_dir)
281
461
 
282
462
  self._emit_step(4, total, "submodules", self.UPDATE_STEPS[3][1])
463
+ self._emit("Updating submodules (quiet — can take several minutes)…")
283
464
  self._run_streamed(
284
465
  [
285
466
  "git",
@@ -289,15 +470,14 @@ class Pico:
289
470
  "update",
290
471
  "--init",
291
472
  "--recursive",
292
- "--progress",
293
473
  ],
294
474
  "SDK submodule update failed",
295
475
  )
296
476
 
297
- meta = self._write_meta()
477
+ meta = self._write_meta(requested_version=version)
298
478
  self._emit(
299
- "Pico SDK updated (%s / %s)"
300
- % (meta.get("version"), meta.get("revision"))
479
+ "Pico SDK updated (%s / %s) [requested %s]"
480
+ % (meta.get("version"), meta.get("revision"), version)
301
481
  )
302
482
  self._emit(
303
483
  "%s%s/%s:done:Update complete"
@@ -360,24 +540,6 @@ class Pico:
360
540
  candidates.sort(key=lambda path: os.path.getmtime(path), reverse=True)
361
541
  return candidates[0]
362
542
 
363
- def _run_streamed(self, args: list[str], cwd: str, env: dict[str, str]) -> None:
364
- self.logger.info("$ %s", " ".join(args))
365
- process = subprocess.Popen(
366
- args,
367
- cwd=cwd,
368
- env=env,
369
- stdout=subprocess.PIPE,
370
- stderr=subprocess.STDOUT,
371
- text=True,
372
- bufsize=1,
373
- )
374
- assert process.stdout is not None
375
- for line in process.stdout:
376
- logging.info(line.rstrip("\n"))
377
- returncode = process.wait()
378
- if returncode != 0:
379
- raise PicoError("Command failed (%s): %s" % (returncode, " ".join(args)))
380
-
381
543
  def build_firmware(self, module_name: str, slug: str | None = None) -> dict[str, Any]:
382
544
  """
383
545
  Compile UF2 firmwares for a module (all uf2 kinds, or one slug).
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- VERSION = "1.49.5"
4
+ VERSION = "1.49.7"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cleepcli
3
- Version: 1.49.5
3
+ Version: 1.49.7
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
 
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