From 983aacbc24512dd03049e1c215f0eba8570c5c6d Mon Sep 17 00:00:00 2001 From: Steven B <51370195+sdb9696@users.noreply.github.com> Date: Thu, 4 Jul 2024 13:52:01 +0100 Subject: [PATCH] Structure cli into a package (#1038) PR with just the initial structural changes for the cli to be a package. Subsequent PR will break out `main.py` into modules. Doing it in two stages ensure that the commit history will be continuous for `cli.py` > `cli/main.py` --- devtools/parse_pcap.py | 2 +- kasa/cli/__init__.py | 1 + kasa/cli/__main__.py | 5 +++++ kasa/{cli.py => cli/main.py} | 0 kasa/tests/test_cli.py | 6 +++--- pyproject.toml | 2 +- 6 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 kasa/cli/__init__.py create mode 100644 kasa/cli/__main__.py rename kasa/{cli.py => cli/main.py} (100%) diff --git a/devtools/parse_pcap.py b/devtools/parse_pcap.py index 7a55bf54..02d3911c 100644 --- a/devtools/parse_pcap.py +++ b/devtools/parse_pcap.py @@ -8,7 +8,7 @@ import click import dpkt from dpkt.ethernet import ETH_TYPE_IP, Ethernet -from kasa.cli import echo +from kasa.cli.main import echo from kasa.xortransport import XorEncryption diff --git a/kasa/cli/__init__.py b/kasa/cli/__init__.py new file mode 100644 index 00000000..1d499165 --- /dev/null +++ b/kasa/cli/__init__.py @@ -0,0 +1 @@ +"""Package for the cli.""" diff --git a/kasa/cli/__main__.py b/kasa/cli/__main__.py new file mode 100644 index 00000000..5d4ca6a0 --- /dev/null +++ b/kasa/cli/__main__.py @@ -0,0 +1,5 @@ +"""Main module.""" + +from kasa.cli.main import cli + +cli() diff --git a/kasa/cli.py b/kasa/cli/main.py similarity index 100% rename from kasa/cli.py rename to kasa/cli/main.py diff --git a/kasa/tests/test_cli.py b/kasa/tests/test_cli.py index 06a7d37a..e6b96cd7 100644 --- a/kasa/tests/test_cli.py +++ b/kasa/tests/test_cli.py @@ -17,7 +17,7 @@ from kasa import ( Module, UnsupportedDeviceError, ) -from kasa.cli import ( +from kasa.cli.main import ( TYPE_TO_CLASS, alias, brightness, @@ -500,7 +500,7 @@ async def test_credentials(discovery_mock, mocker, runner): f"Username:{dev.credentials.username} Password:{dev.credentials.password}" ) - mocker.patch("kasa.cli.state", new=_state) + mocker.patch("kasa.cli.main.state", new=_state) dr = DiscoveryResult(**discovery_mock.discovery_data["result"]) res = await runner.invoke( @@ -746,7 +746,7 @@ async def test_type_param(device_type, mocker, runner): nonlocal result_device result_device = dev - mocker.patch("kasa.cli.state", new=_state) + mocker.patch("kasa.cli.main.state", new=_state) expected_type = TYPE_TO_CLASS[device_type] mocker.patch.object(expected_type, "update") res = await runner.invoke( diff --git a/pyproject.toml b/pyproject.toml index 45350aef..bfa04477 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,7 +18,7 @@ include = [ "Documentation" = "https://python-kasa.readthedocs.io" [tool.poetry.scripts] -kasa = "kasa.cli:cli" +kasa = "kasa.cli:__main__" [tool.poetry.dependencies] python = "^3.9"