This class manages and prepares a payload with a temporary directory.
| 385 | |
| 386 | @dataclass |
| 387 | class Payload: |
| 388 | """ |
| 389 | This class manages and prepares a payload with a temporary directory. |
| 390 | """ |
| 391 | |
| 392 | info: dict |
| 393 | archive_name: str = "payload.tar.gz" |
| 394 | conda_exe_name: str = "_conda.exe" |
| 395 | |
| 396 | # Enable additional log output during pre/post uninstall/install. |
| 397 | add_debug_logging: bool = False |
| 398 | |
| 399 | @functools.cached_property |
| 400 | def root(self) -> Path: |
| 401 | """Create root upon first access and cache it.""" |
| 402 | return Path(tempfile.mkdtemp(prefix="payload-")) |
| 403 | |
| 404 | def remove(self, *, ignore_errors: bool = True) -> None: |
| 405 | """Remove the root of the payload. |
| 406 | |
| 407 | This function requires some extra care due to the root directory being a cached property. |
| 408 | """ |
| 409 | root = getattr(self, "root", None) |
| 410 | if root is None: |
| 411 | return |
| 412 | shutil.rmtree(root, ignore_errors=ignore_errors) |
| 413 | # Now we drop the cached value so next access will recreate if desired |
| 414 | try: |
| 415 | delattr(self, "root") |
| 416 | except Exception: |
| 417 | # delattr on a cached_property may raise on some versions / edge cases |
| 418 | pass |
| 419 | |
| 420 | def prepare(self) -> None: |
| 421 | """Prepares the payload. |
| 422 | |
| 423 | Directory structure created during preparation: |
| 424 | |
| 425 | <root>/ (temporary directory, see :attr:`root`) |
| 426 | ├── welcome.bmp, header.bmp, icon.ico (branding images for WiX UI, not installed) |
| 427 | └── <EXTERNAL_PACKAGE_PATH>/ (external_dir: contains the payload archive and conda exe) |
| 428 | └── base/ (base_dir: represents the base conda environment) |
| 429 | └── pkgs/ (pkgs_dir: staging area for conda package distributions) |
| 430 | |
| 431 | Note: base_dir and pkgs_dir are removed after archiving. |
| 432 | """ |
| 433 | external_dir = self.root / EXTERNAL_PACKAGE_PATH |
| 434 | external_dir.mkdir(parents=True, exist_ok=True) |
| 435 | |
| 436 | write_images(self.info, self.root, installer_type="msi") |
| 437 | |
| 438 | # Note that the directory name "base" is also explicitly defined in `run_installation.bat` |
| 439 | base_dir = external_dir / "base" |
| 440 | base_dir.mkdir() |
| 441 | |
| 442 | pkgs_dir = base_dir / "pkgs" |
| 443 | pkgs_dir.mkdir() |
| 444 |
no outgoing calls