Skip to content

Commit a644039

Browse files
authored
Refactor python module
Refactor python module
2 parents 20cb4db + 1dfd607 commit a644039

File tree

28 files changed

+188
-135
lines changed

28 files changed

+188
-135
lines changed

.github/workflows/pythonapp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
python -m pytest
4444
- name: Run App
4545
run: |
46-
PARAMETERS=./defaults/cypress.cfg streamlit run src/app.py &
46+
PARAMETERS=./defaults/cypress.cfg streamlit run st_app.py &
4747
- name: Cypress
4848
uses: cypress-io/github-action@v1
4949
with:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ COPY defaults defaults
99
COPY src src
1010
RUN pip install -q .
1111

12-
CMD ["streamlit", "run", "src/app.py"]
12+
CMD ["streamlit", "run", "st_app.py"]
1313

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: PARAMETERS=defaults/webapp.cfg STREAMLIT_SERVER_PORT=$PORT streamlit run src/app.py
1+
web: PARAMETERS=defaults/webapp.cfg STREAMLIT_SERVER_PORT=$PORT streamlit run st_app.py

docs/contributing/app-dev.md

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,27 @@
1212

1313
The application is built with [Streamlit](https://www.streamlit.io/), Streamlit requires:
1414

15-
- Python 2.7.0 or later / Python 3.6.x or later
15+
- Python 3.6.x or later
1616
- PIP
1717

1818
See [Streamlit's Getting Started guide](https://docs.streamlit.io/getting_started.html) for detailed information on prerequisites and setup
1919

2020
## Running CHIME Locally
2121

22+
23+
### With `venv`
24+
25+
```bash
26+
python3 -m venv ~.venv
27+
. ~.venv/bin/activate
28+
pip install -e .
29+
```
30+
2231
### With `pipenv`
2332

2433
```bash
2534
pipenv shell
2635
pipenv sync --dev
27-
PARAMETERS=defaults/webapp.cfg streamlit run src/app.py
2836
```
2937

3038
### With `conda`
@@ -33,32 +41,60 @@ PARAMETERS=defaults/webapp.cfg streamlit run src/app.py
3341
conda env create -f environment.yml
3442
source activate chime
3543
pip install streamlit
36-
PARAMETERS=defaults/webapp.cfg streamlit run src/app.py
3744
```
3845

46+
## Run the Streamlit Web App
47+
48+
```bash
49+
PARAMETERS=-./defaults/webapp.cfg streamlit run st_app.py
50+
```
51+
52+
## Run the Command Line Interface
53+
54+
```bash
55+
PARAMETERS=./defaults/cli.cfg penn_chime
56+
```
57+
58+
## Help with the Command Line Interface
59+
60+
```bash
61+
penn_chime --help
62+
```
63+
64+
### Choosing a Different Set of Parameters
65+
66+
If you want a different set of default parameters, you may use your own configuration file.
67+
68+
```bash
69+
PARAMETERS=./defaults/yours.cfg streamlit run st_app.py
70+
```
71+
72+
Be sure to include `--current-date` in the file, if your `--current-hospitalized` is not today's value.
73+
Be sure to include `--mitigation-date` in the file if social distancing was implemented before today.
74+
3975
### Choosing a Different Port
4076

41-
If you need to run the application on a different port than the default (8000), you can export a variable in your shell session to override it with any port number of your choice before running:
77+
If you need to run the application on a different port than the default (8000), you can set an environment variable.
4278

4379
```bash
44-
STREAMLIT_SERVER_PORT=1234 PARAMETERS=defaults/webapp.cfg streamlit run src/app.py
80+
STREAMLIT_SERVER_PORT=1234 PARAMETERS=./defaults/webapp.cfg streamlit run st_app.py
4581
```
4682

4783
## Project Layout
4884

4985
### Application files
5086

51-
- `src/app.py`: Main source for the application
52-
- `src/test_app.py`: [pytest](https://docs.pytest.org/en/latest/) tests for `app.py`
87+
- `st_app.py`: Startup script for the streamlit web application.
88+
- `src`: Source code for the `penn_chime` module.
89+
- `tests/`: [pytest](https://docs.pytest.org/en/latest/) tests for the `penn_chime` module.
5390
- `script/`: Developer workflow scripts following [GitHub's Scripts To Rule Them All](https://github.com/github/scripts-to-rule-them-all) pattern.
5491
- `.streamlit/`: [Streamlit config options](https://docs.streamlit.io/cli.html)
5592
- `.env`: Local environment variables to use when running application, this file is copied from `.env.example` to start you out and then ignored by git
56-
- `pytest.ini`: Configuration for [pytest](https://docs.pytest.org/en/latest/)
93+
- `environment.yml`
5794
- `Pipfile`
5895
- `Pipfile.lock`
59-
- `environment.yml`
60-
- `requirements.txt`
6196
- `setup.py`
97+
- `setup.cfg`: Configuration for flake8, mypy, [pytest](https://docs.pytest.org/en/latest/)
6298

6399
### Documentation
64100

@@ -85,6 +121,11 @@ pip install pytest
85121
pytest
86122
```
87123

124+
The test code runs from the local `tests` directory. Updating code in `tests` modifies the tests.
125+
Use `pip install -e .` so that your local changes to `src` are also the module under test.
126+
For CI, use `pip install .` to test the module installed in site-packages to ensure that the installed module is packaged correctly with all of its dependencies.
127+
Do not import from src in your tests or your python code as this will appear to work locally, but break the python module.
128+
88129
## Validating CHIME
89130

90131
*No validation routine is available yet. If you have thoughts on how to add one, please contribute!*

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"pandas",
3232
"pytest",
3333
"pyyaml",
34-
"selenium",
3534
"streamlit",
3635
"gspread",
3736
"oauth2client"

src/app.py

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/chime_dash/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import TypeVar
99

1010
from dash import Dash
11-
from penn_chime.parameters import Parameters
11+
from penn_chime.model.parameters import Parameters
1212

1313
from chime_dash.app.config import from_object
1414
from chime_dash.app.pages.root import Root

src/chime_dash/app/components/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from dash.development.base_component import ComponentMeta
1212
from dash_html_components import Div
1313

14-
from penn_chime.parameters import Parameters
14+
from penn_chime.model.parameters import Parameters
1515

1616
from chime_dash.app.utils.templates import read_localization_yml, read_localization_markdown
1717

src/chime_dash/app/components/navbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from chime_dash.app.components.base import Component
1111
from chime_dash.app.components.menu import Menu
1212

13-
from penn_chime.parameters import Parameters
13+
from penn_chime.model.parameters import Parameters
1414

1515

1616
class Navbar(Component):

src/chime_dash/app/services/callbacks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
prepare_visualization_group
1313
)
1414

15-
from penn_chime.models import SimSirModel
16-
from penn_chime.parameters import Parameters, Disposition
15+
from penn_chime.model.sir import Sir
16+
from penn_chime.model.parameters import Parameters, Disposition
1717

1818

1919
class ComponentCallbacks:
@@ -37,7 +37,7 @@ def handle_model_change(i, sidebar_data):
3737
viz_kwargs = {}
3838
if sidebar_data:
3939
pars = parameters_deserializer(sidebar_data["parameters"])
40-
model = SimSirModel(pars)
40+
model = Sir(pars)
4141
vis = i.components.get("visualizations", None) if i else None
4242
vis_content = vis.content if vis else None
4343

0 commit comments

Comments
 (0)