From e335cd2c599b5d7df80dfdf8e4c16d12ebb6c2ce Mon Sep 17 00:00:00 2001 From: James Ridgway Date: Sun, 29 Aug 2021 21:55:29 +0100 Subject: [PATCH] Script/entrypoint refactor for Windows compatibility --- devdeck/{devdeck.py => deck_manager.py} | 2 +- devdeck/{logging => }/filters.py | 0 devdeck/logging/__init__.py | 0 bin/devdeck => devdeck/main.py | 14 +++++++------- setup.py | 6 +++++- .../{test_devdeck.py => test_deck_manager.py} | 12 ++++++------ 6 files changed, 19 insertions(+), 15 deletions(-) rename devdeck/{devdeck.py => deck_manager.py} (98%) rename devdeck/{logging => }/filters.py (100%) delete mode 100644 devdeck/logging/__init__.py rename bin/devdeck => devdeck/main.py (92%) rename tests/devdeck/{test_devdeck.py => test_deck_manager.py} (89%) diff --git a/devdeck/devdeck.py b/devdeck/deck_manager.py similarity index 98% rename from devdeck/devdeck.py rename to devdeck/deck_manager.py index b345940..89b1bf9 100644 --- a/devdeck/devdeck.py +++ b/devdeck/deck_manager.py @@ -3,7 +3,7 @@ from devdeck.deck_context import DeckContext -class DevDeck: +class DeckManager: def __init__(self, deck): self.__logger = logging.getLogger('devdeck') self.__deck = deck diff --git a/devdeck/logging/filters.py b/devdeck/filters.py similarity index 100% rename from devdeck/logging/filters.py rename to devdeck/filters.py diff --git a/devdeck/logging/__init__.py b/devdeck/logging/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/bin/devdeck b/devdeck/main.py similarity index 92% rename from bin/devdeck rename to devdeck/main.py index 03bff01..1d65145 100644 --- a/bin/devdeck +++ b/devdeck/main.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python3 import logging import os import sys @@ -8,12 +7,13 @@ from StreamDeck.DeviceManager import DeviceManager -from devdeck.devdeck import DevDeck -from devdeck.logging.filters import InfoFilter +from devdeck.deck_manager import DeckManager +from devdeck.filters import InfoFilter from devdeck.settings.devdeck_settings import DevDeckSettings from devdeck.settings.validation_error import ValidationError -if __name__ == "__main__": + +def main(): os.makedirs(os.path.join(str(Path.home()), '.devdeck'), exist_ok=True) root = logging.getLogger('devdeck') @@ -72,11 +72,11 @@ deck.close() continue - dev_deck = DevDeck(deck) + deck_manager = DeckManager(deck) # Instantiate deck main_deck = deck_settings.deck_class()(None, **deck_settings.settings()) - dev_deck.set_active_deck(main_deck) + deck_manager.set_active_deck(main_deck) for t in threading.enumerate(): if t is threading.currentThread(): @@ -86,5 +86,5 @@ try: t.join() except KeyboardInterrupt as ex: - dev_deck.close() + deck_manager.close() deck.close() diff --git a/setup.py b/setup.py index 1052524..74b4d90 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,11 @@ def get_version(): url='https://github.com/jamesridgway/devdeck', license='MIT', packages=find_packages(), - scripts=['bin/devdeck'], + entry_points={ + 'console_scripts': [ + 'devdeck = devdeck.main:main' + ] + }, install_requires=install_reqs, include_package_data=True ) diff --git a/tests/devdeck/test_devdeck.py b/tests/devdeck/test_deck_manager.py similarity index 89% rename from tests/devdeck/test_devdeck.py rename to tests/devdeck/test_deck_manager.py index 6c6cfd0..ab9acea 100644 --- a/tests/devdeck/test_devdeck.py +++ b/tests/devdeck/test_deck_manager.py @@ -2,14 +2,14 @@ from assertpy import assert_that -from devdeck.devdeck import DevDeck +from devdeck.deck_manager import DeckManager -class TestDevDeck: +class TestDeckManager: @mock.patch('StreamDeck.Devices.StreamDeck.StreamDeck') @mock.patch('StreamDeck.Devices.StreamDeck.StreamDeck') def test_set_active_deck(self, first_mock_deck, second_mock_deck): - dev_deck = DevDeck(first_mock_deck) + dev_deck = DeckManager(first_mock_deck) assert_that(dev_deck.get_active_deck()).is_none() @@ -25,7 +25,7 @@ def test_set_active_deck(self, first_mock_deck, second_mock_deck): @mock.patch('StreamDeck.Devices.StreamDeck.StreamDeck') @mock.patch('StreamDeck.Devices.StreamDeck.StreamDeck') def test_pop_active_deck(self, first_mock_deck, second_mock_deck): - dev_deck = DevDeck(first_mock_deck) + dev_deck = DeckManager(first_mock_deck) # Two active decks and the second is active dev_deck.set_active_deck(first_mock_deck) @@ -38,7 +38,7 @@ def test_pop_active_deck(self, first_mock_deck, second_mock_deck): @mock.patch('StreamDeck.Devices.StreamDeck.StreamDeck') def test_pop_active_deck_does_not_remove_root_deck(self, first_mock_deck): - dev_deck = DevDeck(first_mock_deck) + dev_deck = DeckManager(first_mock_deck) dev_deck.set_active_deck(first_mock_deck) assert_that(dev_deck.get_active_deck()).is_equal_to(first_mock_deck) @@ -48,7 +48,7 @@ def test_pop_active_deck_does_not_remove_root_deck(self, first_mock_deck): @mock.patch('StreamDeck.Devices.StreamDeck.StreamDeck') def test_key_callback_propogates_to_active_deck(self, first_mock_deck): - dev_deck = DevDeck(first_mock_deck) + dev_deck = DeckManager(first_mock_deck) dev_deck.set_active_deck(first_mock_deck) # Pressed