cleepcli 1.49.2__tar.gz → 1.49.3__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.2/cleepcli.egg-info → cleepcli-1.49.3}/PKG-INFO +3 -1
  2. {cleepcli-1.49.2 → cleepcli-1.49.3}/README.md +2 -0
  3. {cleepcli-1.49.2 → cleepcli-1.49.3}/bin/ccli +4 -3
  4. {cleepcli-1.49.2 → cleepcli-1.49.3}/bin/cleep-cli +4 -3
  5. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/version.py +1 -1
  6. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/watchsvc.py +52 -8
  7. {cleepcli-1.49.2 → cleepcli-1.49.3/cleepcli.egg-info}/PKG-INFO +3 -1
  8. {cleepcli-1.49.2 → cleepcli-1.49.3}/tests/test_watchsvc.py +41 -3
  9. {cleepcli-1.49.2 → cleepcli-1.49.3}/LICENSE +0 -0
  10. {cleepcli-1.49.2 → cleepcli-1.49.3}/MANIFEST.in +0 -0
  11. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/__init__.py +0 -0
  12. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/check.py +0 -0
  13. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/ci.py +0 -0
  14. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/cleepapi.py +0 -0
  15. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/config.py +0 -0
  16. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/console.py +0 -0
  17. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/docs.py +0 -0
  18. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/file.py +0 -0
  19. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/git.py +0 -0
  20. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/module.py +0 -0
  21. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/package.py +0 -0
  22. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/pico.py +0 -0
  23. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/systemd/cleep-watch.service +0 -0
  24. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/test.py +0 -0
  25. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/tools.py +0 -0
  26. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli/watch.py +0 -0
  27. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli.egg-info/SOURCES.txt +0 -0
  28. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli.egg-info/dependency_links.txt +0 -0
  29. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli.egg-info/requires.txt +0 -0
  30. {cleepcli-1.49.2 → cleepcli-1.49.3}/cleepcli.egg-info/top_level.txt +0 -0
  31. {cleepcli-1.49.2 → cleepcli-1.49.3}/pyproject.toml +0 -0
  32. {cleepcli-1.49.2 → cleepcli-1.49.3}/requirements.txt +0 -0
  33. {cleepcli-1.49.2 → cleepcli-1.49.3}/setup.cfg +0 -0
  34. {cleepcli-1.49.2 → cleepcli-1.49.3}/setup.py +0 -0
  35. {cleepcli-1.49.2 → cleepcli-1.49.3}/tests/test_check.py +0 -0
  36. {cleepcli-1.49.2 → cleepcli-1.49.3}/tests/test_config.py +0 -0
  37. {cleepcli-1.49.2 → cleepcli-1.49.3}/tests/test_console.py +0 -0
  38. {cleepcli-1.49.2 → cleepcli-1.49.3}/tests/test_coverage.py +0 -0
  39. {cleepcli-1.49.2 → cleepcli-1.49.3}/tests/test_docs_breaking.py +0 -0
  40. {cleepcli-1.49.2 → cleepcli-1.49.3}/tests/test_file_sync_all.py +0 -0
  41. {cleepcli-1.49.2 → cleepcli-1.49.3}/tests/test_module_scaffold.py +0 -0
  42. {cleepcli-1.49.2 → cleepcli-1.49.3}/tests/test_pico.py +0 -0
  43. {cleepcli-1.49.2 → cleepcli-1.49.3}/tests/test_watch.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cleepcli
3
- Version: 1.49.2
3
+ Version: 1.49.3
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
@@ -96,6 +96,8 @@ cleep-cli watchsvc enable
96
96
 
97
97
  The unit runs `cleep-cli watch`, survives `systemctl restart cleep`, and on each start performs a catch-up `syncall` so files written while the watcher was down are applied.
98
98
 
99
+ After `pip install` / upgrade of `cleepcli`, the next `watchsvc install` (idempotent ensure) restarts the unit when the on-disk binary is newer than the running process, so the watcher loads the new CLI without a forced bounce on every Cleep boot.
100
+
99
101
  Manual one-shot resync (when the UI looks stale) — `syncall` also mints a fresh asset bust and reloads the device UI:
100
102
 
101
103
  ```
@@ -60,6 +60,8 @@ cleep-cli watchsvc enable
60
60
 
61
61
  The unit runs `cleep-cli watch`, survives `systemctl restart cleep`, and on each start performs a catch-up `syncall` so files written while the watcher was down are applied.
62
62
 
63
+ After `pip install` / upgrade of `cleepcli`, the next `watchsvc install` (idempotent ensure) restarts the unit when the on-disk binary is newer than the running process, so the watcher loads the new CLI without a forced bounce on every Cleep boot.
64
+
63
65
  Manual one-shot resync (when the UI looks stale) — `syncall` also mints a fresh asset bust and reloads the device UI:
64
66
 
65
67
  ```
@@ -438,7 +438,7 @@ def watch(quiet, loglevel, rpc_url, skip_catchup):
438
438
  @click.option(
439
439
  '--restart-if-active',
440
440
  is_flag=True,
441
- help='With install: restart the unit if it is already running (pick up a new cleep-cli).',
441
+ help='With install: force-restart if already running. Default install also restarts when the unit changed or cleep-cli binary is newer than the running watch.',
442
442
  )
443
443
  def watchsvc_cmd(action, restart_if_active):
444
444
  """
@@ -451,9 +451,10 @@ def watchsvc_cmd(action, restart_if_active):
451
451
  cleep-cli watchsvc install
452
452
  cleep-cli watchsvc enable
453
453
 
454
- After upgrading cleep-cli (pip), restart the watcher so it loads the new code::
454
+ After ``pip install cleepcli``, a later ``watchsvc install`` (or enable) restarts
455
+ the watcher when the on-disk binary is newer than the running process. Force with::
455
456
 
456
- cleep-cli watchsvc restart
457
+ cleep-cli watchsvc install --restart-if-active
457
458
  """
458
459
  svc = WatchService()
459
460
  if action == 'status':
@@ -438,7 +438,7 @@ def watch(quiet, loglevel, rpc_url, skip_catchup):
438
438
  @click.option(
439
439
  '--restart-if-active',
440
440
  is_flag=True,
441
- help='With install: restart the unit if it is already running (pick up a new cleep-cli).',
441
+ help='With install: force-restart if already running. Default install also restarts when the unit changed or cleep-cli binary is newer than the running watch.',
442
442
  )
443
443
  def watchsvc_cmd(action, restart_if_active):
444
444
  """
@@ -451,9 +451,10 @@ def watchsvc_cmd(action, restart_if_active):
451
451
  cleep-cli watchsvc install
452
452
  cleep-cli watchsvc enable
453
453
 
454
- After upgrading cleep-cli (pip), restart the watcher so it loads the new code::
454
+ After ``pip install cleepcli``, a later ``watchsvc install`` (or enable) restarts
455
+ the watcher when the on-disk binary is newer than the running process. Force with::
455
456
 
456
- cleep-cli watchsvc restart
457
+ cleep-cli watchsvc install --restart-if-active
457
458
  """
458
459
  svc = WatchService()
459
460
  if action == 'status':
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- VERSION = "1.49.2"
4
+ VERSION = "1.49.3"
@@ -63,15 +63,54 @@ class WatchService:
63
63
  return True
64
64
  return new != old
65
65
 
66
+ @staticmethod
67
+ def _cli_executable_path():
68
+ """
69
+ On-disk ``cleep-cli`` path used by the watch unit ExecStart.
70
+ """
71
+ return shutil.which("cleep-cli") or "/usr/local/bin/cleep-cli"
72
+
73
+ def _cli_binary_newer_than_running(self):
74
+ """
75
+ Return True when the installed cleep-cli binary is newer than the
76
+ running watch main process (typical after ``pip install cleepcli``).
77
+
78
+ Used so ``watchsvc install`` (without ``--restart-if-active``) still
79
+ picks up an upgraded CLI once, without bouncing on every Cleep boot.
80
+ """
81
+ path = self._cli_executable_path()
82
+ if not path or not os.path.isfile(path):
83
+ return False
84
+ try:
85
+ bin_mtime = os.path.getmtime(path)
86
+ except OSError:
87
+ return False
88
+ resp = self._systemctl(
89
+ "show",
90
+ "-p",
91
+ "ExecMainStartTimestampUSec",
92
+ "--value",
93
+ WATCH_SERVICE,
94
+ timeout=5.0,
95
+ )
96
+ raw = "".join(resp.get("stdout") or []).strip()
97
+ if not raw.isdigit():
98
+ return False
99
+ start_sec = int(raw) / 1_000_000.0
100
+ if start_sec <= 0:
101
+ return False
102
+ return bin_mtime > start_sec
103
+
66
104
  def install(self, restart_if_active=False):
67
105
  """
68
106
  Copy the bundled unit to systemd and reload the daemon.
69
107
 
70
108
  Args:
71
- restart_if_active (bool): when True, restart the unit if it is
72
- already running so a new cleep-cli binary/unit is picked up.
73
- Default False: developer ``ensure`` calls install on every
74
- Cleep start and must not bounce the watcher (catch-up would
109
+ restart_if_active (bool): when True, always restart the unit if it
110
+ is already running. Default False: still restart when the unit
111
+ file changed or when the on-disk cleep-cli binary is newer than
112
+ the running watch process (pip upgrade). Idempotent ensure on
113
+ every Cleep boot must not bounce otherwise (catch-up would
75
114
  restart Cleep again).
76
115
 
77
116
  Returns:
@@ -83,6 +122,7 @@ class WatchService:
83
122
  return False
84
123
  unit_changed = self._unit_content_changed(src)
85
124
  was_active = self.is_active()
125
+ cli_upgraded = was_active and self._cli_binary_newer_than_running()
86
126
  try:
87
127
  os.makedirs(os.path.dirname(WATCH_UNIT_DST), exist_ok=True)
88
128
  shutil.copyfile(src, WATCH_UNIT_DST)
@@ -93,11 +133,15 @@ class WatchService:
93
133
  self.logger.error("systemctl daemon-reload failed after install")
94
134
  return False
95
135
  self.logger.info("Installed %s", WATCH_UNIT_DST)
96
- # Restart when asked (package upgrade) or when the unit file changed
97
- # while the service was already running.
98
- if was_active and (restart_if_active or unit_changed):
136
+ # Restart after forced upgrade, unit change, or pip-replaced cleep-cli.
137
+ if was_active and (restart_if_active or unit_changed or cli_upgraded):
99
138
  self.logger.info(
100
- "Restarting %s to apply watcher changes", WATCH_SERVICE
139
+ "Restarting %s to apply watcher changes "
140
+ "(forced=%s unit_changed=%s cli_upgraded=%s)",
141
+ WATCH_SERVICE,
142
+ restart_if_active,
143
+ unit_changed,
144
+ cli_upgraded,
101
145
  )
102
146
  return self.restart()
103
147
  return True
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cleepcli
3
- Version: 1.49.2
3
+ Version: 1.49.3
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
@@ -96,6 +96,8 @@ cleep-cli watchsvc enable
96
96
 
97
97
  The unit runs `cleep-cli watch`, survives `systemctl restart cleep`, and on each start performs a catch-up `syncall` so files written while the watcher was down are applied.
98
98
 
99
+ After `pip install` / upgrade of `cleepcli`, the next `watchsvc install` (idempotent ensure) restarts the unit when the on-disk binary is newer than the running process, so the watcher loads the new CLI without a forced bounce on every Cleep boot.
100
+
99
101
  Manual one-shot resync (when the UI looks stale) — `syncall` also mints a fresh asset bust and reloads the device UI:
100
102
 
101
103
  ```
@@ -42,7 +42,7 @@ def test_install_does_not_restart_when_active_and_unit_unchanged():
42
42
  "cleepcli.watchsvc.os.makedirs"
43
43
  ), patch("cleepcli.watchsvc.os.path.isfile", return_value=True), patch.object(
44
44
  svc, "_unit_content_changed", return_value=False
45
- ):
45
+ ), patch.object(svc, "_cli_binary_newer_than_running", return_value=False):
46
46
  assert svc.install() is True
47
47
  svc.restart.assert_not_called()
48
48
 
@@ -58,7 +58,7 @@ def test_install_restarts_when_active_and_unit_changed():
58
58
  "cleepcli.watchsvc.os.makedirs"
59
59
  ), patch("cleepcli.watchsvc.os.path.isfile", return_value=True), patch.object(
60
60
  svc, "_unit_content_changed", return_value=True
61
- ):
61
+ ), patch.object(svc, "_cli_binary_newer_than_running", return_value=False):
62
62
  assert svc.install() is True
63
63
  svc.restart.assert_called_once_with()
64
64
 
@@ -74,11 +74,49 @@ def test_install_restarts_when_flag_and_active():
74
74
  "cleepcli.watchsvc.os.makedirs"
75
75
  ), patch("cleepcli.watchsvc.os.path.isfile", return_value=True), patch.object(
76
76
  svc, "_unit_content_changed", return_value=False
77
- ):
77
+ ), patch.object(svc, "_cli_binary_newer_than_running", return_value=False):
78
78
  assert svc.install(restart_if_active=True) is True
79
79
  svc.restart.assert_called_once_with()
80
80
 
81
81
 
82
+ def test_install_restarts_when_cli_binary_newer_than_running():
83
+ """pip upgrade leaves a newer on-disk binary; install must bounce watch once."""
84
+ svc = WatchService()
85
+ svc.console = Mock()
86
+ svc.console.command.return_value = {"returncode": 0, "stdout": "", "stderr": ""}
87
+ svc.is_active = Mock(return_value=True)
88
+ svc.restart = Mock(return_value=True)
89
+
90
+ with patch("cleepcli.watchsvc.shutil.copyfile"), patch(
91
+ "cleepcli.watchsvc.os.makedirs"
92
+ ), patch("cleepcli.watchsvc.os.path.isfile", return_value=True), patch.object(
93
+ svc, "_unit_content_changed", return_value=False
94
+ ), patch.object(svc, "_cli_binary_newer_than_running", return_value=True):
95
+ assert svc.install() is True
96
+ svc.restart.assert_called_once_with()
97
+
98
+
99
+ def test_cli_binary_newer_than_running_compares_mtime_to_service_start():
100
+ svc = WatchService()
101
+ svc.console = Mock()
102
+ # service started at t=100s (100_000_000 us)
103
+ svc.console.command.return_value = {
104
+ "returncode": 0,
105
+ "stdout": ["100000000"],
106
+ "stderr": "",
107
+ }
108
+
109
+ with patch.object(WatchService, "_cli_executable_path", return_value="/usr/local/bin/cleep-cli"), patch(
110
+ "cleepcli.watchsvc.os.path.isfile", return_value=True
111
+ ), patch("cleepcli.watchsvc.os.path.getmtime", return_value=150.0):
112
+ assert svc._cli_binary_newer_than_running() is True
113
+
114
+ with patch.object(WatchService, "_cli_executable_path", return_value="/usr/local/bin/cleep-cli"), patch(
115
+ "cleepcli.watchsvc.os.path.isfile", return_value=True
116
+ ), patch("cleepcli.watchsvc.os.path.getmtime", return_value=50.0):
117
+ assert svc._cli_binary_newer_than_running() is False
118
+
119
+
82
120
  def test_enable_installs_when_missing():
83
121
  svc = WatchService()
84
122
  svc.install = Mock(return_value=True)
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
File without changes