From d8f2e03d36d80ad5acfc5068b20866a66187202f Mon Sep 17 00:00:00 2001 From: Abel Luck Date: Mon, 30 Mar 2026 15:23:34 +0200 Subject: [PATCH] be consistent with env var names --- README.md | 2 +- repub/entrypoint.py | 6 +++--- tests/test_entrypoint.py | 31 ++++++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ec2a848..706b052 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ uv sync --all-groups uv run repub ``` -By default the UI listens on `127.0.0.1:8080`. You can override that with `REPUB_HOST` and `REPUB_PORT`, or with: +By default the UI listens on `127.0.0.1:8080`. You can override that with `REPUBLISHER_HOST` and `REPUBLISHER_PORT`, or with: ```sh uv run repub serve --host 0.0.0.0 --port 8080 diff --git a/repub/entrypoint.py b/repub/entrypoint.py index d0de180..12ce84c 100644 --- a/repub/entrypoint.py +++ b/repub/entrypoint.py @@ -34,12 +34,12 @@ def parse_args(argv: list[str] | None = None) -> tuple[str, argparse.Namespace]: serve_parser = subparsers.add_parser("serve", help="Start the republisher web UI") serve_parser.add_argument( "--host", - default=os.environ.get("REPUB_HOST", "127.0.0.1"), + default=os.environ.get("REPUBLISHER_HOST", "127.0.0.1"), help="Host interface for the web UI", ) serve_parser.add_argument( "--port", - default=os.environ.get("REPUB_PORT", "8080"), + default=os.environ.get("REPUBLISHER_PORT", "8080"), help="Port for the web UI", ) @@ -72,7 +72,7 @@ def entrypoint(argv: list[str] | None = None) -> int: try: port = int(args.port) except ValueError: - logger.error("Invalid REPUB_PORT/--port value: %s", args.port) + logger.error("Invalid REPUBLISHER_PORT/--port value: %s", args.port) return 2 app = create_app() diff --git a/tests/test_entrypoint.py b/tests/test_entrypoint.py index 50eb470..7d3454b 100644 --- a/tests/test_entrypoint.py +++ b/tests/test_entrypoint.py @@ -1,6 +1,7 @@ +import io from types import SimpleNamespace -from repub.entrypoint import FeedNameFilter +from repub.entrypoint import FeedNameFilter, entrypoint, logger, parse_args def test_feed_name_filter_accepts_matching_item() -> None: @@ -15,3 +16,31 @@ def test_feed_name_filter_rejects_non_matching_item() -> None: feed_filter = FeedNameFilter({"feed_name": "nasa"}) assert feed_filter.accepts(item) is False + + +def test_parse_args_uses_republisher_host_and_port_env_vars(monkeypatch) -> None: + monkeypatch.setenv("REPUBLISHER_HOST", "0.0.0.0") + monkeypatch.setenv("REPUBLISHER_PORT", "9090") + + command, args = parse_args(["serve"]) + + assert command == "serve" + assert args.host == "0.0.0.0" + assert args.port == "9090" + + +def test_entrypoint_rejects_invalid_republisher_port(monkeypatch) -> None: + monkeypatch.setenv("REPUBLISHER_PORT", "not-a-number") + stream = io.StringIO() + original_streams = [handler.stream for handler in logger.handlers] + for handler in logger.handlers: + handler.stream = stream + + try: + exit_code = entrypoint(["serve"]) + finally: + for handler, original_stream in zip(logger.handlers, original_streams): + handler.stream = original_stream + + assert exit_code == 2 + assert "Invalid REPUBLISHER_PORT/--port value" in stream.getvalue()