Skip to content

Commit

Permalink
Merge pull request #1 from MichaelPesce/initial-cleanup
Browse files Browse the repository at this point in the history
Adapt repo to be project agnostic
  • Loading branch information
MichaelPesce authored Dec 12, 2024
2 parents 9fb3625 + 0fe8e3c commit ab92db5
Show file tree
Hide file tree
Showing 27 changed files with 192 additions and 515 deletions.
50 changes: 22 additions & 28 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- uses: conda-incubator/setup-miniconda@v3
with:
environment-file: environment.yml
activate-environment: watertap-ui-env
activate-environment: flowsheet-processor-env
miniforge-version: latest

- name: Set up debug logging
Expand All @@ -46,40 +46,35 @@ jobs:
echo "ACTIONS_STEP_DEBUG=true" >> $GITHUB_ENV
- name: Add theme to .env file
working-directory: ./electron/ui
working-directory: ./frontend
run: |
echo REACT_APP_THEME=watertap >> .env
# - name: Install Electron JS dependencies
# run: |
# npm --prefix electron clean-install

- name: Install frontend JS dependencies
run: |
npm --prefix electron/ui clean-install
npm --prefix frontend clean-install
- name: get idaes extensions
run: idaes get-extensions

- name: Install watertap-ui Python package
- name: Install Python package
run: |
pip install --progress-bar off .
- name: Install WaterTAP for testing purposes
run: pip install watertap@git+https://github.com/watertap-org/watertap@main

- name: Display installed environment
run: |
conda env export --no-builds
- name: get idaes extensions
run: idaes get-extensions

- name: run backend server
run: uvicorn --app-dir backend/app main:app --reload --host 127.0.0.1 --port 8001 & sleep 30
run: uvicorn --app-dir backend/src/idaes_flowsheet_processor_ui main:app --reload --host 127.0.0.1 --port 8001 & sleep 30

- name: run frontend
run: npm --prefix electron/ui start & sleep 30
run: npm --prefix frontend start & sleep 30

- name: run component tests
run: npm --prefix electron/ui run test
run: npm --prefix frontend run test

- name: Cypress e2e tests
working-directory: electron/ui
working-directory: frontend
timeout-minutes: 45
run: npx cypress run

Expand Down Expand Up @@ -127,8 +122,8 @@ jobs:
with:
name: cypress_results-${{ matrix.os }}
path: |
electron/ui/cypress/screenshots/
electron/ui/cypress/videos/
frontend/cypress/screenshots/
frontend/cypress/videos/
## post-run conda often fails for weird reasons. this is a potential solution
## see https://github.com/conda-incubator/setup-miniconda/issues/277#issuecomment-1431458277
Expand Down Expand Up @@ -162,25 +157,24 @@ jobs:
- uses: conda-incubator/setup-miniconda@v3
with:
environment-file: environment.yml
activate-environment: watertap-ui-env
activate-environment: flowsheet-processor-env
miniforge-version: latest

# Set project as environment variable. This can also be set by the frontend.
- name: Set env
run: echo "project=nawi" >> $GITHUB_ENV

- name: Install watertap-ui Python package
- name: Install Python package
run: |
pip install --progress-bar off .
pip install --progress-bar off .[testing]
- name: Install httpx
run: |
pip install httpx
- name: Install WaterTAP for testing purposes
run: pip install watertap@git+https://github.com/watertap-org/watertap@main

- name: get idaes extensions
run: idaes get-extensions

- name: Run pytest
working-directory: backend
working-directory: backend/src/idaes_flowsheet_processor_ui
run: |
pytest tests -v
pytest . -v
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,5 @@ idaes-extensions/
get-idaes-extensions-dist/
cert/
extensions/
setup-extensions-dist/
sweep_outputs/
math.nist.gov/
130 changes: 19 additions & 111 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# watertap-ui
# idaes-flowsheet-processor-ui

This repository is for work on the user interface (UI) for the WaterTAP library.
This repository is for work on the user interface (UI) for the IDAES Flowsheet Processor.
The UI installer can be downloaded from our homepage at: https://watertap-org.github.io/

## Getting started (developer)
Expand All @@ -10,30 +10,26 @@ The UI installer can be downloaded from our homepage at: https://watertap-org.gi
The following steps assume that:

1. `conda` is already installed and configured
2. This repository (i.e. the WaterTAP UI repository, https://github.com/watertap-org/watertap-ui) has been cloned locally and the working directory is set to the root of the repository
2. This repository (i.e. https://github.com/watertap-org/idaes-flowsheet-processor-ui) has been cloned locally and the working directory is set to the root of the repository

## Installation

### 1. Creating the Conda environment

Run the following command to create and activate a new Conda environment named `watertap-ui-env`:
Run the following command to create and activate a new Conda environment named `flowsheet-processor-env`:

```sh
conda env create --file environment.yml && conda activate watertap-ui-env
conda env create --file environment.yml && conda activate flowsheet-processor-env
```

This will install the correct runtime versions of both the backend (Python) and frontend (JavaScript/NodeJS/Electron) portions of the UI, as well as the backend (Python) dependencies.
This will install the correct runtime versions of both the backend (Python) and frontend (NodeJS) portions of the UI, as well as the backend (Python) dependencies.

### 2. Install the JavaScript dependencies

Run the following commands to install the JavaScript dependencies:
Run the following command to install the JavaScript dependencies:

```sh
npm --prefix electron clean-install
```

```sh
npm --prefix electron/ui clean-install
npm --prefix frontend clean-install
```

### 3. Install the IDAES solver dependencies
Expand All @@ -42,75 +38,32 @@ npm --prefix electron/ui clean-install
idaes get-extensions --verbose
```

### 4. (Optional) Install the developer version of WaterTAP

By default, Step 1 above will install the `watertap` Python package from the current `main` branch of the watertap-org/watertap repository.

To use the WaterTAP UI with the development version of WaterTAP, run the following steps:

#### 4.0. (Optional) Clone the `watertap-org/watertap` repository locally

If you already have a local clone of the WaterTAP repository, you can skip this step.

Otherwise, run the following command to create a local clone of the WaterTAP repository in a directory of your choice, e.g. `/path/to/my/watertap`:

```sh
git clone https://github.com/watertap-org/ /path/to/my/watertap
```

#### 4.1. Ensure that the `watertap-ui-env` Conda environment is active

```sh
conda activate watertap-ui-env
```

#### 4.2. Uninstall the currently installed version of WaterTAP

```sh
pip uninstall --yes watertap
```

#### 4.3. Install the development version of WaterTAP

The following assumes that the `watertap-org/watertap` repository has been cloned to a directory named `/path/to/my/watertap`.

```sh
bash -c "cd /path/to/my/watertap && pip install -r requirements-dev.txt"
```

# Running the UI

### Ensure that the `watertap-ui-env` Conda environment is active and all dependencies are installed
### Ensure that the `flowsheet-processor-env` Conda environment is active and all dependencies are installed

```console
conda activate watertap-ui-env
conda activate flowsheet-processor-env
```

### Run UI in browser

```console
cd <watertap-ui-path>/electron/ui
cd <idaes-flowsheet-processor-ui-path>/frontend
npm run app-start
```

### Run UI with electron

```console
cd <watertap-ui-path>/electron/ui
npm run electron-start
```

# Running developer tests

There are three sets of tests that can be run: Python tests, JavaScript unit tests, and JavaScript end-to-end tests.

## Running Python tests

To run the Python tests, make sure you have the appropriate version of watertap in your conda env. Then from the repository root directory run:
From the repository root directory run:

To run:
```shell
cd backend
cd backend/src/idaes_flowsheet_processor_ui
pytest
```

Expand All @@ -122,7 +75,7 @@ The unit tests are written using the [testing-library](https://testing-library.c

To run:
```shell
cd electron/ui
cd frontend
npm run test
```

Expand All @@ -132,61 +85,16 @@ Hit 'a' for "run all tests" if you want to run tests regardless of what changed.

The end-to-end tests are written in Cypress.

Before running the tests, start the back-end server, in another process (or shell):
Before running the tests, start the app, in another process (or shell):
```shell
cd electron/ui
npm run start-backend
cd frontend
npm run app-start
```

Then, to run the tests:
```shell
cd electron/ui # if needed
cd frontend
npx cypress run
```

If there are errors, screenshots and videos can be found (in subdirectories named for each test) under `electron/ui/cypress/screenshots` and `electron/ui/cypress/videos`.

# Building production Electron app

The following steps assume that:

1. `conda` is already installed and configured
2. The WaterTAP-UI package has been succesfully installed
3. Watertap is cloned and installed locally. This is required for transferring data files (png and yaml)
4. Watertap and Watertap-ui directories must be inside of the same parent directory.
5. `watertap-ui-env` Conda environment is active

### 1. Transfer Entry points

```sh
cd <watertap-ui-path>/electron
npm --prefix electron run move-entrypoints
```

### 2. Create build distribution

### Windows:
#### Requirements:
1) Windows operating system
2) The following environment variables must be set
- CSC_LINK: "<path-to-valid-codesigning-certificate.p12>"
- CSC_KEY_PASSWORD: "<codesign-account-password>"

#### Command:
```console
cd <watertap-ui-path>/electron
npm run dist:win
```

### Mac (requires Mac OS):
#### Requirements:
1) Mac operationg system
2) Signed in to Apple developer account
3) A valid <u>Developer ID Application</u> certificate AND corresponding private key stored in keychain access

#### Command:

```console
cd <watertap-ui-path>/electron
npm run dist:mac
```
If there are errors, screenshots and videos can be found (in subdirectories named for each test) under `electron/ui/cypress/screenshots` and `electron/ui/cypress/videos`.
23 changes: 23 additions & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
aiofiles==23.2.1
anyio==3.6.1
asgiref==3.5.2
certifi==2021.10.8
click==8.1.3
fastapi==0.115.6
flexparser != 0.4
h11==0.13.0
idna==3.3
parameter-sweep==0.1.dev5
pydantic==2.6.4
pydantic-settings==2.2.1
python-multipart==0.0.5
chardet
pyyaml
requests
tinydb
sniffio==1.2.0
typing_extensions==4.9.0
uvicorn==0.32.1
importlib_resources==5.9.0 ; python_version < "3.10"
git+https://github.com/watertap-org/idaes-flowsheet-processor.git

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def _get_release_platform(platform):
# full platform name
platform = f"{platform}-{mach}"
# See if machine is supported
if platform == "windows-aarch64":
platform = "windows-x86_64"
if platform not in idaes.config.base_platforms:
raise UnsupportedPlatformError(f"Unsupported platform: {platform}.")
_log.debug(f"Downloading binaries for {platform}")
Expand Down Expand Up @@ -399,4 +401,4 @@ def download_binaries(
_log.debug(f"Extracting files in {p} to {to_path}")
with tarfile.open(p, "r") as f:
_verify_tar_member_targets(f, to_path, links)
f.extractall(to_path)
f.extractall(to_path)
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
import time
from types import ModuleType
from typing import Optional, Dict, List, Union
import app

# third-party
from fastapi import HTTPException
from pydantic import BaseModel, validator, field_validator, ValidationInfo, Field
import tinydb # JSON single-file 'database'

# package-local
from app.internal.settings import Deployment, AppSettings
from idaes_flowsheet_processor_ui.internal.settings import Deployment, AppSettings
from idaes_flowsheet_processor.api import FlowsheetInterface
import idaes.logger as idaeslog

Expand Down
Loading

0 comments on commit ab92db5

Please sign in to comment.