fontlab-python-instamix 1.0.2__tar.gz → 1.0.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 (48) hide show
  1. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/CHANGELOG.md +4 -0
  2. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/PKG-INFO +1 -1
  3. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/__version__.py +2 -2
  4. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/bootstrap.py +7 -1
  5. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/legacy.py +80 -7
  6. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/tests/test_parity.py +108 -0
  7. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/.gitignore +0 -0
  8. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/LICENSE +0 -0
  9. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/PLAN.md +0 -0
  10. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/README.md +0 -0
  11. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/build.sh +0 -0
  12. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/examples/com.example.hello.fontlabext/encoding/hello.enc +0 -0
  13. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/examples/com.example.hello.fontlabext/manifest.fontlabextj +0 -0
  14. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/examples/com.example.hello.fontlabext/scripts/Hello.py +0 -0
  15. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/install.vfpy +0 -0
  16. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/publish.sh +0 -0
  17. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/pyproject.toml +0 -0
  18. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/__init__.py +0 -0
  19. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/__main__.py +0 -0
  20. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/cli.py +0 -0
  21. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/dest.py +0 -0
  22. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/distinfo.py +0 -0
  23. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/env.py +0 -0
  24. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/extension.py +0 -0
  25. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/gui.py +0 -0
  26. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/initscript.py +0 -0
  27. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/launch.py +0 -0
  28. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/launchers.py +0 -0
  29. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/ledger.py +0 -0
  30. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/manifest.py +0 -0
  31. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/markers.py +0 -0
  32. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/packages.py +0 -0
  33. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/platformdirs.py +0 -0
  34. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/stub.py +0 -0
  35. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/stub_install.vfpy +0 -0
  36. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/uv.py +0 -0
  37. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/vcs.py +0 -0
  38. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/venv.py +0 -0
  39. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/wrap.py +0 -0
  40. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/stub/install.vfpy +0 -0
  41. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/test.sh +0 -0
  42. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/tests/conftest.py +0 -0
  43. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/tests/test_bootstrap_cli.py +0 -0
  44. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/tests/test_dest.py +0 -0
  45. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/tests/test_env.py +0 -0
  46. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/tests/test_extension.py +0 -0
  47. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/tests/test_manifest.py +0 -0
  48. {fontlab_python_instamix-1.0.2 → fontlab_python_instamix-1.0.3}/tests/test_packages.py +0 -0
@@ -3,6 +3,10 @@ this_file: CHANGELOG.md
3
3
  ---
4
4
  # Changelog
5
5
 
6
+ ## 1.0.3 (2026-11-16)
7
+
8
+ - Legacy migration moves files the legacy log recorded (`hashes`, `kept`) at new install targets to `Extensions/.instamix/backup/<id>/<UTC>/` instead of refusing, restores them if the install fails, and still applies after an earlier `migrated_to` uninstall. Unrecorded collisions still refuse. Reruns never move instamix's own files, backup folders are never overwritten, and a rollback restore is logged as `restored`.
9
+
6
10
  ## 1.0.2 (2026-11-16)
7
11
 
8
12
  - Sibling detection now follows legacy `fontlab-fly`: a neighbouring folder counts only if it has `install.vfpy` and a pyproject with a `[tool.fontlab-install]` table and valid `id`, matched by normalised table or project name. Read-only checkouts such as TypeRig no longer break installs; their specs go to uv.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: fontlab-python-instamix
3
- Version: 1.0.2
3
+ Version: 1.0.3
4
4
  Summary: Stdlib-only installer for FontLab 9 extensions, scripts and Python packages
5
5
  Project-URL: Repository, https://github.com/fontlabcom/fontlab-python-instamix
6
6
  License-Expression: Apache-2.0
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '1.0.2'
22
- __version_tuple__ = version_tuple = (1, 0, 2)
21
+ __version__ = version = '1.0.3'
22
+ __version_tuple__ = version_tuple = (1, 0, 3)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -365,19 +365,25 @@ def _install_checkout(
365
365
  finish=lambda target: _finish(project, data_manifest, target),
366
366
  fields={"init_script": True} if project.init_script else None,
367
367
  ),
368
+ data,
368
369
  )
369
370
  if project.init_script:
370
371
  initscript.update(data)
371
372
  return record
372
373
 
373
374
 
374
- def _install_after_migration(migrated, ext_id: str, install):
375
+ def _install_after_migration(migrated, ext_id: str, install, data: Path | None = None):
375
376
  """Run *install*; after a legacy migration, say how to recover from a failure."""
376
377
  try:
377
378
  return install()
378
379
  except Exception as exc:
379
380
  if not migrated:
380
381
  raise
382
+ legacy.restore(migrated.get("moved") or [], data, ext_id)
383
+ if migrated.get("backup_only"):
384
+ raise BootstrapError(
385
+ f"The new install of {ext_id} failed: {exc}. Files moved aside from a legacy install were put back. Fix the cause and run install.vfpy again."
386
+ ) from exc
381
387
  raise BootstrapError(
382
388
  f"The legacy install of {ext_id} was removed, but the new install failed: {exc}. Fix the cause and run install.vfpy again."
383
389
  ) from exc
@@ -164,17 +164,88 @@ def _prune(folder: Path, scripts: Path) -> None:
164
164
  folder = folder.parent
165
165
 
166
166
 
167
+ def previous_install(data: Path, ext_id: str) -> dict | None:
168
+ """The last ``install`` record of the log, even after a ``migrated_to`` uninstall."""
169
+ state, path = None, log_path(data, ext_id)
170
+ if path.is_file():
171
+ for line in path.read_text(encoding="utf-8", errors="replace").splitlines():
172
+ try:
173
+ record = json.loads(line)
174
+ except ValueError:
175
+ continue
176
+ if isinstance(record, dict) and record.get("action") == "install":
177
+ state = record
178
+ return state
179
+
180
+
181
+ def _recorded(data: Path, state: dict) -> list[Path]:
182
+ """Paths an install record lists under ``files``, ``hashes`` or ``kept``."""
183
+ raws = list(state.get("files") or []) + list(state.get("hashes") or {})
184
+ for item in state.get("kept") or []:
185
+ raws.append(item[0] if isinstance(item, (list, tuple)) and item else item)
186
+ paths = [Path(raw) if Path(raw).is_absolute() else data / raw for raw in raws if isinstance(raw, str)]
187
+ return list(dict.fromkeys(paths))
188
+
189
+
190
+ def move_aside(data: Path, ext_id: str, state: dict, targets: set[str]) -> list[tuple[str, str]]:
191
+ """Move recorded files that sit at install *targets* into the backup folder.
192
+
193
+ Returns ``[(original, backup)]``. Unrecorded files are never touched.
194
+ """
195
+ if ledger.read(data, ext_id): # instamix already installed it: files there are ours
196
+ return []
197
+ stamp = time.strftime("%Y%m%dT%H%M%SZ", time.gmtime())
198
+ root = data / "Extensions" / ".instamix" / "backup" / ext_id
199
+ base, count = root / stamp, 1
200
+ while base.exists(): # never overwrite an earlier backup
201
+ count += 1
202
+ base = root / f"{stamp}-{count}"
203
+ moved = []
204
+ for path in _recorded(data, state):
205
+ rel = _rel(data, str(path))
206
+ if rel not in targets or not (path.is_symlink() or path.exists()) or not _inside(data, path):
207
+ continue
208
+ backup = base / rel
209
+ backup.parent.mkdir(parents=True, exist_ok=True)
210
+ os.replace(path, backup)
211
+ moved.append((str(path), str(backup)))
212
+ return moved
213
+
214
+
215
+ def restore(moved: list, data: Path | None = None, ext_id: str | None = None) -> None:
216
+ """Put files moved by :func:`move_aside` back; log it when *data* and *ext_id* are given."""
217
+ for original, backup in reversed(moved):
218
+ if Path(backup).is_symlink() or Path(backup).exists():
219
+ Path(original).parent.mkdir(parents=True, exist_ok=True)
220
+ os.replace(backup, original)
221
+ if moved and data is not None and ext_id:
222
+ _log(data, ext_id, {"action": "restored", "id": ext_id, "restored": moved, "time": time.strftime("%Y-%m-%dT%H:%M:%S")})
223
+
224
+
225
+ def _log(data: Path, ext_id: str, record: dict) -> None:
226
+ with log_path(data, ext_id).open("a", encoding="utf-8") as stream:
227
+ stream.write(json.dumps(record, sort_keys=True) + "\n")
228
+
229
+
167
230
  def migrate(data: Path, ext_id: str, known: set[str], targets: set[str]) -> dict | None:
168
- """Remove the legacy install of *ext_id*; return a summary, or None if none exists.
231
+ """Remove the legacy install of *ext_id*; return a summary, or None if nothing was done.
169
232
 
170
233
  *known* holds SHA-256 digests of files instamix will install; *targets*
171
- holds data-relative POSIX paths it will create. A kept legacy file at
172
- one of those targets would block the new install, so nothing is
173
- removed and :class:`MigrationError` lists the conflicts.
234
+ holds data-relative POSIX paths it will create. A kept legacy file in
235
+ the log's ``files`` at one of those targets would block the new install,
236
+ so nothing is removed and :class:`MigrationError` lists the conflicts.
237
+ Other files the log recorded (``hashes``, ``kept``) at a target are older
238
+ copies: they are moved to ``Extensions/.instamix/backup/<id>/<UTC>/``.
239
+ After an earlier migration the previous install record is used again.
174
240
  """
175
241
  data = Path(data)
176
242
  state = installed(data, ext_id)
177
243
  if not state:
244
+ prior = previous_install(data, ext_id)
245
+ moved = move_aside(data, ext_id, prior, targets) if prior else []
246
+ if moved:
247
+ _log(data, ext_id, {"action": "backup", "id": ext_id, "moved": moved, "time": time.strftime("%Y-%m-%dT%H:%M:%S")})
248
+ return {"id": ext_id, "removed": [], "kept": [], "moved": moved, "backup_only": True}
178
249
  return None
179
250
  remove, kept = plan(data, state, known)
180
251
  blocked = [path for path, _ in kept if _rel(data, path) in targets]
@@ -183,12 +254,14 @@ def migrate(data: Path, ext_id: str, known: set[str], targets: set[str]) -> dict
183
254
  for path in sorted(remove, key=lambda p: len(p.parts), reverse=True):
184
255
  if path.is_symlink() or path.exists():
185
256
  _remove(path, data)
257
+ moved = move_aside(data, ext_id, state, targets)
186
258
  record = {"action": "uninstall", "id": ext_id, "time": time.strftime("%Y-%m-%dT%H:%M:%S"), "migrated_to": "fontlab-instamix"}
187
259
  record["kept"] = [path for path, _ in kept]
188
- with log_path(data, ext_id).open("a", encoding="utf-8") as stream:
189
- stream.write(json.dumps(record, sort_keys=True) + "\n")
260
+ if moved:
261
+ record["moved"] = moved
262
+ _log(data, ext_id, record)
190
263
  cleanup_shared(data)
191
- return {"id": ext_id, "removed": [str(p) for p in remove], "kept": kept}
264
+ return {"id": ext_id, "removed": [str(p) for p in remove], "kept": kept, "moved": moved}
192
265
 
193
266
 
194
267
  def _rel(data: Path, path: str) -> str:
@@ -689,3 +689,111 @@ def test_initscript_when_user_content_then_file_kept(tmp_path):
689
689
  initscript.update(tmp_path)
690
690
  initscript.update(tmp_path, remove=True)
691
691
  assert "mine" in (tmp_path / "initScript.py").read_text()
692
+
693
+
694
+ def _stale_copy(data, root, ext_id):
695
+ """Add an old-version copy of Tool.py that the log lists only under hashes."""
696
+ old = data / "Scripts" / "Old Tool.py"
697
+ old.write_text("print('old version')\n")
698
+ log = legacy.log_path(data, ext_id)
699
+ record = json.loads(log.read_text().splitlines()[0])
700
+ record["hashes"] = {**record.get("hashes", {}), str(old): "0" * 64}
701
+ log.write_text(json.dumps(record) + "\n")
702
+ return old
703
+
704
+
705
+ def _project_with_old_tool(tmp_path):
706
+ root = _project(tmp_path / "proj-a")
707
+ (root / "Scripts").mkdir(exist_ok=True)
708
+ (root / "Scripts" / "Old Tool.py").write_text("print('new')\n")
709
+ return root
710
+
711
+
712
+ def test_install_project_when_recorded_stale_copy_then_moved_aside(data, tmp_path):
713
+ root = _project_with_old_tool(tmp_path)
714
+ _legacy(data, root, "com.example.proja", hashed=True)
715
+ old = _stale_copy(data, root, "com.example.proja")
716
+ bootstrap.install_project(root / "install.vfpy", data, requirements=NO_REQS)
717
+ assert old.exists() # the new file now sits there
718
+ backups = list((data / "Extensions" / ".instamix" / "backup" / "com.example.proja").rglob("Old Tool.py"))
719
+ assert [b.read_text() for b in backups] == ["print('old version')\n"]
720
+ assert backups[0].as_posix().endswith("/Scripts/Old Tool.py")
721
+ log = legacy.log_path(data, "com.example.proja").read_text().splitlines()
722
+ assert json.loads(log[-1])["moved"]
723
+
724
+
725
+ def test_install_project_when_already_migrated_then_stale_copy_moved_aside(data, tmp_path):
726
+ root = _project_with_old_tool(tmp_path)
727
+ _legacy(data, root, "com.example.proja", hashed=True)
728
+ old = _stale_copy(data, root, "com.example.proja")
729
+ log = legacy.log_path(data, "com.example.proja")
730
+ with log.open("a") as stream:
731
+ stream.write(json.dumps({"action": "uninstall", "id": "com.example.proja", "migrated_to": "fontlab-instamix"}) + "\n")
732
+ assert legacy.installed(data, "com.example.proja") is None
733
+ bootstrap.install_project(root / "install.vfpy", data, requirements=NO_REQS)
734
+ assert old.read_text() == "print('new')\n"
735
+ assert list((data / "Extensions" / ".instamix" / "backup").rglob("Old Tool.py"))
736
+
737
+
738
+ def test_install_project_when_unrecorded_collision_then_refused(data, tmp_path):
739
+ root = _project_with_old_tool(tmp_path)
740
+ _legacy(data, root, "com.example.proja", hashed=True)
741
+ (data / "Scripts" / "Old Tool.py").write_text("mine\n")
742
+ with pytest.raises(Exception, match="refusing to overwrite"):
743
+ bootstrap.install_project(root / "install.vfpy", data, requirements=NO_REQS)
744
+ assert (data / "Scripts" / "Old Tool.py").read_text() == "mine\n"
745
+
746
+
747
+ def test_legacy_restore_when_moved_then_files_back(data):
748
+ state = {"files": ["Scripts/a.py"]}
749
+ (data / "Scripts").mkdir(parents=True)
750
+ (data / "Scripts" / "a.py").write_text("x")
751
+ moved = legacy.move_aside(data, "com.example.x", state, {"Scripts/a.py"})
752
+ assert not (data / "Scripts" / "a.py").exists()
753
+ legacy.restore(moved)
754
+ assert (data / "Scripts" / "a.py").read_text() == "x"
755
+
756
+
757
+ def _migrated_state(data, root):
758
+ _legacy(data, root, "com.example.proja", hashed=True)
759
+ old = _stale_copy(data, root, "com.example.proja")
760
+ log = legacy.log_path(data, "com.example.proja")
761
+ with log.open("a") as stream:
762
+ stream.write(json.dumps({"action": "uninstall", "id": "com.example.proja", "migrated_to": "fontlab-instamix"}) + "\n")
763
+ return old
764
+
765
+
766
+ def test_install_project_when_rerun_from_migrated_state_then_one_backup_only(data, tmp_path):
767
+ root = _project_with_old_tool(tmp_path)
768
+ old = _migrated_state(data, root)
769
+ backups = data / "Extensions" / ".instamix" / "backup"
770
+ for _ in range(3):
771
+ bootstrap.install_project(root / "install.vfpy", data, requirements=NO_REQS)
772
+ assert old.read_text() == "print('new')\n"
773
+ found = list(backups.rglob("Old Tool.py"))
774
+ assert [b.read_text() for b in found] == ["print('old version')\n"]
775
+
776
+
777
+ def test_move_aside_when_same_second_then_backups_not_overwritten(data):
778
+ (data / "Scripts").mkdir(parents=True)
779
+ state = {"files": ["Scripts/a.py"]}
780
+ for text in ("one", "two"):
781
+ (data / "Scripts" / "a.py").write_text(text)
782
+ legacy.move_aside(data, "com.example.x", state, {"Scripts/a.py"})
783
+ found = sorted(b.read_text() for b in (data / "Extensions").rglob("a.py"))
784
+ assert found == ["one", "two"]
785
+
786
+
787
+ def test_install_project_when_install_fails_after_move_then_files_restored(data, tmp_path, monkeypatch):
788
+ root = _project_with_old_tool(tmp_path)
789
+ old = _migrated_state(data, root)
790
+
791
+ def boom(*args, **kwargs):
792
+ raise RuntimeError("boom")
793
+
794
+ monkeypatch.setattr(extension, "install_folder", boom)
795
+ with pytest.raises(bootstrap.BootstrapError, match="put back"):
796
+ bootstrap.install_project(root / "install.vfpy", data, requirements=NO_REQS)
797
+ assert old.read_text() == "print('old version')\n"
798
+ last = json.loads(legacy.log_path(data, "com.example.proja").read_text().splitlines()[-1])
799
+ assert last["action"] == "restored"