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.
|
Returns absolute path to the output audio file.
|
||||||
"""
|
"""
|
||||||
# Delayed import to avoid circular dependency when bin.commands is not yet loaded
|
# 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:
|
try:
|
||||||
import websockets
|
import websockets
|
||||||
@@ -4,17 +4,17 @@ from pathlib import Path
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from bin.commands import pdf, image, latex, video, bib, voice
|
from mytoolkit.commands import pdf, image, latex, video, bib, voice, docx
|
||||||
from bin.commands.convert import convert_cmd
|
from mytoolkit.commands.convert import convert_cmd
|
||||||
from bin.commands.env import env_cmd
|
from mytoolkit.commands.env import env_cmd
|
||||||
from bin.commands.templates import templates_cmd
|
from mytoolkit.commands.templates import templates_cmd
|
||||||
from bin.commands.ssh import ssh_cmd
|
from mytoolkit.commands.ssh import ssh_cmd
|
||||||
from bin.commands.git import git_cmd
|
from mytoolkit.commands.git import git_cmd
|
||||||
from bin.commands.server import server_cmd
|
from mytoolkit.commands.server import server_cmd
|
||||||
from bin.commands.webpage import webpage_cmd
|
from mytoolkit.commands.webpage import webpage_cmd
|
||||||
from bin.commands.mycv import mycv_cmd
|
from mytoolkit.commands.mycv import mycv_cmd
|
||||||
from bin.commands.mail import mail
|
from mytoolkit.commands.mail import mail
|
||||||
from bin.commands.self_mgmt import update_cmd, uninstall_cmd
|
from mytoolkit.commands.self_mgmt import update_cmd, uninstall_cmd
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
@@ -27,6 +27,7 @@ def cli():
|
|||||||
# Register command groups
|
# Register command groups
|
||||||
cli.add_command(convert_cmd)
|
cli.add_command(convert_cmd)
|
||||||
cli.add_command(pdf.pdf)
|
cli.add_command(pdf.pdf)
|
||||||
|
cli.add_command(docx.docx)
|
||||||
cli.add_command(image.image)
|
cli.add_command(image.image)
|
||||||
cli.add_command(voice.voice)
|
cli.add_command(voice.voice)
|
||||||
cli.add_command(latex.latex)
|
cli.add_command(latex.latex)
|
||||||
@@ -5,8 +5,8 @@ from pathlib import Path
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from bin.config import config
|
from mytoolkit.config import config
|
||||||
from bin.utils import handle_errors, run_command
|
from mytoolkit.utils import handle_errors, run_command
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
@@ -6,9 +6,9 @@ import click
|
|||||||
from pypdf import PdfReader, PdfWriter
|
from pypdf import PdfReader, PdfWriter
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from bin.md_to_pdf import build_pdf
|
from mytoolkit.md_to_pdf import build_pdf
|
||||||
from bin import templates_registry
|
from mytoolkit import templates_registry
|
||||||
from bin.utils import handle_errors, run_command
|
from mytoolkit.utils import handle_errors, run_command
|
||||||
|
|
||||||
|
|
||||||
@click.command("convert")
|
@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
|
import click
|
||||||
|
|
||||||
from bin.config import CONFIG_PATH, config
|
from mytoolkit.config import CONFIG_PATH, config
|
||||||
|
|
||||||
|
|
||||||
@click.group(name="env")
|
@click.group(name="env")
|
||||||
@@ -7,7 +7,7 @@ import sys
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from bin.config import config
|
from mytoolkit.config import config
|
||||||
|
|
||||||
|
|
||||||
def _get_proxies() -> dict[str, str]:
|
def _get_proxies() -> dict[str, str]:
|
||||||
@@ -5,9 +5,9 @@ from pathlib import Path
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from bin.api.image import _RATIO_MAP, generate_image
|
from mytoolkit.api.image import _RATIO_MAP, generate_image
|
||||||
from bin.config import config
|
from mytoolkit.config import config
|
||||||
from bin.utils import handle_errors, run_command
|
from mytoolkit.utils import handle_errors, run_command
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
@@ -5,7 +5,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from bin.utils import handle_errors, run_command
|
from mytoolkit.utils import handle_errors, run_command
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
@@ -19,7 +19,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from bin.utils import handle_errors
|
from mytoolkit.utils import handle_errors
|
||||||
|
|
||||||
_HOME = Path(os.environ.get("MYTOOLKIT_HOME", Path.home() / ".mytoolkit"))
|
_HOME = Path(os.environ.get("MYTOOLKIT_HOME", Path.home() / ".mytoolkit"))
|
||||||
CONFIG_PATH = _HOME / "mail.json"
|
CONFIG_PATH = _HOME / "mail.json"
|
||||||
@@ -5,7 +5,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from bin.md_to_pdf import build_pdf
|
from mytoolkit.md_to_pdf import build_pdf
|
||||||
|
|
||||||
|
|
||||||
_CV_DIR = (
|
_CV_DIR = (
|
||||||
@@ -8,8 +8,8 @@ import click
|
|||||||
from pypdf import PdfReader, PdfWriter
|
from pypdf import PdfReader, PdfWriter
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from bin.md_to_pdf import expand_bookmarks
|
from mytoolkit.md_to_pdf import expand_bookmarks
|
||||||
from bin.utils import handle_errors, run_command
|
from mytoolkit.utils import handle_errors, run_command
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
@@ -5,8 +5,8 @@ from pathlib import Path
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from bin.config import config
|
from mytoolkit.config import config
|
||||||
from bin.utils import handle_errors
|
from mytoolkit.utils import handle_errors
|
||||||
|
|
||||||
|
|
||||||
def _get_hosts() -> dict:
|
def _get_hosts() -> dict:
|
||||||
@@ -4,7 +4,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from bin import templates_registry
|
from mytoolkit import templates_registry
|
||||||
|
|
||||||
|
|
||||||
@click.group(name="templates")
|
@click.group(name="templates")
|
||||||
@@ -5,7 +5,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from bin.utils import handle_errors, run_command
|
from mytoolkit.utils import handle_errors, run_command
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
@@ -5,9 +5,9 @@ from pathlib import Path
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from bin.api.voice import synthesize_tts
|
from mytoolkit.api.voice import synthesize_tts
|
||||||
from bin.config import config
|
from mytoolkit.config import config
|
||||||
from bin.utils import handle_errors
|
from mytoolkit.utils import handle_errors
|
||||||
|
|
||||||
_VOICE_CHOICES = [
|
_VOICE_CHOICES = [
|
||||||
"zh_female_cancan_mars_bigtts",
|
"zh_female_cancan_mars_bigtts",
|
||||||
@@ -13,7 +13,7 @@ import time
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from bin.commands.server import (
|
from mytoolkit.commands.server import (
|
||||||
manageable_services,
|
manageable_services,
|
||||||
get_service,
|
get_service,
|
||||||
no_color_env,
|
no_color_env,
|
||||||
@@ -6,8 +6,8 @@ from pathlib import Path
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from bin import templates_registry
|
from mytoolkit import templates_registry
|
||||||
from bin.utils import run_command
|
from mytoolkit.utils import run_command
|
||||||
|
|
||||||
# Typst callouts exported by templates/md-to-pdf/{textbook,manual}/template.typ.
|
# 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.
|
# Keep this tuple and _extra_imports (below) in sync when adding or removing `#let` callouts.
|
||||||
+2
-2
@@ -13,10 +13,10 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
mytoolkit = "bin.cli:main"
|
mytoolkit = "mytoolkit.cli:main"
|
||||||
|
|
||||||
[tool.hatch.build.targets.wheel]
|
[tool.hatch.build.targets.wheel]
|
||||||
packages = ["bin"]
|
packages = ["mytoolkit"]
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["hatchling"]
|
requires = ["hatchling"]
|
||||||
|
|||||||
Reference in New Issue
Block a user