From a4e1284a54326d72707144f74a658d1c63392e84 Mon Sep 17 00:00:00 2001 From: Artur Mukhamadiev Date: Sun, 12 Jul 2026 23:06:54 +0300 Subject: [PATCH] [packaging] convert to installable executable package - rename src/ts-example -> src/ts_example (valid import identifier) - switch intra-package imports to relative form - add hatchling build-system, [project.scripts] entry point (ts-example), and src-layout wheel config to pyproject.toml - move runtime deps (rich, textual, textual-autocomplete) into pyproject - update README: pip install -e ., launch via ts-example or python -m ts_example --- README.md | 21 ++++++++++++++----- pyproject.toml | 15 +++++++++++++ src/{ts-example => ts_example}/__init__.py | 0 src/{ts-example => ts_example}/__main__.py | 8 +++---- src/{ts-example => ts_example}/arg_conf.py | 0 .../command_runner.py | 0 src/{ts-example => ts_example}/log_conf.py | 0 src/{ts-example => ts_example}/ts_minimal.py | 6 +++--- src/{ts-example => ts_example}/tui.py | 4 ++-- 9 files changed, 40 insertions(+), 14 deletions(-) rename src/{ts-example => ts_example}/__init__.py (100%) rename src/{ts-example => ts_example}/__main__.py (91%) rename src/{ts-example => ts_example}/arg_conf.py (100%) rename src/{ts-example => ts_example}/command_runner.py (100%) rename src/{ts-example => ts_example}/log_conf.py (100%) rename src/{ts-example => ts_example}/ts_minimal.py (98%) rename src/{ts-example => ts_example}/tui.py (99%) diff --git a/README.md b/README.md index 0e66071..9794053 100644 --- a/README.md +++ b/README.md @@ -5,23 +5,34 @@ ```bash $ python3 -m venv .venv $ source .venv/bin/activate -$ pip install -r requirements.txt +$ pip install -e . ``` +The `-e` flag installs the package in editable mode, so edits under `src/` +are picked up without reinstalling. The install also creates a `ts-example` +command on your PATH (see `pyproject.toml` -> `[project.scripts]`). + ## Launch +Once installed, run the package via its console script: + ```bash -$ source .venv/bin/activate -$ python3 src/ts-example +$ ts-example minimal --file path/to/file.py +``` + +or equivalently as a module: + +```bash +$ python3 -m ts_example minimal --file path/to/file.py ``` ## TUI usage Start the TUI (the required `--file` argument can be the file you intend to -inspect): +inspect). Global options such as `--tui` must come *before* the subcommand: ```bash -$ python3 src/ts-example --tui minimal --file path/to/file.py +$ ts-example --tui minimal --file path/to/file.py ``` At the prompt, load a file and then inspect grammar fields: diff --git a/pyproject.toml b/pyproject.toml index ca74039..b87f62a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,7 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + [project] name = "ts-example" version = "0.0.1" @@ -7,4 +11,15 @@ dependencies = [ "tree-sitter>=0.26.0", "tree-sitter-cpp==0.23.4", "tree-sitter-python==0.25.0", + "rich>=15.0.0", + "textual>=8.2.8", + "textual-autocomplete>=4.0.6", ] + +# Install a `ts-example` command on PATH that calls ts_example.__main__:main. +[project.scripts] +ts-example = "ts_example.__main__:main" + +# The import package lives under src/ (src-layout). +[tool.hatch.build.targets.wheel] +packages = ["src/ts_example"] \ No newline at end of file diff --git a/src/ts-example/__init__.py b/src/ts_example/__init__.py similarity index 100% rename from src/ts-example/__init__.py rename to src/ts_example/__init__.py diff --git a/src/ts-example/__main__.py b/src/ts_example/__main__.py similarity index 91% rename from src/ts-example/__main__.py rename to src/ts_example/__main__.py index df39fe9..4472515 100644 --- a/src/ts-example/__main__.py +++ b/src/ts_example/__main__.py @@ -1,10 +1,10 @@ import logging from typing import Optional -import ts_minimal as tsmin -import tui -from arg_conf import parser, setup_parser -from log_conf import logger, logger_setup +from . import ts_minimal as tsmin +from . import tui +from .arg_conf import parser, setup_parser +from .log_conf import logger, logger_setup def parse_severity(severity: str): diff --git a/src/ts-example/arg_conf.py b/src/ts_example/arg_conf.py similarity index 100% rename from src/ts-example/arg_conf.py rename to src/ts_example/arg_conf.py diff --git a/src/ts-example/command_runner.py b/src/ts_example/command_runner.py similarity index 100% rename from src/ts-example/command_runner.py rename to src/ts_example/command_runner.py diff --git a/src/ts-example/log_conf.py b/src/ts_example/log_conf.py similarity index 100% rename from src/ts-example/log_conf.py rename to src/ts_example/log_conf.py diff --git a/src/ts-example/ts_minimal.py b/src/ts_example/ts_minimal.py similarity index 98% rename from src/ts-example/ts_minimal.py rename to src/ts_example/ts_minimal.py index e43a362..0d41073 100644 --- a/src/ts-example/ts_minimal.py +++ b/src/ts_example/ts_minimal.py @@ -3,9 +3,9 @@ from typing import Any import tree_sitter_cpp as tscpp import tree_sitter_python as tspython -from arg_conf import parser as arg_parser -from command_runner import ICommandRunner -from log_conf import logger +from .arg_conf import parser as arg_parser +from .command_runner import ICommandRunner +from .log_conf import logger from tree_sitter import Language, Parser, Query, QueryCursor, Tree PY_LANGUAGE = Language(tspython.language()) diff --git a/src/ts-example/tui.py b/src/ts_example/tui.py similarity index 99% rename from src/ts-example/tui.py rename to src/ts_example/tui.py index 5b02d57..54e1726 100644 --- a/src/ts-example/tui.py +++ b/src/ts_example/tui.py @@ -3,8 +3,8 @@ import os from pathlib import Path from typing import Any -from command_runner import ICommandRunner -from log_conf import logger +from .command_runner import ICommandRunner +from .log_conf import logger from textual import on from textual.app import App, ComposeResult from textual.geometry import Offset, Region, Spacing