parqx 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
parqx/__init__.py ADDED
@@ -0,0 +1 @@
1
+ """The Parqx package."""
parqx/__main__.py ADDED
@@ -0,0 +1,5 @@
1
+ """Parqx: A Parquet TUI inspector."""
2
+
3
+ from parqx.cli import app
4
+
5
+ app(prog_name="parqx")
parqx/cli.py ADDED
@@ -0,0 +1,63 @@
1
+ """The Parqx CLI entrypoint."""
2
+
3
+ import logging
4
+ from importlib import metadata
5
+ from pathlib import Path
6
+ from typing import Annotated
7
+
8
+ import pyarrow.parquet as pq
9
+ import typer
10
+
11
+ from parqx.logger import setup_logging
12
+ from parqx.tui.app import ParqxApp
13
+
14
+ logger = logging.getLogger(__name__)
15
+
16
+ app = typer.Typer(help="Parqx: A Parquet TUI inspector.")
17
+
18
+
19
+ def version_callback(value: bool) -> None:
20
+ """Parqx version callback."""
21
+ if value:
22
+ print(f"parqx {metadata.version('parqx')}")
23
+ raise typer.Exit()
24
+
25
+
26
+ @app.command()
27
+ def main(
28
+ path: Annotated[
29
+ Path,
30
+ typer.Argument(
31
+ exists=True,
32
+ file_okay=True,
33
+ dir_okay=False,
34
+ readable=True,
35
+ help="Parquet file to inspect.",
36
+ ),
37
+ ],
38
+ verbose: Annotated[
39
+ int,
40
+ typer.Option(
41
+ "--verbose",
42
+ "-v",
43
+ count=True,
44
+ help="Enable verbose logging (or `-vv` for more verbose output).",
45
+ ),
46
+ ] = 0,
47
+ version: Annotated[
48
+ bool | None,
49
+ typer.Option(
50
+ "--version",
51
+ callback=version_callback,
52
+ is_eager=True,
53
+ help="Show the version and exit.",
54
+ ),
55
+ ] = None,
56
+ ) -> None:
57
+ """Parqx: A Parquet TUI inspector."""
58
+ _ = version
59
+
60
+ setup_logging(verbose)
61
+
62
+ table = pq.read_table(path) # type: ignore
63
+ ParqxApp(table).run()
parqx/logger.py ADDED
@@ -0,0 +1,76 @@
1
+ """The Parqx logging configuration."""
2
+
3
+ import logging
4
+ from logging.handlers import RotatingFileHandler
5
+ from pathlib import Path
6
+
7
+ from platformdirs import user_log_dir
8
+ from textual.logging import TextualHandler
9
+
10
+ _LOGGER_NAME = "parqx"
11
+ _LOG_FILE_NAME = "parqx.log"
12
+ _LOG_FILE_MAX_BYTES = 5 * 1024 * 1024 # 5 MiB
13
+ _LOG_FILE_BACKUP_COUNT = 3
14
+ _FILE_FORMAT = "%(asctime)s %(levelname)-8s %(name)s:%(lineno)d %(message)s"
15
+ _DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
16
+
17
+
18
+ def _verbosity_to_level(verbose: int) -> int:
19
+ """Map the `--verbose` count to a `logging` level."""
20
+ if verbose <= 0:
21
+ return logging.WARNING
22
+ if verbose == 1:
23
+ return logging.INFO
24
+ return logging.DEBUG
25
+
26
+
27
+ def _log_file_path() -> Path:
28
+ """Return the rotating log file path under the platform user log directory."""
29
+ log_dir = Path(user_log_dir("parqx", appauthor=False, ensure_exists=True))
30
+ return log_dir / _LOG_FILE_NAME
31
+
32
+
33
+ def setup_logging(verbose: int = 0) -> None:
34
+ r"""Configure logging for the Parqx application.
35
+
36
+ A TUI takes over the terminal, so log records must never reach `stdout` or
37
+ `stderr` while the app is running. This function installs two handlers on
38
+ the `parqx` logger:
39
+
40
+ - A `RotatingFileHandler` writing detailed records to a log file under
41
+ the platform user log directory (e.g. `%LOCALAPPDATA%\\parqx\\Logs\\parqx.log`
42
+ on Windows, `~/.local/state/parqx/log/parqx.log` on Linux).
43
+ - A `TextualHandler` so `logger.*` calls are also visible in `textual console`
44
+ during development.
45
+
46
+ Propagation to the root logger is disabled so records can't accidentally
47
+ leak to `stderr` and corrupt the TUI. The function is idempotent - calling
48
+ it again replaces the previously installed handlers.
49
+
50
+ Args:
51
+ verbose: Verbosity count from the CLI (`-v` once, `-vv` twice, ...).
52
+ 0 maps to `WARNING`, 1 to `INFO`, 2+ to `DEBUG`.
53
+ """
54
+ level = _verbosity_to_level(verbose)
55
+ log_file = _log_file_path()
56
+
57
+ logger = logging.getLogger(_LOGGER_NAME)
58
+ logger.setLevel(level)
59
+ logger.propagate = False
60
+
61
+ for existing in logger.handlers:
62
+ logger.removeHandler(existing)
63
+ existing.close()
64
+
65
+ file_handler = RotatingFileHandler(
66
+ log_file,
67
+ maxBytes=_LOG_FILE_MAX_BYTES,
68
+ backupCount=_LOG_FILE_BACKUP_COUNT,
69
+ encoding="utf-8",
70
+ delay=True,
71
+ )
72
+ file_handler.setLevel(level)
73
+ file_handler.setFormatter(logging.Formatter(_FILE_FORMAT, datefmt=_DATE_FORMAT))
74
+ logger.addHandler(file_handler)
75
+
76
+ logger.addHandler(TextualHandler())
parqx/py.typed ADDED
File without changes
parqx/tui/__init__.py ADDED
@@ -0,0 +1 @@
1
+ """The Parqx TUI package."""
parqx/tui/app.py ADDED
@@ -0,0 +1,25 @@
1
+ """The Parqx Textual App."""
2
+
3
+ from typing import Any
4
+
5
+ import pyarrow as pa
6
+ from textual.app import App, ComposeResult
7
+
8
+ from parqx.tui.widgets import ArrowTable
9
+
10
+
11
+ class ParqxApp(App[Any]):
12
+ """A Textual App for Parqx."""
13
+
14
+ def __init__(self, table: pa.Table) -> None:
15
+ """Initialize the app with an Arrow table to inspect.
16
+
17
+ Args:
18
+ table: Arrow table displayed by the main table widget.
19
+ """
20
+ super().__init__()
21
+ self._table = table
22
+
23
+ def compose(self) -> ComposeResult:
24
+ """Yield child widgets for the app."""
25
+ yield ArrowTable(self._table)
@@ -0,0 +1,5 @@
1
+ """The TUI widgets package."""
2
+
3
+ from parqx.tui.widgets.arrow_table import ArrowTable
4
+
5
+ __all__ = ["ArrowTable"]