WIP: start ripping out args (MR 2252)

Cease merging pmbootstrap.cfg into args, implement a Context type to let
us pull globals out of thin air (as an intermediate workaround) and rip
args out of a lot of the codebase.

This is just a first pass, after this we can split all the state that
leaked over into Context into types with narrower scopes (like a
BuildContext(), etc).

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-05-25 03:59:04 +02:00 committed by Oliver Smith
parent bfea00e03a
commit 34dd9d42ba
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
129 changed files with 1393 additions and 1300 deletions

View file

@ -2,45 +2,42 @@
# SPDX-License-Identifier: GPL-3.0-or-later
from pathlib import Path
import pmb.config
from pmb.core.types import PmbArgs
from pmb.types import PmbArgs
def merge_with_args(args: PmbArgs):
"""We have the internal config (pmb/config/__init__.py) and the user config
(usually ~/.config/pmbootstrap.cfg, can be changed with the '-c'
parameter).
# def merge_with_args(args: PmbArgs):
# """We have the internal config (pmb/config/__init__.py) and the user config
# (usually ~/.config/pmbootstrap.cfg, can be changed with the '-c'
# parameter).
Args holds the variables parsed from the commandline (e.g. -j fills out
args.jobs), and values specified on the commandline count the most.
# Args holds the variables parsed from the commandline (e.g. -j fills out
# args.jobs), and values specified on the commandline count the most.
In case it is not specified on the commandline, for the keys in
pmb.config.config_keys, we look into the value set in the the user config.
# In case it is not specified on the commandline, for the keys in
# pmb.config.config_keys, we look into the value set in the the user config.
When that is empty as well (e.g. just before pmbootstrap init), or the key
is not in pmb.config_keys, we use the default value from the internal
config.
"""
# Use defaults from the user's config file
cfg = pmb.config.load(args)
for key in cfg["pmbootstrap"]:
if key not in args or getattr(args, key) is None:
value = cfg["pmbootstrap"][key]
if key in pmb.config.defaults:
default = pmb.config.defaults[key]
if isinstance(default, bool):
value = (value.lower() == "true")
setattr(args, key, value)
setattr(args, 'selected_providers', cfg['providers'])
# When that is empty as well (e.g. just before pmbootstrap init), or the key
# is not in pmb.config_keys, we use the default value from the internal
# config.
# """
# # Use defaults from the user's config file
# cfg = pmb.config.load(args)
# for key in cfg["pmbootstrap"]:
# if key not in args or getattr(args, key) is None:
# value = cfg["pmbootstrap"][key]
# if key in pmb.config.defaults:
# default = pmb.config.defaults[key]
# if isinstance(default, bool):
# value = (value.lower() == "true")
# setattr(args, key, value)
# setattr(args, 'selected_providers', cfg['providers'])
# Use defaults from pmb.config.defaults
for key, value in pmb.config.defaults.items():
if key not in args or getattr(args, key) is None:
setattr(args, key, value)
# # Use defaults from pmb.config.defaults
# for key, value in pmb.config.defaults.items():
# if key not in args or getattr(args, key) is None:
# setattr(args, key, value)
pmb.config.work_dir(Path(cfg["pmbootstrap"]["work"]))
# pmb.config.work_dir(Path(cfg["pmbootstrap"]["work"]))
# Make sure args.aports is a Path object
setattr(args, "aports", Path(args.aports))
# args.work is deprecated!
delattr(args, "work")
# # Make sure args.aports is a Path object
# setattr(args, "aports", Path(args.aports))