classInstance#

class Instance(
path: Path | str,
)#

A game directory whose contents come from a modpack.

Parameters:

path (Path | str) – The directory. It is created by the first sync.

path#

The directory.

classmethod open(
path: Path | str,
) → Instance#

Return the instance at path, which does not have to exist yet.

property state: InstanceState | None#

What the last sync installed, or None if nothing has been synced here.

Raises:

InstanceError – The state file is corrupt.

diff(
pack: Modpack,
*,
side: Literal['client', 'server'] = 'client',
include_optional: bool = False,
) → Changes#

Compare this directory with a pack. Changes nothing.

Parameters:
  • pack (Modpack) – The modpack.

  • side (Literal['client', 'server']) – The side to install.

  • include_optional (bool) – Include the pack’s optional files.

Returns:

What a sync would do.

Raises:

InstanceError – The state file is corrupt.

Return type:

Changes

sync(
pack: Modpack,
*,
side: Literal['client', 'server'] = 'client',
include_optional: bool = False,
overwrite: bool = False,
adopt_from: Iterable[Path | str] = (),
session: Session | None = None,
max_workers: int = 8,
progress: Callable[[Progress], None] | None = None,
cancel: CancelToken | None = None,
) → Changes#

Make this directory match a pack and return what changed.

Install and update are the same call. New files are downloaded to a staging directory first, so the instance is only touched once everything is ready. An interrupted sync can simply be run again, and it reuses what was already downloaded. A file whose size and modification time have not changed since the last sync is assumed to have the same contents.

Parameters:
  • pack (Modpack) – The modpack.

  • side (Literal['client', 'server']) – The side to install.

  • include_optional (bool) – Include the pack’s optional files.

  • overwrite (bool) – Replace the player’s changes instead of keeping them.

  • adopt_from (Iterable[Path | str]) – Folders to search for entries that cannot be downloaded. Files are found by name and verified.

  • session (Session | None) – The session to use. A temporary one is created if omitted.

  • max_workers (int) – How many files to download at once.

  • progress (Callable[[Progress], None] | None) – Receives updates for each stage.

  • cancel (CancelToken | None) – Stops the sync. It has no effect once files are being moved into the instance.

Returns:

What changed.

Raises:
  • UnresolvedEntriesError – Entries are still missing. Nothing has been changed.

  • InstanceError – The state file is corrupt, or a file could not be replaced, usually because the game is running. Everything is put back as it was.

  • PackError – The pack’s files are unsafe.

  • DownloadError – A file could not be downloaded.

  • Cancelled – cancel was triggered.

Return type:

Changes

delete() → None#

Delete this instance’s directory. Refuses unmanaged directories.

Raises:

InstanceError – The directory has no state from a previous sync.