Skip to content

Commit

Permalink
Environment variables for debug, port. Launch browser in production
Browse files Browse the repository at this point in the history
  • Loading branch information
kretep committed Dec 3, 2024
1 parent 2b31043 commit fe76aa2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ __pycache__/
build/
dist/
*.egg-info/

.env
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,25 @@
This is a GUI for the cvasl package, currently a work-in-progress.


## Installation
## Install and run

***TODO***
```bash
pip install cvasl-gui
cvasl-gui
```

## Configuration

The application will look for the following environment variables:

```bash
CVASL_DEBUG_MODE # True for development, False for production. Debug mode will show the Dash debug console on the page. In production mode, the browser will be automatically opened.
CVASL_PORT # The port the server runs on, default is 8767
```

## Run
## Development

```bash
python3 src/index.py
poetry install
poetry run cvasl-gui
```
16 changes: 15 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cvasl-gui"
version = "0.1.2"
version = "0.1.3"
description = "A GUI for the cvasl package"
authors = ["Peter Kok <[email protected]>"]
license = "Apache 2.0"
Expand All @@ -11,6 +11,7 @@ python = "^3.9"
dash = "^2.18.1"
pandas = "^2.2.3"
statsmodels = "^0.14.4"
python-dotenv = "^1.0.1"

[tool.poetry.scripts]
cvasl-gui = "cvasl_gui.index:main"
Expand Down
18 changes: 17 additions & 1 deletion src/cvasl_gui/index.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import os
import webbrowser
from threading import Timer
from dotenv import load_dotenv

from dash import html, dcc, Input, Output

from cvasl_gui import data_store
Expand Down Expand Up @@ -49,7 +54,18 @@ def display_content(selected_tab):


def main():
app.run_server(debug=True)
# Load environment variables
load_dotenv()
port = os.getenv('CVASL_PORT', 8767)
debug_mode = os.getenv('CVASL_DEBUG_MODE', False)

# Schedule a timer to open the browser
if not debug_mode: # we don't want to relaunch on every change
url = f"http://127.0.0.1:{port}/"
Timer(1, lambda: webbrowser.open(url)).start()

# Start the Dash server
app.run_server(port=port, debug=debug_mode)


if __name__ == '__main__':
Expand Down

0 comments on commit fe76aa2

Please sign in to comment.