fontlab-python-instamix 1.0.1__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.1 → fontlab_python_instamix-1.0.3}/CHANGELOG.md +10 -0
  2. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/PKG-INFO +3 -2
  3. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/README.md +2 -1
  4. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/__version__.py +2 -2
  5. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/bootstrap.py +38 -12
  6. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/extension.py +28 -1
  7. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/initscript.py +3 -0
  8. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/legacy.py +80 -7
  9. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/tests/test_bootstrap_cli.py +61 -0
  10. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/tests/test_parity.py +122 -0
  11. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/.gitignore +0 -0
  12. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/LICENSE +0 -0
  13. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/PLAN.md +0 -0
  14. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/build.sh +0 -0
  15. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/examples/com.example.hello.fontlabext/encoding/hello.enc +0 -0
  16. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/examples/com.example.hello.fontlabext/manifest.fontlabextj +0 -0
  17. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/examples/com.example.hello.fontlabext/scripts/Hello.py +0 -0
  18. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/install.vfpy +0 -0
  19. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/publish.sh +0 -0
  20. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/pyproject.toml +0 -0
  21. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/__init__.py +0 -0
  22. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/__main__.py +0 -0
  23. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/cli.py +0 -0
  24. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/dest.py +0 -0
  25. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/distinfo.py +0 -0
  26. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/env.py +0 -0
  27. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/gui.py +0 -0
  28. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/launch.py +0 -0
  29. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/launchers.py +0 -0
  30. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/ledger.py +0 -0
  31. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/manifest.py +0 -0
  32. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/markers.py +0 -0
  33. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/packages.py +0 -0
  34. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/platformdirs.py +0 -0
  35. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/stub.py +0 -0
  36. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/stub_install.vfpy +0 -0
  37. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/uv.py +0 -0
  38. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/vcs.py +0 -0
  39. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/venv.py +0 -0
  40. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/src/fontlab_instamix/wrap.py +0 -0
  41. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/stub/install.vfpy +0 -0
  42. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/test.sh +0 -0
  43. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/tests/conftest.py +0 -0
  44. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/tests/test_dest.py +0 -0
  45. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/tests/test_env.py +0 -0
  46. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/tests/test_extension.py +0 -0
  47. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/tests/test_manifest.py +0 -0
  48. {fontlab_python_instamix-1.0.1 → fontlab_python_instamix-1.0.3}/tests/test_packages.py +0 -0
@@ -3,6 +3,16 @@ 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
+
10
+ ## 1.0.2 (2026-11-16)
11
+
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.
13
+ - Uninstall removes empty folders that instamix created under `Scripts/` (never `Scripts/` itself) and deletes `initScript.py` when only instamix's block was in it.
14
+ - 147 offline pytest tests; an offline run installed and uninstalled all 13 workspace packages in one data folder.
15
+
6
16
  ## 1.0.1 (2026-11-16)
7
17
 
8
18
  - Legacy `install.vfpy` parity in `bootstrap.install_project`: environment markers (`markers.py`), hatch-vcs versions (`vcs.py`), dist-info (`distinfo.py`), the fontlabapp `initScript.py` block (`initscript.py`), `Scripts/Instamix` launchers (`launchers.py`, `launch.py`), plugin bundles under `Extensions/<kind>`, Scripts mapping and junk filter, hatch/project fallbacks for packages and dependencies, and migration of legacy installs (`legacy.py`).
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: fontlab-python-instamix
3
- Version: 1.0.1
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
@@ -121,7 +121,8 @@ It matches the legacy `install.vfpy`:
121
121
  - The version comes from the static `[project].version`, then the hatch-vcs version file, `PKG-INFO`, `git describe` and the fallback version.
122
122
  - `<dist>-<version>.dist-info` (INSTALLER `fontlab-instamix`) is written so `importlib.metadata` finds the package. Uninstall removes it and never follows the editable package link.
123
123
  - `Scripts/Instamix/` holds `List Extensions.py` and `Uninstall <id>.py`.
124
- - For fontlabapp, the `fontlabapp.plugins` block is added to `initScript.py`, and removed again on uninstall.
124
+ - For fontlabapp, the `fontlabapp.plugins` block is added to `initScript.py`, and removed again on uninstall; `initScript.py` is deleted if nothing else is in it. Empty folders under `Scripts/` that instamix created are pruned too (never `Scripts/` itself, never a folder that existed before install).
125
+ - Dependencies uv installed from PyPI (for example fonttools) stay after uninstall: other extensions may share them, and the legacy installer also kept them. Sibling checkouts are detected only if their pyproject has a `[tool.fontlab-install]` table with a valid `id`; anything else (such as TypeRig) goes to uv.
125
126
  - A legacy `install.vfpy` install of the same id is migrated first. Files it logged are removed; changed files are kept. If a kept file would collide with the new install, the install stops before it changes anything. Shared legacy tools (`fontlab_install.py`, `Scripts/Extensions/`) are removed once no legacy install remains.
126
127
 
127
128
  ## Development
@@ -109,7 +109,8 @@ It matches the legacy `install.vfpy`:
109
109
  - The version comes from the static `[project].version`, then the hatch-vcs version file, `PKG-INFO`, `git describe` and the fallback version.
110
110
  - `<dist>-<version>.dist-info` (INSTALLER `fontlab-instamix`) is written so `importlib.metadata` finds the package. Uninstall removes it and never follows the editable package link.
111
111
  - `Scripts/Instamix/` holds `List Extensions.py` and `Uninstall <id>.py`.
112
- - For fontlabapp, the `fontlabapp.plugins` block is added to `initScript.py`, and removed again on uninstall.
112
+ - For fontlabapp, the `fontlabapp.plugins` block is added to `initScript.py`, and removed again on uninstall; `initScript.py` is deleted if nothing else is in it. Empty folders under `Scripts/` that instamix created are pruned too (never `Scripts/` itself, never a folder that existed before install).
113
+ - Dependencies uv installed from PyPI (for example fonttools) stay after uninstall: other extensions may share them, and the legacy installer also kept them. Sibling checkouts are detected only if their pyproject has a `[tool.fontlab-install]` table with a valid `id`; anything else (such as TypeRig) goes to uv.
113
114
  - A legacy `install.vfpy` install of the same id is migrated first. Files it logged are removed; changed files are kept. If a kept file would collide with the new install, the install stops before it changes anything. Shared legacy tools (`fontlab_install.py`, `Scripts/Extensions/`) are removed once no legacy install remains.
114
115
 
115
116
  ## Development
@@ -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.1'
22
- __version_tuple__ = version_tuple = (1, 0, 1)
21
+ __version__ = version = '1.0.3'
22
+ __version_tuple__ = version_tuple = (1, 0, 3)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -20,6 +20,7 @@ from __future__ import annotations
20
20
 
21
21
  import json
22
22
  import os
23
+ import re
23
24
  import shutil
24
25
  import tempfile
25
26
  import tomllib
@@ -249,7 +250,7 @@ def sibling_dependencies(project: Project) -> tuple[list[Path], list[str]]:
249
250
  name = markers.split(spec)[0]
250
251
  for sep in "<>=!~[ (@":
251
252
  name = name.split(sep)[0]
252
- sibling = _sibling(project.root.parent, name.strip())
253
+ sibling = _sibling(project.root.parent, name.strip(), skip=project.root)
253
254
  if sibling:
254
255
  siblings.append(sibling)
255
256
  else:
@@ -257,16 +258,35 @@ def sibling_dependencies(project: Project) -> tuple[list[Path], list[str]]:
257
258
  return siblings, specs
258
259
 
259
260
 
260
- def _sibling(parent: Path, name: str) -> Path | None:
261
- for candidate in dict.fromkeys(
262
- [name, name.replace("_", "-"), name.replace("-", "_")]
263
- ):
264
- folder = parent / candidate
265
- if (
266
- candidate
267
- and (folder / "install.vfpy").is_file()
268
- and (folder / "pyproject.toml").is_file()
269
- ):
261
+ def _norm(name: str) -> str:
262
+ """PEP 503 name normalisation (``Foo_Bar.baz`` -> ``foo-bar-baz``)."""
263
+ return re.sub(r"[-_.]+", "-", name).lower()
264
+
265
+
266
+ def _sibling(parent: Path, name: str, skip: Path | None = None) -> Path | None:
267
+ """Find the checkout beside *skip* that installs the dependency *name*.
268
+
269
+ Only folders with install.vfpy and a pyproject.toml holding a
270
+ ``[tool.fontlab-install]`` table with a valid ``id`` count, matched by that
271
+ table's ``name`` or ``[project].name`` (never by folder name alone), so
272
+ unrelated checkouts such as TypeRig are left to uv. First sorted folder wins.
273
+ """
274
+ wanted = _norm(name)
275
+ if not wanted or not parent.is_dir():
276
+ return None
277
+ for folder in sorted(parent.iterdir()):
278
+ if folder == skip or not (folder / "install.vfpy").is_file():
279
+ continue
280
+ try:
281
+ doc = tomllib.loads((folder / "pyproject.toml").read_text(encoding="utf-8"))
282
+ except (OSError, ValueError):
283
+ continue
284
+ tool, project = doc.get("tool"), doc.get("project")
285
+ table = tool.get("fontlab-install") if isinstance(tool, dict) else None
286
+ if not isinstance(table, dict) or not manifest.ID_PATTERN.match(str(table.get("id", ""))):
287
+ continue
288
+ names = {table.get("name"), project.get("name") if isinstance(project, dict) else None}
289
+ if wanted in {_norm(n) for n in names if isinstance(n, str)}:
270
290
  return folder
271
291
  return None
272
292
 
@@ -345,19 +365,25 @@ def _install_checkout(
345
365
  finish=lambda target: _finish(project, data_manifest, target),
346
366
  fields={"init_script": True} if project.init_script else None,
347
367
  ),
368
+ data,
348
369
  )
349
370
  if project.init_script:
350
371
  initscript.update(data)
351
372
  return record
352
373
 
353
374
 
354
- def _install_after_migration(migrated, ext_id: str, install):
375
+ def _install_after_migration(migrated, ext_id: str, install, data: Path | None = None):
355
376
  """Run *install*; after a legacy migration, say how to recover from a failure."""
356
377
  try:
357
378
  return install()
358
379
  except Exception as exc:
359
380
  if not migrated:
360
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
361
387
  raise BootstrapError(
362
388
  f"The legacy install of {ext_id} was removed, but the new install failed: {exc}. Fix the cause and run install.vfpy again."
363
389
  ) from exc
@@ -373,9 +373,36 @@ def _remove_tracked(data: Path, entries: list[dict]) -> list[dict]:
373
373
  return removed
374
374
 
375
375
 
376
+ def _created_dirs(data: Path, entries: list[dict]) -> set[Path]:
377
+ """Folders instamix created: ``dir`` entries of *entries* and of every ledger record."""
378
+ owned = list(entries)
379
+ for record in ledger.records(data):
380
+ owned += record.get("entries", [])
381
+ paths = (_entry_path(data, e) for e in owned if e.get("kind") == "dir")
382
+ return {p for p in paths if p is not None}
383
+
384
+
385
+ def _prune_empty(data: Path, path: Path | None, created: set[Path]) -> None:
386
+ """Remove now-empty folders above *path* that instamix created, never ``Scripts/``."""
387
+ scripts = Path(data) / "Scripts"
388
+ if path is None:
389
+ return
390
+ folder = path.parent
391
+ while folder != scripts and scripts in folder.parents and folder in created:
392
+ try:
393
+ folder.rmdir()
394
+ except OSError:
395
+ return
396
+ folder = folder.parent
397
+
398
+
376
399
  def remove_entries(data: Path, entries: list[dict]) -> list[str]:
377
400
  """Remove recorded paths that are still ours; return the ones left behind."""
378
- removed = {id(e) for e in _remove_tracked(data, entries)}
401
+ done = _remove_tracked(data, entries)
402
+ created = _created_dirs(data, entries) if done else set()
403
+ for entry in done:
404
+ _prune_empty(data, _entry_path(data, entry), created)
405
+ removed = {id(e) for e in done}
379
406
  kept = []
380
407
  for entry in entries:
381
408
  path = _entry_path(data, entry)
@@ -55,6 +55,9 @@ def update(data: Path, *, remove: bool = False) -> bool:
55
55
  new = updated(contents, remove)
56
56
  if new == contents:
57
57
  return False
58
+ if remove and not new.strip():
59
+ path.unlink() # nothing but our block was in it
60
+ return True
58
61
  handle, temp = tempfile.mkstemp(prefix=".initScript-", dir=str(path.parent))
59
62
  try:
60
63
  with os.fdopen(handle, "wb") as stream:
@@ -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:
@@ -99,3 +99,64 @@ def test_gui_when_no_pythonqt_then_console(capsys):
99
99
 
100
100
  gui.message("hi")
101
101
  assert "hi" in capsys.readouterr().out
102
+
103
+
104
+ def test_install_project_when_neighbour_has_no_install_table_then_left_to_uv(data, tmp_path):
105
+ other = tmp_path / "typerig"
106
+ other.mkdir()
107
+ (other / "install.vfpy").write_text("")
108
+ (other / "pyproject.toml").write_text('[project]\nname = "typerig"\nversion = "1"\n')
109
+ bad = tmp_path / "broken"
110
+ bad.mkdir()
111
+ (bad / "install.vfpy").write_text("")
112
+ (bad / "pyproject.toml").write_text("not [valid toml")
113
+ root = _project(tmp_path / "proj-a", "proj-a", "com.example.proja", ["typerig>=1", "broken"])
114
+ calls = []
115
+ records = bootstrap.install_project(
116
+ root / "install.vfpy", data, requirements=lambda d, specs: calls.append(list(specs))
117
+ )
118
+ assert [r["id"] for r in records] == ["com.example.proja"]
119
+ assert calls == [["typerig>=1", "broken"]]
120
+ assert sorted(p.name for p in other.iterdir()) == ["install.vfpy", "pyproject.toml"]
121
+
122
+
123
+ def test_sibling_when_folder_name_differs_then_matches_project_name(tmp_path):
124
+ _project(tmp_path / "checkout-x", "Proj_X.lib", "com.example.projx")
125
+ assert bootstrap._sibling(tmp_path, "proj-x-lib", skip=tmp_path / "proj-a") == tmp_path / "checkout-x"
126
+
127
+
128
+ def test_uninstall_when_scripts_subfolders_emptied_then_pruned(data, tmp_path):
129
+ root = _project(tmp_path / "proj-a", "proj-a", "com.example.proja")
130
+ (root / "Scripts" / "Features").mkdir()
131
+ (root / "Scripts" / "Features" / "x.py").write_text("")
132
+ bootstrap.install_project(root / "install.vfpy", data, requirements=lambda d, s: None)
133
+ (data / "Scripts" / "Mine").mkdir()
134
+ assert (data / "Scripts" / "Features").is_dir()
135
+ extension.uninstall("com.example.proja", data)
136
+ assert not (data / "Scripts" / "Features").exists()
137
+ assert (data / "Scripts" / "Mine").is_dir() and (data / "Scripts").is_dir()
138
+
139
+
140
+ def test_uninstall_when_user_folder_preexisted_then_kept(data, tmp_path):
141
+ root = _project(tmp_path / "proj-a", "proj-a", "com.example.proja")
142
+ (root / "Scripts" / "Mine").mkdir()
143
+ (root / "Scripts" / "Mine" / "x.py").write_text("")
144
+ mine = data / "Scripts" / "Mine"
145
+ mine.mkdir(parents=True) # user's own empty folder, before install
146
+ bootstrap.install_project(root / "install.vfpy", data, requirements=lambda d, s: None)
147
+ assert (mine / "x.py").exists()
148
+ extension.uninstall("com.example.proja", data)
149
+ assert mine.is_dir() and not (mine / "x.py").exists()
150
+
151
+
152
+ def test_sibling_when_tables_malformed_then_skipped(tmp_path):
153
+ bad = tmp_path / "bad"
154
+ bad.mkdir()
155
+ (bad / "install.vfpy").write_text("")
156
+ (bad / "pyproject.toml").write_text('tool = 1\nproject = "x"\n')
157
+ badid = tmp_path / "badid"
158
+ badid.mkdir()
159
+ (badid / "install.vfpy").write_text("")
160
+ (badid / "pyproject.toml").write_text('[project]\nname = "badid"\n[tool.fontlab-install]\nid = "nodots"\n')
161
+ assert bootstrap._sibling(tmp_path, "bad") is None
162
+ assert bootstrap._sibling(tmp_path, "badid") is None
@@ -675,3 +675,125 @@ def test_stub_download_when_no_wheel_then_clear_error(tmp_path, monkeypatch, dat
675
675
  )
676
676
  with pytest.raises(RuntimeError, match="no fontlab-instamix wheel"):
677
677
  ns["download"](tmp_path)
678
+
679
+
680
+ def test_initscript_when_only_block_removed_then_file_deleted(tmp_path):
681
+ initscript.update(tmp_path)
682
+ assert (tmp_path / "initScript.py").is_file()
683
+ assert initscript.update(tmp_path, remove=True)
684
+ assert not (tmp_path / "initScript.py").exists()
685
+
686
+
687
+ def test_initscript_when_user_content_then_file_kept(tmp_path):
688
+ (tmp_path / "initScript.py").write_text("print('mine')\n")
689
+ initscript.update(tmp_path)
690
+ initscript.update(tmp_path, remove=True)
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"