Filesystem

import knots_hub.filesystem

manipulate the filesystem

class knots_hub.filesystem.HubLocalFilesystem(root_dir: Path | None = None)

Collection of paths for storing runtime data

__init__(root_dir: Path | None = None)
property hubinstall_record_path: Path

Filesystem path to a file that may not exist yet. Used to store install metadata.

initialize()
property is_hub_installed: bool
property log_path: Path

Filesystem path to a file that may not exist yet. Used for storing python logs.

property root_dir: Path

Fileystem path to a directory that may not exist but whose parent must exist.

This directory is used to store runtime data generated by the hub.

knots_hub.filesystem.find_hub_executable(directory: Path) Path | None

Get the path of the hub executable stored in the given directory.

Parameters:

directory – filesystem path to an existing directory

Returns:

filesystem path to an existing file or None if not found

knots_hub.filesystem.get_expected_hub_executable(directory: Path) Path

Get the path of the expected hub executable for this library version.

Note a previous version might be installed locally so this is why this path might exist or not.

Parameters:

directory – filesystem path to a directory that may exist

Returns:

filesystem path to a file that might exist or not.

knots_hub.filesystem.is_runtime_from_local_install(local_install_path) bool

Find if the current runtime code is executed from a local hub installation.

Parameters:

local_install_path – path of the theoric local hub installation

knots_hub.filesystem.rmtree(path: Path, ignore_errors=False)

Remove the directory and its content while handling any potential PermissionError.

This function is copied from tempfile.TemporaryDirectory._rmtree

Parameters:
  • path – filesystem path to an existing directory

  • ignore_errors – do not raise if there is error during cleanup