Files
deskflow/scripts/lib/config.py
Nick Bolton 4d3f0c820e Correct Qt macOS target and drop Core5Compat lib (#7389)
* Remove Core5Compat

* Remove hack

* Update ChangeLog

* Revert "Remove hack"

This reverts commit dda3ad05818d346fdfcbb41944b9e731a4b547c0.

* Set `add_compile_definitions` for Qt

* Revert "Set `add_compile_definitions` for Qt"

This reverts commit 0258d2d226a76081068f4e565855f37993953be5.

* Use arm64_monterey bottle

* Revert "Use arm64_monterey bottle"

This reverts commit a46d743dc6883c925e2328b9628231189cb34367.

* Use aqt to install Qt on Mac

* Append env var instead of overwrite

* Fixed filename

* Use GITHUB_PATH

* Restore original GITHUB_ENV logic

* Use newer cache action

* Update ChangeLog
2024-07-15 12:57:39 +01:00

82 lines
2.4 KiB
Python

import yaml
import lib.env as env
import lib.cmd_utils as cmd_utils
config_file = "config.yaml"
root_key = "config"
deps_key = "dependencies"
class ConfigKeyError(RuntimeError):
def __init__(self, config_file, key):
self.config_file = config_file
self.key = key
def __str__(self):
return f"Not found in {self.config_file}: {self.key}"
def _get(dict, key, key_parent=None, required=True):
value = dict.get(key)
if required and not value:
key_path = f"{root_key}:{key_parent}:{key}" if key_parent else key
raise ConfigKeyError(config_file, key_path)
return value
class Config:
"""Reads the project configuration YAML file."""
def __init__(self):
with open(config_file, "r") as f:
data = yaml.safe_load(f)
self.os_name = env.get_os()
print("Config for OS:", self.os_name)
root = _get(data, root_key)
self.os = _get(root, self.os_name)
def get_os_value(self, key):
return _get(self.os, key, self.os_name)
def get_qt_config(self):
qt_key = "qt"
qt = self.get_os_deps_value(qt_key)
parent_key = f"{self.os_name}:{deps_key}"
mirror_url = _get(qt, "mirror", parent_key)
version = _get(qt, "version", parent_key)
base_dir = _get(qt, "base-dir", parent_key)
modules = _get(qt, "modules", parent_key, required=False)
return mirror_url, version, base_dir, modules
def get_os_deps_value(self, key):
deps = self.get_os_value(deps_key)
return _get(deps, key, f"{self.os_name}:{deps_key}")
def get_deps_command(self):
deps = self.get_os_value(deps_key)
command = _get(deps, "command", f"{self.os_name}:{deps_key}")
return cmd_utils.strip_continuation_sequences(command)
def get_linux_deps_command(self, distro):
distro_data = self.get_os_value(distro)
deps = _get(distro_data, deps_key, f"{self.os_name}:{distro}")
command = _get(deps, "command", f"{self.os_name}:{distro}:{deps_key}")
return cmd_utils.strip_continuation_sequences(command)
def get_windows_ci_config(self):
choco_ci_key = "ci"
choco_ci = self.get_os_deps_value(choco_ci_key)
choco_ci_path = f"{self.os_name}:{deps_key}:{choco_ci_key}"
edit_config = _get(choco_ci, "edit-config", choco_ci_path)
skip_packages = _get(choco_ci, "skip-packages", choco_ci_path)
return edit_config, skip_packages