Skip to content

Commit

Permalink
Merge pull request #205 from desultory/dev
Browse files Browse the repository at this point in the history
clean imports, black format
  • Loading branch information
desultory authored Feb 7, 2025
2 parents 2466d2f + fcbbb98 commit 48472cb
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 29 deletions.
6 changes: 3 additions & 3 deletions src/ugrd/base/cmdline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
__author__ = "desultory"
__version__ = "3.1.0"
__version__ = "3.1.1"

from importlib.metadata import PackageNotFoundError, version


def parse_cmdline_bool(self) -> str:
Expand Down Expand Up @@ -46,8 +48,6 @@ def export_exports(self) -> list[str]:
Sets 'exported' to 1 once done.
If 'exported' is set, returns early.
"""
from importlib.metadata import PackageNotFoundError, version

try:
self["exports"]["VERSION"] = version(__package__.split(".")[0])
except PackageNotFoundError:
Expand Down
5 changes: 3 additions & 2 deletions src/ugrd/base/keymap.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
__author__ = "desultory"
__version__ = "1.0.0"
__version__ = "1.0.1"

from pathlib import Path

from zenlib.util import contains

Expand All @@ -12,7 +14,6 @@ def _find_keymap_include(self, base_path, included_file, no_recurse=False) -> st
Stopping at the 'keymaps' directory, if not found, recursively searches the parent directory.
Keeps recursively searching if the included file does not end with '.inc'.
"""
from pathlib import Path

if not isinstance(base_path, Path):
base_path = Path(base_path)
Expand Down
9 changes: 3 additions & 6 deletions src/ugrd/crypto/cryptsetup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
__author__ = "desultory"
__version__ = "4.0.4"

from json import loads
from pathlib import Path
from re import search
from textwrap import dedent

from ugrd import AutodetectError, ValidationError
from zenlib.util import colorize, contains, unset
Expand Down Expand Up @@ -161,8 +164,6 @@ def _get_dm_slave_info(self, device_info: dict) -> (str, dict):

def _read_cryptsetup_header(self, mapped_name: str, slave_device: str = None) -> dict:
"""Reads LUKS header information from a device or header file into a dict"""
from json import loads

header_file = self["cryptsetup"][mapped_name].get("header_file")
if not header_file:
if slave_device:
Expand Down Expand Up @@ -292,8 +293,6 @@ def _validate_cryptsetup_device(self, mapped_name) -> None:
@unset("_cryptsetup_backend")
def detect_cryptsetup_backend(self) -> None:
"""Determines the cryptsetup backend by running 'cryptsetup --debug luksDump' on this file"""
from re import search

try:
raw_luks_info = (
self._run(["cryptsetup", "--debug", "luksDump", __file__], fail_silent=True, fail_hard=False)
Expand Down Expand Up @@ -487,8 +486,6 @@ def open_crypt_dev(self) -> str:

def _open_crypt_dev(self, name: str, parameters: dict) -> list[str]:
"""Generates a loop to open a cryptsetup device with the given parameters."""
from textwrap import dedent

retries = parameters.get("retries", self["cryptsetup_retries"])
out = [
f"einfo 'Opening cryptsetup device: {name}'",
Expand Down
4 changes: 2 additions & 2 deletions src/ugrd/fs/mounts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
__author__ = "desultory"
__version__ = "6.6.1"
__version__ = "6.6.2"

from pathlib import Path
from re import search
from typing import Union

from ugrd import AutodetectError, ValidationError
Expand Down Expand Up @@ -315,7 +316,6 @@ def get_blkid_info(self, device=None) -> dict:
"""Gets the blkid info for all devices if no device is passed.
Gets the blkid info for the passed device if a device is passed.
The info is stored in self['_blkid_info']."""
from re import search

try:
if device:
Expand Down
8 changes: 4 additions & 4 deletions src/ugrd/fs/test_image.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
__version__ = "1.2.1"
__version__ = "1.2.2"

from tempfile import TemporaryDirectory

from zenlib.util import colorize, contains

Expand Down Expand Up @@ -103,8 +105,6 @@ def make_test_image(self):
elif rootfs_type == "xfs":
self._run(["mkfs", "-t", rootfs_type, "-m", "uuid=%s" % rootfs_uuid, image_path])
try: # XFS doesn't support importing a directory as a filesystem, it must be mounted
from tempfile import TemporaryDirectory

with TemporaryDirectory() as tmp_dir:
self._run(["mount", image_path, tmp_dir])
self._run(["cp", "-a", f"{build_dir}/.", tmp_dir])
Expand All @@ -113,7 +113,7 @@ def make_test_image(self):
raise RuntimeError("Could not mount the XFS test image: %s", e)
elif rootfs_type == "squashfs":
# First, make the inner squashfs image
squashfs_image = self._get_out_path(f'squash/{self["squashfs_image"]}')
squashfs_image = self._get_out_path(f"squash/{self['squashfs_image']}")
if squashfs_image.exists():
if self.clean:
self.logger.warning("Removing existing squashfs image file: %s" % colorize(squashfs_image, "red"))
Expand Down
5 changes: 2 additions & 3 deletions src/ugrd/initramfs_dict.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__author__ = "desultory"
__version__ = "2.3.3"
__version__ = "2.3.4"

from collections import UserDict
from importlib import import_module
Expand All @@ -9,6 +9,7 @@
from tomllib import TOMLDecodeError, load
from typing import Callable

from pycpio import PyCPIO
from zenlib.logging import loggify
from zenlib.types import NoDupFlatList
from zenlib.util import colorize, handle_plural, pretty_print
Expand Down Expand Up @@ -151,8 +152,6 @@ def _process_custom_parameters(self, parameter_name: str, parameter_type: type)
Updates the custom_parameters attribute.
Sets the initial value of the parameter based on the type.
"""
from pycpio import PyCPIO

if isinstance(parameter_type, str):
parameter_type = eval(parameter_type)

Expand Down
5 changes: 1 addition & 4 deletions src/ugrd/initramfs_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from importlib.metadata import version
from textwrap import dedent
from tomllib import TOMLDecodeError, load

from zenlib.logging import loggify
Expand Down Expand Up @@ -114,8 +115,6 @@ def run_func(self, function, force_include=False, force_exclude=False) -> list[s
return function_output

if isinstance(function_output, str) and "\n" in function_output:
from textwrap import dedent

function_output = dedent(function_output)
function_output = [ # If the output string has a newline, split and get rid of empty lines
line for line in function_output.split("\n") if line and line != "\n" and not line.isspace()
Expand Down Expand Up @@ -241,8 +240,6 @@ def run_hook(self, hook: str, *args, **kwargs) -> list[str]:

def generate_profile(self) -> list[str]:
"""Generates the shell profile file based on self.included_functions."""
from importlib.metadata import version

ver = version(__package__) or 9999 # Version won't be found unless the package is installed
out = [
self["shebang"].split(" ")[0], # Don't add arguments to the shebang (for the profile)
Expand Down
8 changes: 3 additions & 5 deletions src/ugrd/kmod/kmod.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
__author__ = "desultory"
__version__ = "3.2.2"
__version__ = "3.2.3"

from pathlib import Path
from platform import uname
from struct import unpack
from subprocess import run

from ugrd.kmod import BuiltinModuleError, DependencyResolutionError, IgnoredModuleError, _normalize_kmod_name
Expand Down Expand Up @@ -115,8 +117,6 @@ def _autodetect_modules_lspci(self) -> None:
@contains("kmod_autodetect_lsmod", "kmod_autodetect_lsmod is not enabled, skipping.")
def _autodetect_modules_lsmod(self) -> None:
"""Gets the name of all currently used kernel modules."""
from platform import uname

if self.get("kernel_version") and self["kernel_version"] != uname().release:
self.logger.warning(
"Kernel version is set to %s, but the current kernel version is %s"
Expand Down Expand Up @@ -181,8 +181,6 @@ def _get_kver_from_header(self) -> str:
The version string can be up to 127 bytes long and is null-terminated.
https://www.kernel.org/doc/html/v6.7/arch/x86/boot.html#the-real-mode-kernel-header
"""
from struct import unpack

kernel_path = _find_kernel_image(self)
kver_offset = unpack("<h", kernel_path.read_bytes()[0x020E:0x0210])[0] + 512
header = kernel_path.read_bytes()[kver_offset : kver_offset + 127]
Expand Down

0 comments on commit 48472cb

Please sign in to comment.