Skip to content

Commit fcbbb98

Browse files
committed
clean imports, black format
Signed-off-by: Zen <[email protected]>
1 parent 2466d2f commit fcbbb98

File tree

8 files changed

+21
-29
lines changed

8 files changed

+21
-29
lines changed

Diff for: src/ugrd/base/cmdline.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
__author__ = "desultory"
2-
__version__ = "3.1.0"
2+
__version__ = "3.1.1"
3+
4+
from importlib.metadata import PackageNotFoundError, version
35

46

57
def parse_cmdline_bool(self) -> str:
@@ -46,8 +48,6 @@ def export_exports(self) -> list[str]:
4648
Sets 'exported' to 1 once done.
4749
If 'exported' is set, returns early.
4850
"""
49-
from importlib.metadata import PackageNotFoundError, version
50-
5151
try:
5252
self["exports"]["VERSION"] = version(__package__.split(".")[0])
5353
except PackageNotFoundError:

Diff for: src/ugrd/base/keymap.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
__author__ = "desultory"
2-
__version__ = "1.0.0"
2+
__version__ = "1.0.1"
3+
4+
from pathlib import Path
35

46
from zenlib.util import contains
57

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

1718
if not isinstance(base_path, Path):
1819
base_path = Path(base_path)

Diff for: src/ugrd/crypto/cryptsetup.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
__author__ = "desultory"
22
__version__ = "4.0.4"
33

4+
from json import loads
45
from pathlib import Path
6+
from re import search
7+
from textwrap import dedent
58

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

162165
def _read_cryptsetup_header(self, mapped_name: str, slave_device: str = None) -> dict:
163166
"""Reads LUKS header information from a device or header file into a dict"""
164-
from json import loads
165-
166167
header_file = self["cryptsetup"][mapped_name].get("header_file")
167168
if not header_file:
168169
if slave_device:
@@ -292,8 +293,6 @@ def _validate_cryptsetup_device(self, mapped_name) -> None:
292293
@unset("_cryptsetup_backend")
293294
def detect_cryptsetup_backend(self) -> None:
294295
"""Determines the cryptsetup backend by running 'cryptsetup --debug luksDump' on this file"""
295-
from re import search
296-
297296
try:
298297
raw_luks_info = (
299298
self._run(["cryptsetup", "--debug", "luksDump", __file__], fail_silent=True, fail_hard=False)
@@ -487,8 +486,6 @@ def open_crypt_dev(self) -> str:
487486

488487
def _open_crypt_dev(self, name: str, parameters: dict) -> list[str]:
489488
"""Generates a loop to open a cryptsetup device with the given parameters."""
490-
from textwrap import dedent
491-
492489
retries = parameters.get("retries", self["cryptsetup_retries"])
493490
out = [
494491
f"einfo 'Opening cryptsetup device: {name}'",

Diff for: src/ugrd/fs/mounts.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
__author__ = "desultory"
2-
__version__ = "6.6.1"
2+
__version__ = "6.6.2"
33

44
from pathlib import Path
5+
from re import search
56
from typing import Union
67

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

320320
try:
321321
if device:

Diff for: src/ugrd/fs/test_image.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
__version__ = "1.2.1"
1+
__version__ = "1.2.2"
2+
3+
from tempfile import TemporaryDirectory
24

35
from zenlib.util import colorize, contains
46

@@ -103,8 +105,6 @@ def make_test_image(self):
103105
elif rootfs_type == "xfs":
104106
self._run(["mkfs", "-t", rootfs_type, "-m", "uuid=%s" % rootfs_uuid, image_path])
105107
try: # XFS doesn't support importing a directory as a filesystem, it must be mounted
106-
from tempfile import TemporaryDirectory
107-
108108
with TemporaryDirectory() as tmp_dir:
109109
self._run(["mount", image_path, tmp_dir])
110110
self._run(["cp", "-a", f"{build_dir}/.", tmp_dir])
@@ -113,7 +113,7 @@ def make_test_image(self):
113113
raise RuntimeError("Could not mount the XFS test image: %s", e)
114114
elif rootfs_type == "squashfs":
115115
# First, make the inner squashfs image
116-
squashfs_image = self._get_out_path(f'squash/{self["squashfs_image"]}')
116+
squashfs_image = self._get_out_path(f"squash/{self['squashfs_image']}")
117117
if squashfs_image.exists():
118118
if self.clean:
119119
self.logger.warning("Removing existing squashfs image file: %s" % colorize(squashfs_image, "red"))

Diff for: src/ugrd/initramfs_dict.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "desultory"
2-
__version__ = "2.3.3"
2+
__version__ = "2.3.4"
33

44
from collections import UserDict
55
from importlib import import_module
@@ -9,6 +9,7 @@
99
from tomllib import TOMLDecodeError, load
1010
from typing import Callable
1111

12+
from pycpio import PyCPIO
1213
from zenlib.logging import loggify
1314
from zenlib.types import NoDupFlatList
1415
from zenlib.util import colorize, handle_plural, pretty_print
@@ -151,8 +152,6 @@ def _process_custom_parameters(self, parameter_name: str, parameter_type: type)
151152
Updates the custom_parameters attribute.
152153
Sets the initial value of the parameter based on the type.
153154
"""
154-
from pycpio import PyCPIO
155-
156155
if isinstance(parameter_type, str):
157156
parameter_type = eval(parameter_type)
158157

Diff for: src/ugrd/initramfs_generator.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from importlib.metadata import version
2+
from textwrap import dedent
23
from tomllib import TOMLDecodeError, load
34

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

116117
if isinstance(function_output, str) and "\n" in function_output:
117-
from textwrap import dedent
118-
119118
function_output = dedent(function_output)
120119
function_output = [ # If the output string has a newline, split and get rid of empty lines
121120
line for line in function_output.split("\n") if line and line != "\n" and not line.isspace()
@@ -241,8 +240,6 @@ def run_hook(self, hook: str, *args, **kwargs) -> list[str]:
241240

242241
def generate_profile(self) -> list[str]:
243242
"""Generates the shell profile file based on self.included_functions."""
244-
from importlib.metadata import version
245-
246243
ver = version(__package__) or 9999 # Version won't be found unless the package is installed
247244
out = [
248245
self["shebang"].split(" ")[0], # Don't add arguments to the shebang (for the profile)

Diff for: src/ugrd/kmod/kmod.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
__author__ = "desultory"
2-
__version__ = "3.2.2"
2+
__version__ = "3.2.3"
33

44
from pathlib import Path
5+
from platform import uname
6+
from struct import unpack
57
from subprocess import run
68

79
from ugrd.kmod import BuiltinModuleError, DependencyResolutionError, IgnoredModuleError, _normalize_kmod_name
@@ -115,8 +117,6 @@ def _autodetect_modules_lspci(self) -> None:
115117
@contains("kmod_autodetect_lsmod", "kmod_autodetect_lsmod is not enabled, skipping.")
116118
def _autodetect_modules_lsmod(self) -> None:
117119
"""Gets the name of all currently used kernel modules."""
118-
from platform import uname
119-
120120
if self.get("kernel_version") and self["kernel_version"] != uname().release:
121121
self.logger.warning(
122122
"Kernel version is set to %s, but the current kernel version is %s"
@@ -181,8 +181,6 @@ def _get_kver_from_header(self) -> str:
181181
The version string can be up to 127 bytes long and is null-terminated.
182182
https://www.kernel.org/doc/html/v6.7/arch/x86/boot.html#the-real-mode-kernel-header
183183
"""
184-
from struct import unpack
185-
186184
kernel_path = _find_kernel_image(self)
187185
kver_offset = unpack("<h", kernel_path.read_bytes()[0x020E:0x0210])[0] + 512
188186
header = kernel_path.read_bytes()[kver_offset : kver_offset + 127]

0 commit comments

Comments
 (0)