Skip to content

Commit

Permalink
Merge pull request OpenMS#39 from axelwalter/main
Browse files Browse the repository at this point in the history
Add CI
  • Loading branch information
axelwalter authored Oct 31, 2023
2 parents f8b3cfa + 6e65ed6 commit 3ffba89
Show file tree
Hide file tree
Showing 25 changed files with 469 additions and 249 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build-docker-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Docker Image CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build-full-app:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build the full Docker image
run: docker build . --file Dockerfile --tag streamlitapp:latest

build-simple-app:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build the Docker image (pyOpenMS only)
run: docker build . --file Dockerfile_simple --tag streamlitapp-simple:latest
6 changes: 5 additions & 1 deletion .github/workflows/build-windows-executable-app.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Build executable for Windows
on: [push]
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build-openms:
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Pylint

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py') --disable=C0103,C0114,C0301,C0411,W0212,W0631,W0602,W1514,W2402,E0401,E1101,F0001,R1732 --errors-only
25 changes: 25 additions & 0 deletions .github/workflows/workflow-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test workflow functions

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest
- name: Running test cases
run: |
pytest test.py
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

This is a template app for OpenMS workflows in a web application.

## Requires

Python <= 3.10

## Features

- Workspaces for user data with unique shareable IDs
Expand Down
54 changes: 38 additions & 16 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,65 @@
import streamlit as st
from src.common import *
from pathlib import Path
"""
Main page for the OpenMS Template App.
This module sets up and displays the Streamlit app for the OpenMS Template App.
It includes:
- Setting the app title.
- Displaying a description.
- Providing a download button for the Windows version of the app.
Usage:
Run this script to launch the OpenMS Template App.
Note:
- If run in local mode, the CAPTCHA control is not applied.
- If not in local mode, CAPTCHA control is applied to verify the user.
Returns:
None
"""

import sys

from src.captcha_ import *
from pathlib import Path
import streamlit as st

from src.captcha_ import captcha_control
from src.common import page_setup, save_params

params = page_setup(page="main")


def main():
"""
Display main page content.
"""
st.title("Template App")
st.markdown("## A template for an OpenMS streamlit app.")
if Path("OpenMS-App.zip").exists():
st.markdown("## Installation")
with open("OpenMS-App.zip", "rb") as file:
st.download_button(
label="Download for Windows",
data=file,
file_name="OpenMS-App.zip",
mime="archive/zip",
type="primary"
)
label="Download for Windows",
data=file,
file_name="OpenMS-App.zip",
mime="archive/zip",
type="primary",
)
save_params(params)


# Check if the script is run in local mode (e.g., "streamlit run app.py local")
if "local" in sys.argv:
# In local mode, run the main function without applying captcha
main()

# If not in local mode, assume it's hosted/online mode
else:

# WORK LIKE MULTIPAGE APP
if 'controllo' not in st.session_state or st.session_state['controllo'] == False:

if "controllo" not in st.session_state or st.session_state["controllo"] is False:
# Apply captcha control to verify the user
captcha_control()

else:
else:
# Run the main function
main()


18 changes: 12 additions & 6 deletions clean-up-workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
threshold = current_time - (86400 * 7)

# Print current time
print(f"Current Time: {datetime.utcfromtimestamp(current_time).strftime('%Y-%m-%d %H:%M:%S UTC')}\n")
print(
f"Current Time: {datetime.utcfromtimestamp(current_time).strftime('%Y-%m-%d %H:%M:%S UTC')}\n"
)

# Collect remaining dirctories to print out later
remaining_directories = []
Expand All @@ -25,14 +27,16 @@
if directory.is_dir():
# Get the directory's modification time
modification_time = os.path.getmtime(directory)

# Check if the modification time is less than the threshold
if modification_time < threshold:
# Calculate the time difference in seconds
time_difference = current_time - modification_time

# Print the directory name and the time difference in minutes
print(f"Deleting directory: {directory.name}, Last Modified: {time_difference / 86400:.1f} days ago")
print(
f"Deleting directory: {directory.name}, Last Modified: {time_difference / 86400:.1f} days ago"
)

# Remove workspace
shutil.rmtree(directory)
Expand All @@ -43,10 +47,12 @@
if remaining_directories:
print(f"\nRemaining directories in {workspaces_directory.name}:")
for directory in remaining_directories:
print(f"{directory.name}, Last Modified: {(current_time - os.path.getmtime(directory)) / 60:.2f} minutes ago")
print(
f"{directory.name}, Last Modified: {(current_time - os.path.getmtime(directory)) / 60:.2f} minutes ago"
)
else:
print(f"\n{workspaces_directory.name} is empty.")


# Print separator
print(100*"-")
print(100 * "-")
20 changes: 10 additions & 10 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ name: streamlit-env
channels:
- conda-forge
dependencies:
- python=3.10
- plotly
- pip
- numpy
- pandas
- mono
- python==3.10
- plotly==5.18.0
- pip==23.3
- numpy==1.25.2
- pandas==2.1.2
- mono==6.12.0.90
- pip: # dependencies only available through pip
# streamlit dependencies
- streamlit
- streamlit-plotly-events
- streamlit-aggrid
- captcha
- streamlit==1.28.0
- streamlit-plotly-events==0.0.6
- streamlit-aggrid==0.3.4.post3
- captcha==0.5.0
11 changes: 6 additions & 5 deletions hooks/hook-streamlit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from PyInstaller.utils.hooks import copy_metadata

datas = []
datas += copy_metadata('streamlit')
datas += copy_metadata('streamlit_plotly_events')
datas += copy_metadata('pyopenms')
datas += copy_metadata('captcha')
datas += copy_metadata('pyarrow')
datas += copy_metadata("streamlit")
datas += copy_metadata("streamlit_plotly_events")
datas += copy_metadata("pyopenms")
datas += copy_metadata("captcha")
datas += copy_metadata("pyarrow")
44 changes: 24 additions & 20 deletions pages/0_📁_File_Upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import streamlit as st
import pandas as pd

from src.common import *
from src.fileupload import *
from src.captcha_ import *
from src.captcha_ import captcha_control
from src.common import page_setup, save_params, v_space, show_table
from src import fileupload

params = page_setup()

# If run in hosted mode, show captcha as long as it has not been solved
if 'controllo' not in st.session_state or params["controllo"] == False:
if "controllo" not in st.session_state or params["controllo"] is False:
# Apply captcha by calling the captcha_control function
captcha_control()

Expand All @@ -25,11 +25,12 @@
with tabs[0]:
with st.form("mzML-upload", clear_on_submit=True):
files = st.file_uploader(
"mzML files", accept_multiple_files=(st.session_state.location == "local"))
"mzML files", accept_multiple_files=(st.session_state.location == "local")
)
cols = st.columns(3)
if cols[1].form_submit_button("Add files to workspace", type="primary"):
if files:
save_uploaded_mzML(files)
fileupload.save_uploaded_mzML(files)
else:
st.warning("Select files first.")

Expand All @@ -38,42 +39,45 @@
st.markdown("Short information text on example data.")
cols = st.columns(3)
if cols[1].button("Load Example Data", type="primary"):
load_example_mzML_files()
fileupload.load_example_mzML_files()

# Local file upload option: via directory path
if st.session_state.location == "local":
with tabs[2]:
# with st.form("local-file-upload"):
local_mzML_dir = st.text_input(
"path to folder with mzML files")
local_mzML_dir = st.text_input("path to folder with mzML files")
# raw string for file paths
local_mzML_dir = r"{}".format(local_mzML_dir)
local_mzML_dir = rf"{local_mzML_dir}"
cols = st.columns(3)
if cols[1].button("Copy files to workspace", type="primary", disabled=(local_mzML_dir == "")):
copy_local_mzML_files_from_directory(local_mzML_dir)
if cols[1].button(
"Copy files to workspace", type="primary", disabled=(local_mzML_dir == "")
):
fileupload.copy_local_mzML_files_from_directory(local_mzML_dir)

mzML_dir = Path(st.session_state.workspace, "mzML-files")
if any(Path(mzML_dir).iterdir()):
v_space(2)
# Display all mzML files currently in workspace
df = pd.DataFrame(
{"file name": [f.name for f in Path(mzML_dir).iterdir()]})
df = pd.DataFrame({"file name": [f.name for f in Path(mzML_dir).iterdir()]})
st.markdown("##### mzML files in current workspace:")
show_table(df)
v_space(1)
# Remove files
with st.expander("🗑️ Remove mzML files"):
to_remove = st.multiselect("select mzML files",
options=[f.stem for f in sorted(mzML_dir.iterdir())])
to_remove = st.multiselect(
"select mzML files", options=[f.stem for f in sorted(mzML_dir.iterdir())]
)
c1, c2 = st.columns(2)
if c2.button("Remove **selected**", type="primary", disabled=not any(to_remove)):
params = remove_selected_mzML_files(to_remove, params)
if c2.button(
"Remove **selected**", type="primary", disabled=not any(to_remove)
):
params = fileupload.remove_selected_mzML_files(to_remove, params)
save_params(params)
st.rerun()

if c1.button("⚠️ Remove **all**", disabled=not any(mzML_dir.iterdir())):
params = remove_all_mzML_files(params)
params = fileupload.remove_all_mzML_files(params)
save_params(params)
st.rerun()

save_params(params)
save_params(params)
Loading

0 comments on commit 3ffba89

Please sign in to comment.