refactor: rename bin/ package to mytoolkit/
This commit is contained in:
@@ -32,7 +32,7 @@ def synthesize_tts(
|
||||
Returns absolute path to the output audio file.
|
||||
"""
|
||||
# Delayed import to avoid circular dependency when bin.commands is not yet loaded
|
||||
from bin.commands.protocols import EventType, MsgType, full_client_request, receive_message
|
||||
from mytoolkit.commands.protocols import EventType, MsgType, full_client_request, receive_message
|
||||
|
||||
try:
|
||||
import websockets
|
||||
@@ -4,17 +4,17 @@ from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
from bin.commands import pdf, image, latex, video, bib, voice
|
||||
from bin.commands.convert import convert_cmd
|
||||
from bin.commands.env import env_cmd
|
||||
from bin.commands.templates import templates_cmd
|
||||
from bin.commands.ssh import ssh_cmd
|
||||
from bin.commands.git import git_cmd
|
||||
from bin.commands.server import server_cmd
|
||||
from bin.commands.webpage import webpage_cmd
|
||||
from bin.commands.mycv import mycv_cmd
|
||||
from bin.commands.mail import mail
|
||||
from bin.commands.self_mgmt import update_cmd, uninstall_cmd
|
||||
from mytoolkit.commands import pdf, image, latex, video, bib, voice, docx
|
||||
from mytoolkit.commands.convert import convert_cmd
|
||||
from mytoolkit.commands.env import env_cmd
|
||||
from mytoolkit.commands.templates import templates_cmd
|
||||
from mytoolkit.commands.ssh import ssh_cmd
|
||||
from mytoolkit.commands.git import git_cmd
|
||||
from mytoolkit.commands.server import server_cmd
|
||||
from mytoolkit.commands.webpage import webpage_cmd
|
||||
from mytoolkit.commands.mycv import mycv_cmd
|
||||
from mytoolkit.commands.mail import mail
|
||||
from mytoolkit.commands.self_mgmt import update_cmd, uninstall_cmd
|
||||
|
||||
|
||||
@click.group()
|
||||
@@ -27,6 +27,7 @@ def cli():
|
||||
# Register command groups
|
||||
cli.add_command(convert_cmd)
|
||||
cli.add_command(pdf.pdf)
|
||||
cli.add_command(docx.docx)
|
||||
cli.add_command(image.image)
|
||||
cli.add_command(voice.voice)
|
||||
cli.add_command(latex.latex)
|
||||
@@ -5,8 +5,8 @@ from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
from bin.config import config
|
||||
from bin.utils import handle_errors, run_command
|
||||
from mytoolkit.config import config
|
||||
from mytoolkit.utils import handle_errors, run_command
|
||||
|
||||
|
||||
@click.group()
|
||||
@@ -6,9 +6,9 @@ import click
|
||||
from pypdf import PdfReader, PdfWriter
|
||||
from PIL import Image
|
||||
|
||||
from bin.md_to_pdf import build_pdf
|
||||
from bin import templates_registry
|
||||
from bin.utils import handle_errors, run_command
|
||||
from mytoolkit.md_to_pdf import build_pdf
|
||||
from mytoolkit import templates_registry
|
||||
from mytoolkit.utils import handle_errors, run_command
|
||||
|
||||
|
||||
@click.command("convert")
|
||||
@@ -0,0 +1,51 @@
|
||||
"""DOCX utilities."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import click
|
||||
from docx import Document
|
||||
|
||||
from mytoolkit.utils import handle_errors
|
||||
|
||||
|
||||
@click.group()
|
||||
def docx():
|
||||
"""DOCX manipulation commands."""
|
||||
pass
|
||||
|
||||
|
||||
@docx.command("extract-text")
|
||||
@click.argument("input_file", type=click.Path(exists=True, dir_okay=False, path_type=Path))
|
||||
@click.option(
|
||||
"-o",
|
||||
"--output",
|
||||
type=click.Path(dir_okay=False, path_type=Path),
|
||||
help="Output text file. Defaults to stdout.",
|
||||
)
|
||||
@click.option(
|
||||
"--preserve-empty/--no-preserve-empty",
|
||||
default=False,
|
||||
help="Preserve empty paragraphs as blank lines.",
|
||||
)
|
||||
@handle_errors
|
||||
def extract_text(input_file, output, preserve_empty):
|
||||
"""Extract text from a DOCX file.
|
||||
|
||||
Extracts all paragraph text from the document, with one paragraph per line.
|
||||
Tables are not extracted by default.
|
||||
"""
|
||||
document = Document(str(input_file))
|
||||
|
||||
paragraphs = []
|
||||
for para in document.paragraphs:
|
||||
text = para.text.strip()
|
||||
if text or preserve_empty:
|
||||
paragraphs.append(para.text)
|
||||
|
||||
result = "\n".join(paragraphs)
|
||||
|
||||
if output:
|
||||
output.write_text(result, encoding="utf-8")
|
||||
click.echo(f"Extracted text to {output}")
|
||||
else:
|
||||
click.echo(result)
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import click
|
||||
|
||||
from bin.config import CONFIG_PATH, config
|
||||
from mytoolkit.config import CONFIG_PATH, config
|
||||
|
||||
|
||||
@click.group(name="env")
|
||||
@@ -7,7 +7,7 @@ import sys
|
||||
|
||||
import click
|
||||
|
||||
from bin.config import config
|
||||
from mytoolkit.config import config
|
||||
|
||||
|
||||
def _get_proxies() -> dict[str, str]:
|
||||
@@ -5,9 +5,9 @@ from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
from bin.api.image import _RATIO_MAP, generate_image
|
||||
from bin.config import config
|
||||
from bin.utils import handle_errors, run_command
|
||||
from mytoolkit.api.image import _RATIO_MAP, generate_image
|
||||
from mytoolkit.config import config
|
||||
from mytoolkit.utils import handle_errors, run_command
|
||||
|
||||
|
||||
@click.group()
|
||||
@@ -5,7 +5,7 @@ from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
from bin.utils import handle_errors, run_command
|
||||
from mytoolkit.utils import handle_errors, run_command
|
||||
|
||||
|
||||
@click.group()
|
||||
@@ -19,7 +19,7 @@ from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
from bin.utils import handle_errors
|
||||
from mytoolkit.utils import handle_errors
|
||||
|
||||
_HOME = Path(os.environ.get("MYTOOLKIT_HOME", Path.home() / ".mytoolkit"))
|
||||
CONFIG_PATH = _HOME / "mail.json"
|
||||
@@ -5,7 +5,7 @@ from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
from bin.md_to_pdf import build_pdf
|
||||
from mytoolkit.md_to_pdf import build_pdf
|
||||
|
||||
|
||||
_CV_DIR = (
|
||||
@@ -8,8 +8,8 @@ import click
|
||||
from pypdf import PdfReader, PdfWriter
|
||||
from PIL import Image
|
||||
|
||||
from bin.md_to_pdf import expand_bookmarks
|
||||
from bin.utils import handle_errors, run_command
|
||||
from mytoolkit.md_to_pdf import expand_bookmarks
|
||||
from mytoolkit.utils import handle_errors, run_command
|
||||
|
||||
|
||||
@click.group()
|
||||
@@ -5,8 +5,8 @@ from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
from bin.config import config
|
||||
from bin.utils import handle_errors
|
||||
from mytoolkit.config import config
|
||||
from mytoolkit.utils import handle_errors
|
||||
|
||||
|
||||
def _get_hosts() -> dict:
|
||||
@@ -4,7 +4,7 @@ from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
from bin import templates_registry
|
||||
from mytoolkit import templates_registry
|
||||
|
||||
|
||||
@click.group(name="templates")
|
||||
@@ -5,7 +5,7 @@ from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
from bin.utils import handle_errors, run_command
|
||||
from mytoolkit.utils import handle_errors, run_command
|
||||
|
||||
|
||||
@click.group()
|
||||
@@ -5,9 +5,9 @@ from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
from bin.api.voice import synthesize_tts
|
||||
from bin.config import config
|
||||
from bin.utils import handle_errors
|
||||
from mytoolkit.api.voice import synthesize_tts
|
||||
from mytoolkit.config import config
|
||||
from mytoolkit.utils import handle_errors
|
||||
|
||||
_VOICE_CHOICES = [
|
||||
"zh_female_cancan_mars_bigtts",
|
||||
@@ -13,7 +13,7 @@ import time
|
||||
|
||||
import click
|
||||
|
||||
from bin.commands.server import (
|
||||
from mytoolkit.commands.server import (
|
||||
manageable_services,
|
||||
get_service,
|
||||
no_color_env,
|
||||
@@ -6,8 +6,8 @@ from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
from bin import templates_registry
|
||||
from bin.utils import run_command
|
||||
from mytoolkit import templates_registry
|
||||
from mytoolkit.utils import run_command
|
||||
|
||||
# Typst callouts exported by templates/md-to-pdf/{textbook,manual}/template.typ.
|
||||
# Keep this tuple and _extra_imports (below) in sync when adding or removing `#let` callouts.
|
||||
+2
-2
@@ -13,10 +13,10 @@ dependencies = [
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
mytoolkit = "bin.cli:main"
|
||||
mytoolkit = "mytoolkit.cli:main"
|
||||
|
||||
[tool.hatch.build.targets.wheel]
|
||||
packages = ["bin"]
|
||||
packages = ["mytoolkit"]
|
||||
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
|
||||
Reference in New Issue
Block a user