[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
This commit is contained in:
Artur Mukhamadiev 2026-07-12 23:06:54 +03:00
parent 00ddf1ee33
commit a4e1284a54
9 changed files with 40 additions and 14 deletions

View File

@ -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:

View File

@ -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"]

View File

@ -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):

View File

@ -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())

View File

@ -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