From a2bcdcc80b890e5752430f2e2b945a95cfbb216a Mon Sep 17 00:00:00 2001 From: andrefetch Date: Mon, 16 Nov 2026 16:10:35 -0500 Subject: [PATCH] feat: fixed docker --- .github/workflows/python-publish.yml | 37 ++++++++++++++++++++++++++- .github/workflows/tests.yml | 6 ++--- .postal/config.toml | 2 +- docker/README.md | 29 ++++++++++++++++----- pyproject.toml | 1 - tests/test_repl.py | 38 ++++++++++++++++++++++++++++ ui/repl/app.py | 6 +++++ 7 files changed, 106 insertions(+), 13 deletions(-) create mode 100644 tests/test_repl.py diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 6e769e8..5244a60 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -29,8 +29,43 @@ jobs: - name: Build release distributions run: | # NOTE: put your own distribution build steps here. - python -m pip install build + python -m pip install build twine trove-classifiers python -m build + python -m twine check dist/* + + - name: Validate classifiers against PyPI's list + # PyPI rejects any unknown classifier with a 400 during upload, so + # catch typos here instead of failing the publish step. + run: | + python - <<'EOF' + import pathlib, sys, tarfile, zipfile + from trove_classifiers import classifiers + + valid = set(classifiers) + invalid = [] + for path in sorted(pathlib.Path("dist").iterdir()): + if path.suffix == ".whl": + with zipfile.ZipFile(path) as archive: + name = next(n for n in archive.namelist() if n.endswith("METADATA")) + metadata = archive.read(name).decode("utf-8", "replace") + elif path.suffixes[-2:] == [".tar", ".gz"]: + with tarfile.open(path) as archive: + member = next(m for m in archive.getmembers() if m.name.endswith("PKG-INFO")) + metadata = archive.extractfile(member).read().decode("utf-8", "replace") + else: + continue + for line in metadata.splitlines(): + if not line.startswith("Classifier: "): + continue + classifier = line.split(": ", 1)[1] + if classifier not in valid: + invalid.append(f"{classifier} (in {path.name})") + + if invalid: + print("Invalid PyPI classifiers:", *invalid, sep="\n ") + sys.exit(1) + print("All classifiers are valid.") + EOF - name: Upload distributions uses: actions/upload-artifact@v4 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5f06f9f..0b3bb46 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,9 +20,6 @@ jobs: fail-fast: false matrix: python-version: ["3.11", "3.13"] - env: - TIKTOKEN_CACHE_DIR: ${{ runner.temp }}/tiktoken - XDG_CONFIG_HOME: ${{ runner.temp }}/postal-config steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 @@ -36,6 +33,9 @@ jobs: run: python -c "import tiktoken; tiktoken.get_encoding('cl100k_base')" - name: Run Python tests run: python -m pytest tests -q + env: + TIKTOKEN_CACHE_DIR: ${{ runner.temp }}/tiktoken + XDG_CONFIG_HOME: ${{ runner.temp }}/postal-config terminal: name: TypeScript terminal diff --git a/.postal/config.toml b/.postal/config.toml index e852a47..b480109 100644 --- a/.postal/config.toml +++ b/.postal/config.toml @@ -17,7 +17,7 @@ debug = false # command='python3 ./scripts/test_tool.py' [model] -name = "baidu/ernie-5.5-flash-preview:free" +name = "deepseek/deepseek-v4.1-flash-1017" temperature = 1.0 context_window = 256000 diff --git a/docker/README.md b/docker/README.md index 201e6dd..081a574 100644 --- a/docker/README.md +++ b/docker/README.md @@ -10,36 +10,51 @@ Postal provides Docker support through a pre-built container image that includes ### Using Docker Compose -1. **Build and start the container** +Postal's interface is a full-screen terminal UI, so it needs an attached TTY. +Run it in the foreground rather than detached: ```bash cd docker -API_KEY="your_openrouter_api_key" docker-compose up -d +API_KEY="your_openrouter_api_key" docker compose run --rm postal ``` -2. **Connect to your workspace** +The service mounts your current directory (`$POSTAL_WORKSPACE:-..`) as +`/workspace` inside the container. Use `exit` (or Ctrl-C) to leave the UI; the +container is removed afterwards. -The container mounts your current directory (`$POSTAL_WORKSPACE:-..`) as `/workspace` inside the container. You can now interact with your code through Postal. +If you already started it detached with `docker compose up -d`, reattach with +`docker attach postal` — the UI is still running and waiting for input. ### Using Docker Image Directly 1. **Build the image** ```bash -docker build -t postal:dev .. +docker build -t postal:dev -f docker/Dockerfile .. ``` 2. **Run the container** +`-it` is required: without a TTY the UI cannot start. + ```bash -docker run -d \ +docker run --rm -it \ --name postal \ -v "$(pwd):/workspace" \ - -v "$(pwd)/.postal:/config" \ + -v postal-config:/config \ -e API_KEY="your_openrouter_api_key" \ postal:dev ``` +For a one-shot prompt instead of the interactive UI, no TTY is needed: + +```bash +docker run --rm \ + -v "$(pwd):/workspace" -v postal-config:/config \ + -e API_KEY="your_openrouter_api_key" \ + postal:dev "explain this codebase" +``` + ## Configuration ### Environment Variables diff --git a/pyproject.toml b/pyproject.toml index 0075e6f..e6a9123 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,6 @@ classifiers = [ "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", - "Programming Language :: TypeScript", "Topic :: Software Development", ] dependencies = [ diff --git a/tests/test_repl.py b/tests/test_repl.py new file mode 100644 index 0000000..3490b22 --- /dev/null +++ b/tests/test_repl.py @@ -0,0 +1,38 @@ +import asyncio +import unittest +from unittest.mock import patch + +from config.config import Config +from ui.repl.app import Repl + + +class ReplTerminalTests(unittest.TestCase): + def run_repl(self, isatty: bool): + with patch("ui.repl.app.sys.stdin") as stdin, patch("ui.repl.app.shutil.which") as which: + stdin.isatty.return_value = isatty + which.return_value = "/usr/bin/node" + with patch("ui.repl.app.asyncio.create_subprocess_exec") as spawn: + with self.assertRaises(RuntimeError) as raised: + asyncio.run(Repl(Config()).run()) + return raised.exception, which, spawn + + def test_missing_tty_explains_how_to_run_in_docker(self): + error, which, spawn = self.run_repl(isatty=False) + + message = str(error) + self.assertIn("needs a terminal", message) + self.assertIn("docker run -it", message) + self.assertIn("docker exec -it", message) + self.assertIn("postal \"your prompt\"", message) + which.assert_not_called() + spawn.assert_not_called() + + def test_missing_tty_does_not_require_node(self): + error, which, _ = self.run_repl(isatty=False) + + self.assertNotIn("Node.js", str(error)) + which.assert_not_called() + + +if __name__ == "__main__": + unittest.main() diff --git a/ui/repl/app.py b/ui/repl/app.py index fbea219..9599ed8 100644 --- a/ui/repl/app.py +++ b/ui/repl/app.py @@ -29,6 +29,12 @@ async def run(self) -> None: from ui.textual_app import PostalApp await PostalApp(self.config, resume=self.resume, upgrade_notice=self.upgrade_notice).run_async() return + if not sys.stdin.isatty(): + raise RuntimeError( + "The interactive TUI needs a terminal. Run `postal` from an interactive shell " + "(inside Docker use `docker run -it`, or `docker exec -it postal`), " + "or pass a prompt instead: `postal \"your prompt\"`." + ) node = shutil.which("node") if node is None: raise RuntimeError("The TypeScript TUI requires Node.js 22+. Install Node, or set POSTAL_UI=textual to use the legacy interface.")