Skip to content

Commit

Permalink
Format code with black
Browse files Browse the repository at this point in the history
Add formatting check to linters.
  • Loading branch information
igo95862 committed Jun 9, 2024
1 parent d123562 commit 7f77bf5
Show file tree
Hide file tree
Showing 26 changed files with 1,049 additions and 1,058 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ jobs:
image: docker.io/archlinux:latest
steps:
- name: Install linters and Python dependencies
run: |
pacman --noconfirm -Syu \
git \
python-pyflakes reuse \
mypy python-pyqt6 python-tomli-w
run: >
pacman --noconfirm -Syu
git
python-pyflakes reuse
mypy python-pyqt6 python-tomli-w
python-black python-isort
- name: Checkout
uses: actions/checkout@v4
- name: Add safe git directory
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Run linters
run: |
python3 tools/run_linters.py
python3 -m tools.run_linters
build:
name: Build
Expand All @@ -37,9 +38,9 @@ jobs:
image: docker.io/archlinux:latest
steps:
- name: Install build dependencies
run: |
pacman --noconfirm -Syu \
git python python-jinja scdoc meson
run: >
pacman --noconfirm -Syu
git python python-jinja scdoc meson
- name: Checkout
uses: actions/checkout@v4
- name: Run meson
Expand Down
80 changes: 40 additions & 40 deletions docs/man_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@


def scdoc_paragraph(s: Iterator[str]) -> str:
return '\n\n'.join(s)
return "\n\n".join(s)


def scdoc_indent(s: str, indent_level: int = 1) -> str:
return indent(s, '\t'*indent_level)
return indent(s, "\t" * indent_level)


SUBCOMMAND_HELP = {
'run': """The arguments are optional if you have
"run": """The arguments are optional if you have
_executable_name_ key set in config.
Otherwise, you *must* specify arguments to run.
Expand All @@ -40,29 +40,29 @@ def scdoc_indent(s: str, indent_level: int = 1) -> str:
the sandbox. If _--wait_ option is passed the output of the command
will be returned.
""",
'create': """When a new instance is created a desktop
"create": """When a new instance is created a desktop
entry will be also created.
Creating an instance from profile will print some import tips that you
can use to import configuration from unsandboxed application.
""",
'generate-desktop-entry': """Desktop entry can either be specified
"generate-desktop-entry": """Desktop entry can either be specified
by profile, path, name or extracted from metadata when instance was created.
""",
'edit': """After exiting the editor, the file is validated and
"edit": """After exiting the editor, the file is validated and
only written if validation is successful.
_EDITOR_ environmental variable must be set.
""",
'list': '\n'.join(
f"- *{x}*" for x in
BUBBLEJAIL_CMD['list']['add_argument']['list_what']['choices']
)
"list": "\n".join(
f"- *{x}*"
for x in BUBBLEJAIL_CMD["list"]["add_argument"]["list_what"]["choices"]
),
}

OPTION_HELP = {
'run': {
'--debug-bwrap-args': """The instance name must be separated with
"run": {
"--debug-bwrap-args": """The instance name must be separated with
extra -- from the instance name.
This option can be repeated multiple times for multiple args to bwrap.
Expand All @@ -75,8 +75,8 @@ def scdoc_indent(s: str, indent_level: int = 1) -> str:
"""
},
'create': {
'--profile': """If omitted an empty profile will be used and
"create": {
"--profile": """If omitted an empty profile will be used and
the user will have to define the configuration manually.
There is also a _generic_ profile which has some common settings such
Expand All @@ -87,16 +87,16 @@ def scdoc_indent(s: str, indent_level: int = 1) -> str:


def format_option(subcommand: str, option: str) -> Iterator[str]:
option_data = BUBBLEJAIL_CMD[subcommand]['add_argument'][option]
option_data = BUBBLEJAIL_CMD[subcommand]["add_argument"][option]

yield f"*{option}*"

option_action = option_data.get('action')
option_action = option_data.get("action")
match option_action:
case 'store_true' | 'store_false':
case "store_true" | "store_false":
return

option_metavar = option_data.get('metavar')
option_metavar = option_data.get("metavar")
match option_metavar:
case str():
yield f"<{option_metavar}>"
Expand All @@ -109,44 +109,44 @@ def format_option(subcommand: str, option: str) -> Iterator[str]:


def get_option_description(subcommand: str, option: str) -> tuple[str, ...]:
option_data = BUBBLEJAIL_CMD[subcommand]['add_argument'][option]
option_help = option_data['help']
option_data = BUBBLEJAIL_CMD[subcommand]["add_argument"][option]
option_help = option_data["help"]
try:
option_extra_description = OPTION_HELP[subcommand][option]
except KeyError:
option_extra_description = ''
option_extra_description = ""

return option_help, option_extra_description


def get_options(subcommand: str) -> tuple[str, ...]:
return tuple(
filter(
lambda x: x.startswith('-'),
BUBBLEJAIL_CMD[subcommand]['add_argument'].keys(),
lambda x: x.startswith("-"),
BUBBLEJAIL_CMD[subcommand]["add_argument"].keys(),
)
)


def format_arg_names(subcommand: str) -> Iterator[str]:
if get_options(subcommand):
yield '[options...]'
yield "[options...]"

add_arguments_dict = BUBBLEJAIL_CMD[subcommand]['add_argument']
add_arguments_dict = BUBBLEJAIL_CMD[subcommand]["add_argument"]
for add_argument, options in add_arguments_dict.items():
if add_argument.startswith('-'):
if add_argument.startswith("-"):
continue

if options.get('nargs'):
if options.get("nargs"):
yield f"[{add_argument}...]"
else:
yield f"[{add_argument}]"


def get_subcommand_description(subcommand: str) -> tuple[str, ...]:
return (
BUBBLEJAIL_CMD[subcommand]['description'],
SUBCOMMAND_HELP.get(subcommand, ''),
BUBBLEJAIL_CMD[subcommand]["description"],
SUBCOMMAND_HELP.get(subcommand, ""),
)


Expand All @@ -155,10 +155,10 @@ def generate_cmd_man(template_dir: Path) -> None:
loader=FileSystemLoader(template_dir),
undefined=StrictUndefined,
)
env.filters['scdoc_indent'] = scdoc_indent
env.filters['scdoc_paragraph'] = scdoc_paragraph
env.filters["scdoc_indent"] = scdoc_indent
env.filters["scdoc_paragraph"] = scdoc_paragraph

template = env.get_template('bubblejail.1.scd.jinja2')
template = env.get_template("bubblejail.1.scd.jinja2")

print(
template.render(
Expand All @@ -173,17 +173,17 @@ def generate_cmd_man(template_dir: Path) -> None:


def generate_services_man(template_dir: Path) -> None:
modules['xdg'] = MagicMock()
modules["xdg"] = MagicMock()

from bubblejail.services import SERVICES_CLASSES

env = Environment(
loader=FileSystemLoader(template_dir),
undefined=StrictUndefined,
)
env.filters['scdoc_indent'] = scdoc_indent
env.filters["scdoc_indent"] = scdoc_indent

template = env.get_template('bubblejail.services.5.scd.jinja2')
template = env.get_template("bubblejail.services.5.scd.jinja2")

print(
template.render(
Expand All @@ -193,25 +193,25 @@ def generate_services_man(template_dir: Path) -> None:


GENERATORS = {
'cmd': generate_cmd_man,
'services': generate_services_man,
"cmd": generate_cmd_man,
"services": generate_services_man,
}


def main() -> None:
arg_parse = ArgumentParser()
arg_parse.add_argument(
'--template-dir',
"--template-dir",
required=True,
type=Path,
)
arg_parse.add_argument(
'generator',
"generator",
choices=GENERATORS.keys(),
)
args = vars(arg_parse.parse_args())

generator_func_name = args.pop('generator')
generator_func_name = args.pop("generator")

GENERATORS[generator_func_name](**args)

Expand Down
Loading

0 comments on commit 7f77bf5

Please sign in to comment.