Skip to content

Utils

utils

download_and_extract(url: str, save_path: Path, timeout: float = RELEASE_DOWNLOAD_TIMEOUT, overwrite: bool = False, progress_callback: Callable[[str, int, int | None], None] | None = None, cancel: Callable[[], bool] | None = None, sha512: str | None = None) -> None

Downloads a zip file from the given URL and extracts its contents.

Nothing at save_path changes until extraction has fully succeeded.

Parameters:

Name Type Description Default
url str

The URL to download the zip file from.

required
save_path Path

The directory path to save the extracted contents to.

required
timeout float

HTTP request timeout in seconds.

RELEASE_DOWNLOAD_TIMEOUT
overwrite bool

Whether to replace a non-empty save_path.

False
progress_callback Callable[[str, int, int | None], None] | None

Called as (phase, done, total). In the "download" phase these are bytes, and total is None if the server didn't send a size. In the "extract" phase they're files. Exceptions it raises propagate unchanged.

None
cancel Callable[[], bool] | None

Checked before each downloaded chunk; return True to stop. Extraction can't be cancelled.

None
sha512 str | None

Expected hex SHA-512 of the zip (GodotAsset.sha512). On a mismatch, the SHA512-SUMS.txt next to url decides. None skips it.

None

Raises:

Type Description
FileExistsError

If save_path isn't empty and overwrite is False.

DownloadCancelled

If cancel returned True.

ChecksumError

If the zip doesn't match sha512 or SHA512-SUMS.txt.

DownloadError

On network or write failure.

ExtractError

On an invalid or empty zip, or a failed extraction.

find_binary(dir_path: Path) -> Path | None

Finds the Godot binary in a given folder.

Parameters:

Name Type Description Default
dir_path Path

The path to the folder containing the binary.

required

Returns:

Type Description
Path | None

The path to the Godot binary if found, otherwise None.

Raises:

Type Description
FileNotFoundError

If the provided path is not a valid directory.

NotImplementedError

If the current platform is not supported.

start(binary_path: Path, args: Sequence[str] = (), *, project: Path | None = None, output: Path | None = None) -> subprocess.Popen

Launches Godot detached: the project manager, or project in the editor.

Parameters:

Name Type Description Default
binary_path Path

The full path to the Godot binary file.

required
args Sequence[str]

Extra command-line arguments for Godot.

()
project Optional[Path]

A project.godot file to open in the editor.

None
output Optional[Path]

File that receives Godot's stdout and stderr.

None

Returns:

Type Description
Popen

The started Godot process.

Raises:

Type Description
FileNotFoundError

If binary_path or project is not a file.

OSError

If the binary can't be started.