Skip to content

Commit

Permalink
Ruff format and sort imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Jip-Hop committed Jul 16, 2024
1 parent 889f479 commit 00fb155
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 50 deletions.
1 change: 0 additions & 1 deletion src/jlmkr/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from cli import main


if __name__ == "__main__":
try:
sys.exit(main())
Expand Down
20 changes: 10 additions & 10 deletions src/jlmkr/actions/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
import contextlib
import os
import sys

from inspect import cleandoc
from pathlib import Path, PurePath
from textwrap import dedent

from actions.start import start_jail
from cli import DISCLAIMER
from paths import COMMAND_NAME, JAILS_DIR_PATH, SCRIPT_NAME, SCRIPT_DIR_PATH
from paths import COMMAND_NAME, JAILS_DIR_PATH, SCRIPT_DIR_PATH, SCRIPT_NAME
from utils.chroot import Chroot
from utils.config_parser import KeyValueParser, DEFAULT_CONFIG
from utils.console import YELLOW, BOLD, NORMAL, eprint
from utils.config_parser import DEFAULT_CONFIG, KeyValueParser
from utils.console import BOLD, NORMAL, YELLOW, eprint
from utils.dataset import create_zfs_dataset, get_zfs_dataset
from utils.download import run_lxc_download_script
from utils.files import stat_chmod, get_mount_point
from utils.files import get_mount_point, stat_chmod
from utils.jail import (
check_jail_name_valid,
check_jail_name_available,
check_jail_name_valid,
cleanup,
get_jail_config_path,
get_jail_rootfs_path,
get_jail_path,
get_jail_rootfs_path,
)
from utils.dataset import get_zfs_dataset, create_zfs_dataset
from utils.jail import cleanup
from utils.os_release import parse_os_release

from actions.start import start_jail


def create_jail(**kwargs):
print(DISCLAIMER)
Expand Down
8 changes: 6 additions & 2 deletions src/jlmkr/actions/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import subprocess

from utils.console import eprint
from utils.jail import check_jail_name_valid, check_jail_name_available
from utils.jail import get_jail_config_path, jail_is_running
from utils.editor import get_text_editor
from utils.jail import (
check_jail_name_available,
check_jail_name_valid,
get_jail_config_path,
jail_is_running,
)


def edit_jail(jail_name):
Expand Down
3 changes: 1 addition & 2 deletions src/jlmkr/actions/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

import json
import subprocess

from collections import defaultdict

from utils.config_parser import parse_config_file
from utils.console import eprint, NORMAL, UNDERLINE
from utils.console import NORMAL, UNDERLINE, eprint
from utils.jail import get_all_jail_names, get_jail_config_path, get_jail_rootfs_path
from utils.os_release import parse_os_release

Expand Down
7 changes: 4 additions & 3 deletions src/jlmkr/actions/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
#
# SPDX-License-Identifier: LGPL-3.0-only

from actions.stop import stop_jail
from utils.console import eprint
from utils.jail import (
check_jail_name_valid,
check_jail_name_available,
get_jail_path,
check_jail_name_valid,
cleanup,
get_jail_path,
)

from actions.stop import stop_jail


def remove_jail(jail_name):
"""
Expand Down
3 changes: 2 additions & 1 deletion src/jlmkr/actions/restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#
# SPDX-License-Identifier: LGPL-3.0-only

from utils.console import eprint

from actions.start import start_jail
from actions.stop import stop_jail
from utils.console import eprint


def restart_jail(jail_name):
Expand Down
16 changes: 8 additions & 8 deletions src/jlmkr/actions/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
import shlex
import subprocess
import tempfile

from pathlib import Path
from textwrap import dedent

from actions.exec import exec_jail
from paths import COMMAND_NAME, SHORTNAME, JAIL_ROOTFS_NAME
from paths import COMMAND_NAME, JAIL_ROOTFS_NAME, SHORTNAME
from utils.config_parser import parse_config_file
from utils.console import eprint, RED, BOLD, NORMAL
from utils.console import BOLD, NORMAL, RED, eprint
from utils.files import stat_chmod
from utils.gpu import passthrough_intel, passthrough_nvidia
from utils.jail import (
get_jail_path,
jail_is_running,
get_jail_config_path,
get_jail_path,
get_jail_rootfs_path,
jail_is_running,
)
from utils.files import stat_chmod
from utils.gpu import passthrough_intel, passthrough_nvidia

from actions.exec import exec_jail


def start_jail(jail_name):
Expand Down
3 changes: 2 additions & 1 deletion src/jlmkr/actions/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#
# SPDX-License-Identifier: LGPL-3.0-only

from actions.start import start_jail
from utils.config_parser import parse_config_file
from utils.jail import get_all_jail_names, get_jail_config_path

from actions.start import start_jail


def startup_jails():
start_failure = False
Expand Down
24 changes: 12 additions & 12 deletions src/jlmkr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
import os
import sys

from __main__ import __version__
from data import DISCLAIMER
from paths import SCRIPT_PATH, COMMAND_NAME, SCRIPT_NAME
from utils.config_parser import ExceptionWithParser
from utils.console import fail
from utils.editor import get_text_editor
from utils.files import stat_chmod

from actions.create import create_jail
from actions.edit import edit_jail
from actions.exec import exec_jail
Expand All @@ -27,14 +19,22 @@
from actions.startup import startup_jails
from actions.status import status_jail
from actions.stop import stop_jail
from data import DISCLAIMER
from paths import COMMAND_NAME, SCRIPT_NAME, SCRIPT_PATH
from utils.config_parser import ExceptionWithParser
from utils.console import fail
from utils.editor import get_text_editor
from utils.files import stat_chmod

from __main__ import __version__


def main():
if os.stat(SCRIPT_PATH).st_uid != 0:
if os.environ.get('JLMKR_DEBUG') is None:
fail(
f"This script should be owned by the root user... Fix it manually with: `chown root {SCRIPT_PATH}`."
)
if os.environ.get("JLMKR_DEBUG") is None:
fail(
f"This script should be owned by the root user... Fix it manually with: `chown root {SCRIPT_PATH}`."
)

parser = argparse.ArgumentParser(
description=__doc__,
Expand Down
4 changes: 2 additions & 2 deletions src/jlmkr/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#
# SPDX-License-Identifier: LGPL-3.0-only

from __main__ import __disclaimer__
from utils.console import YELLOW, BOLD, NORMAL
from utils.console import BOLD, NORMAL, YELLOW

from __main__ import __disclaimer__

DISCLAIMER = f"""{YELLOW}{BOLD}{__disclaimer__}{NORMAL}"""

Expand Down
1 change: 0 additions & 1 deletion src/jlmkr/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import os.path


# When running as a zipapp, the script file is a parent
ZIPAPP_PATH = os.path.realpath(__file__)
while not os.path.exists(ZIPAPP_PATH):
Expand Down
2 changes: 1 addition & 1 deletion src/jlmkr/utils/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import re

from data import DEFAULT_CONFIG
from utils.console import eprint

from utils.console import eprint

# Used in parser getters to indicate the default behavior when a specific
# option is not found. Created to enable `None` as a valid fallback value.
Expand Down
1 change: 0 additions & 1 deletion src/jlmkr/utils/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import sys


# Only set a color if we have an interactive tty
if sys.stdout.isatty():
BOLD = "\033[1m"
Expand Down
6 changes: 4 additions & 2 deletions src/jlmkr/utils/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
#
# SPDX-License-Identifier: LGPL-3.0-only

import os.path
import subprocess
from pathlib import PurePath

from paths import SCRIPT_DIR_PATH

from utils.console import eprint, fail
import os.path
import subprocess


def _get_relative_path_in_jailmaker_dir(absolute_path):
Expand Down
1 change: 0 additions & 1 deletion src/jlmkr/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from utils.console import eprint
from utils.files import stat_chmod


DOWNLOAD_SCRIPT_DIGEST = (
"cfcb5d08b24187d108f2ab0d21a6cc4b73dcd7f5d7dfc80803bfd7f1642d638d"
)
Expand Down
3 changes: 1 addition & 2 deletions src/jlmkr/utils/gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

import os.path
import subprocess

from pathlib import Path
from textwrap import dedent

from paths import SHORTNAME

from utils.console import eprint
from utils.jail import get_jail_rootfs_path


# Test intel GPU by decoding mp4 file (output is discarded)
# Run the commands below in the jail:
# curl -o bunny.mp4 https://www.w3schools.com/html/mov_bbb.mp4
Expand Down
1 change: 1 addition & 0 deletions src/jlmkr/utils/os_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

def parse_os_release(new_root):
result = {}

with Chroot(new_root):
# Use chroot to correctly resolve os-release symlink (for nixos)
for candidate in ["/etc/os-release", "/usr/lib/os-release"]:
Expand Down

0 comments on commit 00fb155

Please sign in to comment.