forked from Mirror/pmbootstrap
core: don't re-export get_context (MR 2252)
This makes testing a lot more annoying. Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
parent
42d9f4e3cd
commit
6087a9df8f
48 changed files with 86 additions and 55 deletions
|
@ -16,7 +16,8 @@ from .helpers import frontend
|
|||
from .helpers import logging
|
||||
from .helpers import mount
|
||||
from .helpers import other
|
||||
from .core import Chroot, get_context, Config
|
||||
from .core import Chroot, Config
|
||||
from .core.context import get_context
|
||||
from .commands import run_command
|
||||
|
||||
# pmbootstrap version
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Copyright 2023 Oliver Smith
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
import os
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
from pmb.core.pkgrepo import pkgrepo_default_path
|
||||
from pmb.helpers import logging
|
||||
import pmb.aportgen.busybox_static
|
||||
|
|
|
@ -7,7 +7,8 @@ import pmb.chroot.apk
|
|||
import pmb.chroot.apk_static
|
||||
import pmb.helpers.run
|
||||
import pmb.parse.apkindex
|
||||
from pmb.core import Chroot, get_context
|
||||
from pmb.core import Chroot
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
def generate(pkgname: str):
|
||||
|
|
|
@ -7,7 +7,7 @@ from pmb.types import PmbArgs
|
|||
import pmb.helpers.git
|
||||
import pmb.helpers.run
|
||||
import pmb.helpers.args
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
def indent_size(line):
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Copyright 2023 Oliver Smith
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
from pmb.core.arch import Arch
|
||||
from pmb.helpers import logging
|
||||
import os
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Copyright 2023 Oliver Smith
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
import pmb.aportgen.core
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
from pmb.core.pkgrepo import pkgrepo_default_path
|
||||
import pmb.helpers.git
|
||||
import pmb.helpers.run
|
||||
|
|
|
@ -9,7 +9,8 @@ from pmb.core.arch import Arch
|
|||
from pmb.types import PmbArgs
|
||||
import pmb.helpers.run
|
||||
import pmb.parse.apkindex
|
||||
from pmb.core import Chroot, get_context
|
||||
from pmb.core import Chroot
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
def generate(pkgname):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Copyright 2023 Oliver Smith
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
from typing import List
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
from pmb.parse.deviceinfo import Deviceinfo
|
||||
import pmb.helpers.run
|
||||
import pmb.aportgen.core
|
||||
|
|
|
@ -7,7 +7,8 @@ import pmb.chroot.apk
|
|||
import pmb.chroot.apk_static
|
||||
import pmb.helpers.run
|
||||
import pmb.parse.apkindex
|
||||
from pmb.core import Chroot, get_context
|
||||
from pmb.core import Chroot
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
def generate(pkgname):
|
||||
|
|
|
@ -23,7 +23,8 @@ import pmb.parse
|
|||
import pmb.parse.apkindex
|
||||
from pmb.helpers.exceptions import BuildFailedError
|
||||
|
||||
from pmb.core import Chroot, get_context
|
||||
from pmb.core import Chroot
|
||||
from pmb.core.context import get_context
|
||||
|
||||
class BootstrapStage(enum.IntEnum):
|
||||
"""
|
||||
|
|
|
@ -8,7 +8,8 @@ from typing import Any, Dict, Optional, Union
|
|||
import pmb.config
|
||||
import pmb.chroot.apk
|
||||
import pmb.helpers.pmaports
|
||||
from pmb.core import Chroot, ChrootType, get_context
|
||||
from pmb.core import Chroot, ChrootType
|
||||
from pmb.core.context import get_context
|
||||
from pmb.meta import Cache
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@ import pmb.helpers
|
|||
import pmb.helpers.mount
|
||||
import pmb.helpers.pmaports
|
||||
import pmb.parse
|
||||
from pmb.core import Chroot, get_context
|
||||
from pmb.core import Chroot
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
def match_kbuild_out(word):
|
||||
|
|
|
@ -11,7 +11,8 @@ import pmb.config
|
|||
import pmb.chroot
|
||||
import pmb.chroot.apk
|
||||
import pmb.helpers.run
|
||||
from pmb.core import Chroot, get_context
|
||||
from pmb.core import Chroot
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
def init_abuild_minimal(chroot: Chroot=Chroot.native()):
|
||||
|
|
|
@ -10,7 +10,8 @@ import pmb.helpers.cli
|
|||
import pmb.parse
|
||||
import pmb.build
|
||||
|
||||
from pmb.core import Chroot, get_context
|
||||
from pmb.core import Chroot
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
def newapkbuild(folder, args_passed, force=False):
|
||||
|
|
|
@ -16,7 +16,8 @@ import pmb.helpers.pmaports
|
|||
import pmb.helpers.run
|
||||
import pmb.parse.apkindex
|
||||
import pmb.parse.version
|
||||
from pmb.core import Chroot, get_context
|
||||
from pmb.core import Chroot
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
def copy_to_buildpath(package, chroot: Chroot=Chroot.native()):
|
||||
|
|
|
@ -20,7 +20,8 @@ from pmb.meta import Cache
|
|||
import pmb.parse.apkindex
|
||||
import pmb.parse.depends
|
||||
import pmb.parse.version
|
||||
from pmb.core import Chroot, get_context
|
||||
from pmb.core import Chroot
|
||||
from pmb.core.context import get_context
|
||||
from pmb.types import PathString
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ import pmb.config.file
|
|||
import pmb.parse.apkindex
|
||||
import pmb.helpers.http
|
||||
import pmb.parse.version
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
def read_signature_info(tar):
|
||||
|
|
|
@ -16,7 +16,8 @@ import pmb.config.workdir
|
|||
import pmb.helpers.repo
|
||||
import pmb.helpers.run
|
||||
import pmb.helpers.other
|
||||
from pmb.core import Chroot, ChrootType, get_context
|
||||
from pmb.core import Chroot, ChrootType
|
||||
from pmb.core.context import get_context
|
||||
|
||||
cache_chroot_is_outdated: List[str] = []
|
||||
|
||||
|
|
|
@ -8,7 +8,8 @@ import pmb.chroot.apk
|
|||
import pmb.config.pmaports
|
||||
from pmb.types import PmbArgs
|
||||
import pmb.helpers.cli
|
||||
from pmb.core import Chroot, get_context
|
||||
from pmb.core import Chroot
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
def build(flavor, chroot: Chroot):
|
||||
|
|
|
@ -7,7 +7,8 @@ from pmb.helpers import logging
|
|||
|
||||
import pmb.config
|
||||
import pmb.chroot.apk
|
||||
from pmb.core import Chroot, get_context
|
||||
from pmb.core import Chroot
|
||||
from pmb.core.context import get_context
|
||||
from pmb.types import PmbArgs
|
||||
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@ import pmb.config
|
|||
import pmb.helpers.run
|
||||
import pmb.parse
|
||||
import pmb.helpers.mount
|
||||
from pmb.core import Chroot, get_context
|
||||
from pmb.core import Chroot
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
def create_device_nodes(chroot: Chroot):
|
||||
|
|
|
@ -8,7 +8,8 @@ from contextlib import closing
|
|||
import pmb.chroot
|
||||
import pmb.helpers.mount
|
||||
import pmb.install.losetup
|
||||
from pmb.core import Chroot, ChrootType, get_context
|
||||
from pmb.core import Chroot, ChrootType
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
def kill_adb():
|
||||
|
|
|
@ -14,7 +14,8 @@ import pmb.helpers.pmaports
|
|||
import pmb.helpers.run
|
||||
from pmb.meta import Cache
|
||||
import pmb.parse.apkindex
|
||||
from pmb.core import Chroot, get_context
|
||||
from pmb.core import Chroot
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
def zap(confirm=True, dry=False, pkgs_local=False, http=False,
|
||||
|
|
|
@ -7,7 +7,7 @@ from pathlib import Path, PosixPath, PurePosixPath
|
|||
from pmb import commands
|
||||
from pmb.types import PathString
|
||||
from pmb.helpers import run
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
|
||||
class Log(commands.Command):
|
||||
clear_log: bool
|
||||
|
|
|
@ -13,7 +13,7 @@ import pmb.build
|
|||
import pmb.chroot
|
||||
import pmb.chroot.apk
|
||||
from pmb.build import BuildQueueItem
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
|
||||
from pmb import commands
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Copyright 2023 Oliver Smith
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
from pmb.core.chroot import Chroot
|
||||
from pmb.core.config import SystemdConfig
|
||||
from pmb.core.context import Context
|
||||
|
@ -457,7 +457,7 @@ def ask_for_device(context: Context):
|
|||
|
||||
|
||||
def ask_for_additional_options(config):
|
||||
context = pmb.core.get_context()
|
||||
context = pmb.core.context.get_context()
|
||||
# Allow to skip additional options
|
||||
logging.info("Additional options:"
|
||||
f" extra free space: {config.extra_space} MB,"
|
||||
|
|
|
@ -11,7 +11,8 @@ from typing import Optional
|
|||
|
||||
import pmb.config
|
||||
import pmb.config.pmaports
|
||||
from pmb.core import Chroot, get_context
|
||||
from pmb.core import Chroot
|
||||
from pmb.core.context import get_context
|
||||
from pmb.core.pkgrepo import pkgrepo_default_path
|
||||
|
||||
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from .chroot import Chroot, ChrootType
|
||||
from .context import Context, get_context, set_context
|
||||
from .context import Context
|
||||
from .config import Config
|
||||
|
|
|
@ -23,6 +23,12 @@ class Chroot:
|
|||
__name: str
|
||||
|
||||
def __init__(self, suffix_type: ChrootType, name: Optional[Union[str, Arch]] = ""):
|
||||
# We use the native chroot as the buildroot when building for the host arch
|
||||
if suffix_type == ChrootType.BUILDROOT and isinstance(name, Arch):
|
||||
if name.is_native():
|
||||
suffix_type = ChrootType.NATIVE
|
||||
name = ""
|
||||
|
||||
self.__type = suffix_type
|
||||
self.__name = str(name or "")
|
||||
|
||||
|
@ -41,6 +47,9 @@ class Chroot:
|
|||
"riscv64",
|
||||
]
|
||||
|
||||
if self.__type not in ChrootType:
|
||||
raise ValueError(f"Invalid chroot type: '{self.__type}'")
|
||||
|
||||
# A buildroot suffix must have a name matching one of alpines
|
||||
# architectures.
|
||||
if self.__type == ChrootType.BUILDROOT and self.__name not in valid_arches:
|
||||
|
@ -83,7 +92,7 @@ class Chroot:
|
|||
if self.type == ChrootType.NATIVE:
|
||||
return Arch.native()
|
||||
if self.type == ChrootType.BUILDROOT:
|
||||
return Arch.from_str(self.name())
|
||||
return Arch.from_str(self.name)
|
||||
# FIXME: this is quite delicate as it will only be valid
|
||||
# for certain pmbootstrap commands... It was like this
|
||||
# before but it should be fixed.
|
||||
|
@ -96,7 +105,7 @@ class Chroot:
|
|||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if isinstance(other, str):
|
||||
return str(self) == other or self.path == Path(other) or self.name() == other
|
||||
return str(self) == other or self.path == Path(other) or self.name == other
|
||||
|
||||
if isinstance(other, PosixPath):
|
||||
return self.path == other
|
||||
|
@ -104,7 +113,7 @@ class Chroot:
|
|||
if not isinstance(other, Chroot):
|
||||
return NotImplemented
|
||||
|
||||
return self.type == other.type and self.name() == other.name()
|
||||
return self.type == other.type and self.name == other.name
|
||||
|
||||
|
||||
def __truediv__(self, other: object) -> Path:
|
||||
|
@ -138,6 +147,7 @@ class Chroot:
|
|||
return self.__type
|
||||
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self.__name
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import pmb.helpers.cli
|
|||
import pmb.helpers.run
|
||||
import pmb.helpers.run_core
|
||||
import pmb.parse.version
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
|
||||
def _prepare_fifo():
|
||||
"""Prepare the progress fifo for reading / writing.
|
||||
|
|
|
@ -97,7 +97,7 @@ def init(args: PmbArgs) -> PmbArgs:
|
|||
context.force = getattr(args, "force", False)
|
||||
|
||||
# Initialize context
|
||||
pmb.core.set_context(context)
|
||||
pmb.core.context.set_context(context)
|
||||
|
||||
# Initialize logs (we could raise errors below)
|
||||
pmb.helpers.logging.init(args)
|
||||
|
|
|
@ -9,7 +9,7 @@ import sys
|
|||
|
||||
import pmb.config
|
||||
from pmb.types import PmbArgs
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
class ReadlineTabCompleter:
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import os
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
from pmb.core.pkgrepo import pkgrepo_glob_one, pkgrepo_iglob
|
||||
|
||||
|
||||
|
|
|
@ -38,7 +38,8 @@ import pmb.netboot
|
|||
import pmb.parse
|
||||
import pmb.qemu
|
||||
import pmb.sideload
|
||||
from pmb.core import ChrootType, Chroot, get_context
|
||||
from pmb.core import ChrootType, Chroot
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
def _parse_flavor(device: str, autoinstall=True):
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import configparser
|
||||
from pathlib import Path
|
||||
from typing import Dict
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
from pmb.core.context import Context
|
||||
from pmb.core.pkgrepo import pkgrepo_path
|
||||
from pmb.helpers import logging
|
||||
|
|
|
@ -8,7 +8,7 @@ from pathlib import Path
|
|||
import shutil
|
||||
import urllib.request
|
||||
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
from pmb.types import PmbArgs
|
||||
import pmb.helpers.run
|
||||
|
||||
|
|
|
@ -5,8 +5,7 @@ import os
|
|||
import sys
|
||||
from typing import TextIO
|
||||
import pmb.config
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import Context
|
||||
from pmb.core.context import Context, get_context
|
||||
from pmb.types import PmbArgs
|
||||
|
||||
logfd: TextIO
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Copyright 2023 Oliver Smith
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
from pmb.core.arch import Arch
|
||||
from pmb.helpers import logging
|
||||
import os
|
||||
|
|
|
@ -7,7 +7,7 @@ See also:
|
|||
- pmb/helpers/package.py (work with both)
|
||||
"""
|
||||
import glob
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
from pmb.core.arch import Arch
|
||||
from pmb.core.pkgrepo import pkgrepo_iter_package_dirs
|
||||
from pmb.helpers import logging
|
||||
|
|
|
@ -9,7 +9,7 @@ See also:
|
|||
"""
|
||||
import os
|
||||
import hashlib
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
from pmb.core.arch import Arch
|
||||
from pmb.core.pkgrepo import pkgrepo_names
|
||||
from pmb.helpers import logging
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Copyright 2023 Oliver Smith
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
import fcntl
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
from pmb.core.arch import Arch
|
||||
from pmb.types import PathString, Env
|
||||
from pmb.helpers import logging
|
||||
|
@ -180,7 +180,7 @@ def foreground_pipe(cmd, working_dir=None, output_to_stdout=False,
|
|||
* output: ""
|
||||
* output: full program output string (output_return is True)
|
||||
"""
|
||||
context = pmb.core.get_context()
|
||||
context = pmb.core.context.get_context()
|
||||
# Start process in background (stdout and stderr combined)
|
||||
process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT, cwd=working_dir,
|
||||
|
@ -360,7 +360,7 @@ def core(log_message, cmd, working_dir=None, output="log",
|
|||
* the program's entire output (output_return is True)
|
||||
"""
|
||||
sanity_checks(output, output_return, check)
|
||||
context = pmb.core.get_context()
|
||||
context = pmb.core.context.get_context()
|
||||
|
||||
if context.sudo_timer and sudo:
|
||||
sudo_timer_start()
|
||||
|
|
|
@ -6,7 +6,7 @@ import pmb.config.workdir
|
|||
import pmb.helpers.git
|
||||
from pmb.core import Config
|
||||
from pmb.types import PmbArgs
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
from typing import List, Tuple
|
||||
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
import os
|
||||
import glob
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
from pmb.core.pkgrepo import pkgrepo_iglob
|
||||
import pmb.helpers.pmaports
|
||||
import pmb.helpers.package
|
||||
|
|
|
@ -29,7 +29,8 @@ import pmb.install.blockdevice
|
|||
import pmb.install.recovery
|
||||
import pmb.install.ui
|
||||
import pmb.install
|
||||
from pmb.core import Chroot, ChrootType, get_context
|
||||
from pmb.core import Chroot, ChrootType
|
||||
from pmb.core.context import get_context
|
||||
|
||||
# Keep track of the packages we already visited in get_recommends() to avoid
|
||||
# infinite recursion
|
||||
|
@ -812,7 +813,7 @@ def install_system_image(args: PmbArgs, size_reserve, chroot: Chroot, step, step
|
|||
:param disk: path to disk block device (e.g. /dev/mmcblk0) or None
|
||||
"""
|
||||
config = get_context().config
|
||||
device = chroot.name()
|
||||
device = chroot.name
|
||||
# Partition and fill image file/disk block device
|
||||
logging.info(f"*** ({step}/{steps}) PREPARE INSTALL BLOCKDEVICE ***")
|
||||
pmb.helpers.mount.umount_all(chroot.path)
|
||||
|
|
|
@ -10,7 +10,8 @@ import pmb.helpers.mount
|
|||
import pmb.install.losetup
|
||||
import pmb.helpers.cli
|
||||
import pmb.config
|
||||
from pmb.core import Chroot, get_context
|
||||
from pmb.core import Chroot
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
def previous_install(path: Path):
|
||||
|
|
|
@ -6,7 +6,8 @@ import pmb.chroot
|
|||
import pmb.chroot.apk
|
||||
import pmb.helpers.pmaports
|
||||
import pmb.parse.apkindex
|
||||
from pmb.core import Chroot, get_context
|
||||
from pmb.core import Chroot
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
def package_from_aports(pkgname_depend):
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import copy
|
||||
from pathlib import Path
|
||||
from typing import Dict, Optional
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
from pmb.core.arch import Arch
|
||||
from pmb.helpers import logging
|
||||
import os
|
||||
|
|
|
@ -12,7 +12,7 @@ import pmb.helpers.run_core
|
|||
import pmb.parse.apkindex
|
||||
import pmb.config.pmaports
|
||||
import pmb.build
|
||||
from pmb.core import get_context
|
||||
from pmb.core.context import get_context
|
||||
|
||||
|
||||
def scp_abuild_key(args: PmbArgs, user: str, host: str, port: str):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue