From 59a6d3b326f7c102c92319a9cd5d756878391f79 Mon Sep 17 00:00:00 2001 From: Richard Baltrusch Date: Sat, 22 Jun 2024 14:38:00 +0200 Subject: [PATCH 1/3] Add pip install bach_generator workflow --- .github/workflows/pip-test.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/pip-test.yml diff --git a/.github/workflows/pip-test.yml b/.github/workflows/pip-test.yml new file mode 100644 index 0000000..c1aedf9 --- /dev/null +++ b/.github/workflows/pip-test.yml @@ -0,0 +1,24 @@ +name: Check pip install + +on: [push] + +env: + PACKAGE_NAME: bach_generator + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" + - name: Install $PACKAGE_NAME + run: | + python -m pip install --upgrade pip + pip install $PACKAGE_NAME + python -m $PACKAGE_NAME -h From cacba9e22384b4b541b55e92f5520ddb06b5cb9b Mon Sep 17 00:00:00 2001 From: Richard Baltrusch Date: Sat, 22 Jun 2024 14:45:46 +0200 Subject: [PATCH 2/3] Remove automatic gui construction in cli mode --- bach_generator/__main__.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/bach_generator/__main__.py b/bach_generator/__main__.py index 9d68696..3fdb840 100644 --- a/bach_generator/__main__.py +++ b/bach_generator/__main__.py @@ -8,7 +8,6 @@ from typing import Callable, List, Type from bach_generator import cli, runner -from bach_generator.gui import app, init from bach_generator.src import manager, model, music_handler @@ -106,7 +105,7 @@ def run_simulation(args): logging.info("Saved models to file") -def run_gui(): +def run_gui(app, init): """Runs the graphical interface""" init.init() app.data["setup_function"] = setup_simulation @@ -121,20 +120,35 @@ def run_gui(): class StreamHandler(logging.StreamHandler): + """Logging stream handler for gui mode""" + + def __init__(self, gui_app): + super().__init__() + self.app = gui_app + def emit(self, record: logging.LogRecord) -> None: - if not app.destroyed: - app.data["message"].set("Status: " + record.getMessage()) + if not self.app.destroyed: + self.app.data["message"].set("Status: " + record.getMessage()) super().emit(record) def main(): """Main function""" + gui_mode = len(sys.argv) == 1 + if gui_mode: + from bach_generator.gui import ( # pylint: disable=import-outside-toplevel + app, + init, + ) + logging.basicConfig( - level=logging.INFO, format="%(asctime)s %(message)s", handlers=[StreamHandler()] + level=logging.INFO, + format="%(asctime)s %(message)s", + handlers=[StreamHandler(app if gui_mode else None)], ) parser = cli.construct_parser() - if len(sys.argv) == 1: - run_gui() + if gui_mode: + run_gui(app, init) return args = parser.parse_args() cli.display_args(args) From 9346adb9a2af7a55b578f96bb68c04aad55ac86a Mon Sep 17 00:00:00 2001 From: Richard Baltrusch Date: Sat, 22 Jun 2024 14:47:14 +0200 Subject: [PATCH 3/3] Fix workflow step name --- .github/workflows/pip-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pip-test.yml b/.github/workflows/pip-test.yml index c1aedf9..cc38ffe 100644 --- a/.github/workflows/pip-test.yml +++ b/.github/workflows/pip-test.yml @@ -17,7 +17,7 @@ jobs: uses: actions/setup-python@v5 with: python-version: "3.x" - - name: Install $PACKAGE_NAME + - name: Install pypi package run: | python -m pip install --upgrade pip pip install $PACKAGE_NAME