Skip to content

Commit e753102

Browse files
fixed install script tabular
1 parent 97eb90e commit e753102

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed

.pre-commit-config.yaml

+2-4
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,15 @@ repos:
5252
- id: nbstripout-fast
5353
# ruff
5454
- repo: https://github.com/astral-sh/ruff-pre-commit
55-
rev: v0.9.10
55+
rev: v0.11.0
5656
hooks:
5757
- id: ruff
58-
types_or: [python, pyi]
58+
args: ["--output-format", "concise"]
5959
- id: ruff
6060
name: ruff-isort
6161
args: ["--select", "I", "--fix"]
62-
types_or: [python, pyi]
6362
- id: ruff-format
6463
args: ["--preview"]
65-
types_or: [python, pyi]
6664
# pyright
6765
- repo: https://github.com/RobertCraigie/pyright-python
6866
rev: v1.1.396

install.py

+40-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/usr/bin/env python3
2+
# /// script
3+
# requires-python = ">=3.11"
4+
# ///
25
"""Generate phrases for autokey."""
36

47
# %% Imports
@@ -35,8 +38,9 @@
3538
LEGAL_CHARS = re.compile(r"[\x21-\x5B\x5D-\x7E]+")
3639
"""Regex pattern for legal characters."""
3740
ABBREVIATION_PATTERN = re.compile(r"\x5C[\x21-\x7E]+\x20")
38-
# ABBREVIATION_PATTERN = re.compile(r"\x5C[\x21-\x5B\x5D-\x7E]+\x20") # exclude x5C (backslash)
3941
"""Regex pattern for abbreviations start with backslash (5C) and end in space (20)."""
42+
SPECIAL_DIR = "custom_special"
43+
"""Directory for special characters."""
4044

4145

4246
def is_char(s: object, /) -> TypeGuard[CHAR]:
@@ -258,6 +262,7 @@ def load_icons(fname: str | Path, /) -> list[UnprocessedSample]:
258262

259263

260264
def process_icons(data: list[UnprocessedSample], /) -> list[UnicodeSample]:
265+
r"""Process the unicode samples."""
261266
samples: list[UnicodeSample] = []
262267
# parsed = Counter() # ucode -> count
263268
# all_abbreviations = defaultdict(list) # abbrv -> ucode
@@ -463,30 +468,44 @@ def generate_character(
463468
target_dir: Path,
464469
default: bool = False,
465470
) -> None:
466-
"""Generate special characters."""
467-
471+
r"""Generate special characters."""
468472
text_file = target_dir / f"{sample.ucode}.txt"
469473
json_file = target_dir / f".{sample.ucode}.json"
470-
471474
if text_file.exists() or json_file.exists():
472-
if query_choice(
473-
f"Delete existing special character {sample.char!r}?", choices=[False, True]
475+
match query_choice(
476+
f"Found existing special character {sample.char!r} ({sample.ucode}).",
477+
choices=["keep", "delete", "overwrite"],
474478
):
475-
text_file.unlink()
476-
json_file.unlink()
477-
elif query_choice(
478-
f"Do you want to generate special character {sample.char!r}? ({default=})",
479-
choices=[default, not default],
480-
):
481-
target_dir.mkdir(exist_ok=True)
482-
create_autokey_phrase(
483-
NEWLINE, template=template, path=target_dir, overwrite=True
484-
)
485-
LOGGER.info("✅ Added %s.", sample.char)
479+
case "keep":
480+
pass
481+
case "delete":
482+
text_file.unlink()
483+
json_file.unlink()
484+
return
485+
case "overwrite":
486+
text_file.unlink()
487+
json_file.unlink()
488+
case _:
489+
raise ValueError("Invalid choice.")
490+
else:
491+
match query_choice(
492+
f"Install special character {sample.char!r}?",
493+
choices=[False, True],
494+
):
495+
case False:
496+
return
497+
case True:
498+
pass
499+
case _:
500+
raise ValueError("Invalid choice.")
501+
502+
target_dir.mkdir(exist_ok=True)
503+
create_autokey_phrase(sample, template=template, path=target_dir, overwrite=True)
504+
LOGGER.info("✅ Added %s.", sample.char)
486505

487506

488507
def generate_help(*, target_dir: Path) -> None:
489-
"""Create help script and config."""
508+
r"""Create help script and config."""
490509
LOGGER.info("=" * 80)
491510
LOGGER.info("Creating help script in %s.", target_dir)
492511

@@ -505,7 +524,7 @@ def generate_help(*, target_dir: Path) -> None:
505524

506525

507526
def make_template(abbreviations: list[str], description: str, sendmode: str) -> JSON:
508-
"""Create the template."""
527+
r"""Create the template."""
509528
return TEMPLATE | {
510529
"abbreviation": ABBREVIATION | {"abbreviations": abbreviations},
511530
"description": description,
@@ -517,6 +536,7 @@ def make_template(abbreviations: list[str], description: str, sendmode: str) ->
517536

518537

519538
def main() -> None:
539+
r"""Install function."""
520540
logging.basicConfig(level=logging.INFO)
521541

522542
detected_directory = Path.home() / ".config/autokey/data/"
@@ -586,7 +606,7 @@ def main() -> None:
586606
generate_codes(directory, target_dir=target_dir, template=template)
587607

588608
# add special characters
589-
special = target_dir / "special"
609+
special = target_dir / SPECIAL_DIR
590610
generate_character(TABULATOR, target_dir=special, template=template, default=False)
591611
generate_character(NEWLINE, target_dir=special, template=template, default=False)
592612

0 commit comments

Comments
 (0)