Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pip workflow #57

Merged
merged 3 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/pip-test.yml
Original file line number Diff line number Diff line change
@@ -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 pypi package
run: |
python -m pip install --upgrade pip
pip install $PACKAGE_NAME
python -m $PACKAGE_NAME -h
28 changes: 21 additions & 7 deletions bach_generator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down