qgis_deployment_toolbelt.jobs.job_qgis_installation_finder module

Tools to find installed QGIS version

Author: Jean-Marie KERLOCH (https://github.com/jmkerloch)

class qgis_deployment_toolbelt.jobs.job_qgis_installation_finder.JobQgisInstallationFinder(options: dict | None)

Bases: GenericJob

Class to find installed QGIS binaries and version(s).

CACHE_DETECTED_QGIS_VERSION: str | None = None
ENSURE_QGIS_PROFILES_FOLDER: bool = False
ID: str = 'qgis-installation-finder'
OPTIONS

alias of QgisInstallationFinderOptions

__init__(options: dict | None) → None

Instantiate the class.

Parameters:

options (dict | None) – options set in the with key of the scenario step, see QgisInstallationFinderOptions

_abc_impl = <_abc._abc_data object>
_export_qgis_version(version_str: str) → None

Export the detected QGIS version as an environment variable.

Parameters:

version_str (str) – QGIS version, typically a SemVer string like 3.40.1.

static _get_latest_matching_version_path(found_versions: dict[str, str], version: str) → str | None

Get latest version path matching a wanted version.

Parameters:
  • found_versions (dict[str, str]) – dict of found versions

  • version (str) – wanted version

Returns:

latest matching version path, None if not found

Return type:

str | None

static _get_latest_version_from_list(versions: list[str]) → str | None

Get latest version from a list.

Parameters:

versions (list[str]) – list of found version

Returns:

latest version, None if no version provided

Return type:

str | None

_get_linux_installed_qgis_path() → dict[str, str]

Get install qgis path for linux operating system with which

Returns:

dict of QGIS version and QGIS bin path

Return type:

dict[str, str]

static _get_qgis_bin_version(qgis_bin: str) → str | None

Get QGIS bin version with –version.

See:

Parameters:

qgis_bin (str) – QGIS bin executable path

Returns:

SemVer version, None if version not found

Return type:

str | None

static _get_qgis_found_version_dict_from_search_paths(search_paths: list[str], search_patterns: list[str]) → dict[str, str]

Define qgis found version dict from a list of search path.

If identical version are found in multiple path, the first version found in search_path is used.

Parameters:
  • search_paths (list[str]) – list of search paths

  • search_patterns (list[str]) – list of search pattern for qgis binary

Returns:

dict of qgis binary path for qgis version

Return type:

dict[str, str]

static _get_qgis_versions_in_dir(search_dir: str, search_patterns: list[str], found_version: dict[str, str]) → None

Get QGIS binary path from an install directory.

Parameters:
  • install_dir (str) – install directory

  • search_patterns (list[str]) – list of search pattern for qgis binary

  • found_version (dict[str, str]) – updated dict of qgis binary path and version

_get_search_paths_with_environment_variable() → list[str]

Get search_paths option with environment variable update.

Returns:

search_paths

Return type:

list[str]

static _get_windows_hide_console_startupinfo() → dict

Build extra kwargs to hide a console window newly created on Windows.

Returns:

empty on non-Windows platforms, otherwise a single

startupinfo entry ready to unpack into subprocess.run.

Return type:

dict

_get_windows_installed_qgis_path() → dict[str, str]

Get dict of installed QGIS version in common install directory.

Returns:

dict of QGIS version and QGIS bin path

Return type:

dict[str, str]

static _search_qgis_version_and_add_to_dict(qgis_bin: str, found_version: dict[str, str]) → None

Search qgis version from qgis binary and add to found_version dict if found

Parameters:
  • qgis_bin (str) – qgis binary path

  • found_version (dict[str, str]) – updated dict of qgis binary path and version

static _version_sort_key(version_str: str) → Version

Transforn a version string into a sortable and comparable Version object.

Parameters:

version_str (str) – version string to parse, typically X.Y.Z.

Returns:

parsed version, or Version(“0”) if parsing failed.

Return type:

Version

get_installed_qgis_path() → str | None

Get the path to the installed QGIS executable best matching job options.

Returns:

installed qgis path

Return type:

str | None

get_installed_qgis_version_and_path() → tuple[str, str] | None

Get the installed QGIS version and executable path best matching job options.

Returns:

(version, path) tuple, or None if no QGIS

installation is found.

Return type:

tuple[str, str] | None

run() → None

Define QDT_QGIS_EXE_PATH and QDT_QGIS_VERSION for version-dependent jobs, like Shortcuts manager.

run_needed() → bool

Check if running the job is needed.

Returns:

return True if job must be run, False otherwise

Return type:

bool

class qgis_deployment_toolbelt.jobs.job_qgis_installation_finder.QgisInstallationFinderOptions(*, if_not_found: Literal['warning', 'error'] = 'warning', version_priority: list[str] = [], search_paths: list[str] = [])

Bases: JobOptions

Options of the qgis-installation-finder job.

_abc_impl = <_abc._abc_data object>
if_not_found: Literal['warning', 'error']

behavior when no QGIS installation is found

model_config = {'extra': 'forbid', 'frozen': True, 'strict': True, 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

search_paths: list[str]

folders (or names of environment variables holding one) where to look for QGIS. Empty: default install locations (see the job documentation).

version_priority: list[str]

QGIS versions (prefixes like 3.40) to look for first, in order