From 32e807307393d8b77a03c19f45801519b5dcfec8 Mon Sep 17 00:00:00 2001 From: Roeeeee <35409124+5c077m4n@users.noreply.github.com> Date: Fri, 31 May 2024 20:08:29 +0300 Subject: [PATCH] chore: add poetry scripts (#772) * chore: Wrap main functionality in functions * feature: Add peotry scripts * chore: Add description to main functions * chore: update main readme with running scripts via poetry --- README.md | 4 ++-- pyproject.toml | 9 +++++++-- scripts/control_device.py | 7 ++++++- scripts/discover_devices.py | 7 ++++++- scripts/get_device_login_key.py | 7 ++++++- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 32c43e01..902e06f0 100644 --- a/README.md +++ b/README.md @@ -138,8 +138,8 @@ asyncio.run(print_devices(60)) ## Command Line Helper Scripts - [discover_devices.py](https://github.com/TomerFi/aioswitcher/blob/dev/scripts/discover_devices.py) can discover devices and their - states. -- [control_device.py](https://github.com/TomerFi/aioswitcher/blob/dev/scripts/control_device.py) can control a device. + states (can be run by `poetry run discover_devices`). +- [control_device.py](https://github.com/TomerFi/aioswitcher/blob/dev/scripts/control_device.py) can control a device (can be run by `poetry run control_device`). ## Disclaimer diff --git a/pyproject.toml b/pyproject.toml index a743c5a5..fffb424f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,8 +20,8 @@ classifiers = [ include = [ ] exclude = [ ] - [tool.poetry.dependencies] - python = "^3.9.0" +[tool.poetry.dependencies] +python = "^3.9.0" [tool.poetry.group.dev.dependencies] assertpy = "^1.1" @@ -108,3 +108,8 @@ skip_covered = true [build-system] requires = [ "poetry-core>=1.2.0" ] build-backend = "poetry.core.masonry.api" + +[tool.poetry.scripts] +control_device = "scripts.control_device:main" +discover_devices = "scripts.discover_devices:main" +get_device_login_key = "scripts.get_device_login_key:main" diff --git a/scripts/control_device.py b/scripts/control_device.py index 77268ccd..d873799a 100755 --- a/scripts/control_device.py +++ b/scripts/control_device.py @@ -452,7 +452,8 @@ async def set_shutter_position( ) -if __name__ == "__main__": +def main() -> None: + """Run the device controller script.""" try: args = main_parser.parse_args() @@ -572,3 +573,7 @@ async def set_shutter_position( except KeyboardInterrupt: exit() + + +if __name__ == "__main__": + main() diff --git a/scripts/discover_devices.py b/scripts/discover_devices.py index bb320a0d..dfcc20f7 100644 --- a/scripts/discover_devices.py +++ b/scripts/discover_devices.py @@ -113,7 +113,8 @@ def on_device_found_callback(device: SwitcherBase) -> None: await asyncio.sleep(delay) -if __name__ == "__main__": +def main() -> None: + """Run the device discovery script.""" args = parser.parse_args() if args.type == "1": @@ -132,3 +133,7 @@ def on_device_found_callback(device: SwitcherBase) -> None: asyncio.run(print_devices(args.delay, ports)) except KeyboardInterrupt: exit() + + +if __name__ == "__main__": + main() diff --git a/scripts/get_device_login_key.py b/scripts/get_device_login_key.py index 9a4ac471..bd051f8f 100644 --- a/scripts/get_device_login_key.py +++ b/scripts/get_device_login_key.py @@ -78,8 +78,13 @@ def listen_udp(specific_ip: str, port: int) -> None: sock.close() -if __name__ == "__main__": +def main() -> None: + """Fetch the devices's login key.""" args = parser.parse_args() print("ip address: " + args.ip_address) print("port: " + str(args.port)) listen_udp(args.ip_address, args.port) + + +if __name__ == "__main__": + main()