Skip to content

Fix: Display WebApp Versioning #150

Merged
t0mdavid-m merged 5 commits intoOpenMS:mainfrom
asterisk-ragavan:main
Mar 6, 2025
Merged

Fix: Display WebApp Versioning #150
t0mdavid-m merged 5 commits intoOpenMS:mainfrom
asterisk-ragavan:main

Conversation

@asterisk-ragavan
Copy link
Contributor

@asterisk-ragavan asterisk-ragavan commented Mar 5, 2025

Update app name and version display from settings #140

  • Updated app.py to display the app name from settings.json.

  • Updated common.py to display the version in the web UI from settings.py.

Testing

  • checked on light theme
  • checked on dark theme
  • app name from settings visible in the UI

if key version is not present in the settings.json we will get ValueError

image
image

Summary by CodeRabbit

  • New Features
    • The application now loads its settings from an external configuration file, allowing dynamic updates to key information such as the app name.
    • The sidebar now displays the application version (1.0.2), providing clear visibility of the current release for tracking purposes.

--Updated app.py to display the app name from settings.json.
--Updated common.py to display the version in the web UI from settings.py.
@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2025

Walkthrough

The update introduces a mechanism to load configuration settings from a JSON file into the Streamlit session state. In app.py, a conditional check reads from "settings.json" if settings are missing, and the hardcoded application name is replaced with a dynamic value from the session state. The settings.json file now includes a new "version": "1.0.2" key, and additional code in the common module displays this version information in a styled container within the sidebar.

Changes

File(s) Change Summary
app.py Adds a conditional check to load settings from "settings.json" into st.session_state and replaces the hardcoded app name with a dynamic value.
settings.json Introduces a new key "version": "1.0.2" to the configuration file.
src/common/common.py Adds a UI container with styled markdown to display the version information retrieved from st.session_state.settings["version"].

Sequence Diagram(s)

sequenceDiagram
    participant App as Streamlit App
    participant SS as Session State
    participant File as "settings.json" File
    App->>SS: Check for "settings" key
    alt Settings Missing
        App->>File: Read settings.json
        File-->>App: Return settings data
        App->>SS: Store settings data
    end
    App->>App: Use st.session_state.settings["app-name"] for pages
Loading
sequenceDiagram
    participant Sidebar as Application Sidebar
    participant SS as Session State
    participant UI as UI Container/Markdown
    Sidebar->>SS: Retrieve "version" key
    SS-->>Sidebar: Return version value
    Sidebar->>UI: Display styled markdown with version info
Loading

Poem

I'm a rabbit in code land, hopping with delight,
New settings spring alive when the session feels light.
Carrots of version info nibble their way in view,
Dynamic names and numbers, fresh as morning dew.
With each change I twirl and bounce, a joyful little spree,
Coding trails and magic bytes, oh how happy I can be! 🐰


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b12493 and 21c82ff.

📒 Files selected for processing (1)
  • src/common/common.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/common/common.py

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
src/common/common.py (1)

103-105: 🛠️ Refactor suggestion

Duplicate settings loading code

The code to load settings from settings.json appears in both app.py and here. This creates duplication and potential for inconsistency.

Consider refactoring to have a single function that loads settings from the JSON file:

# In a new file, e.g., src/common/settings.py
def load_settings():
    try:
        with open("settings.json", "r") as f:
            return json.load(f)
    except FileNotFoundError:
        default_settings = {"app-name": "OpenMS Web App", "version": "Unknown"}
        st.error("settings.json file not found. Using default settings.")
        return default_settings
    except json.JSONDecodeError:
        default_settings = {"app-name": "OpenMS Web App", "version": "Unknown"}
        st.error("settings.json contains invalid JSON. Using default settings.")
        return default_settings

# Then in common.py and app.py:
if "settings" not in st.session_state:
    from src.common.settings import load_settings
    st.session_state.settings = load_settings()

This way, changes to the loading logic only need to be made in one place.

🧹 Nitpick comments (2)
app.py (1)

5-5:

Details

❓ Verification inconclusive

Remove unused import

The static analysis tool has flagged that pyopenms is imported but not used.

# For some reason the windows version only works if this is imported here
-import pyopenms

However, the comment suggests this import is necessary for Windows compatibility, so verification is needed before removal.


🏁 Script executed:

#!/bin/bash
# Check if pyopenms is used in this file or mentioned in other files with a reference to its usage
echo "Checking if pyopenms is used:"
rg -A 5 -B 5 -p "pyopenms.*import.*windows" --glob "*.py" --glob "*.md"

Length of output: 142


I'll now further verify the usage of pyopenms across the repository. Let's run a more comprehensive search.


🏁 Script executed:

#!/bin/bash
echo "Searching for any instance of 'pyopenms' usage:"
rg -n "pyopenms" --glob "*.py"

Length of output: 724


Unused Import in app.py: Verify Windows Compatibility Before Removal

The static analysis confirms that pyopenms is imported in app.py at line 5 but not used directly in that file. While our repository search shows that pyopenms is used in several other modules (e.g., in files under src/ and elsewhere), we did not find any evidence in app.py itself that indicates a side-effect-driven dependency for the Windows version. Given the existing comment—“for some reason the windows version only works if this is imported here”—please verify on a Windows environment that removing this import does not adversely affect functionality before making any changes.

  • Location: app.py, line 5
  • Action: Manually confirm Windows compatibility without the pyopenms import or provide an additional comment clarifying its necessity if retained.
🧰 Tools
🪛 Ruff (0.8.2)

5-5: pyopenms imported but unused

Remove unused import: pyopenms

(F401)

src/common/common.py (1)

326-342: Add error handling for version display and improve styling

The added code to display version information is a good enhancement, but there are a few improvements that could be made:

  1. Missing error handling if the "version" key doesn't exist in settings
  2. The styling is embedded directly in the code rather than in a separate CSS file
  3. The HTML is directly injected without proper escaping

Here's an improved implementation:

# Display OpenMS WebApp Template Version from settings.json 
with st.container():
    st.markdown(
        """
        <style>
        .version-box {
            border: 1px solid #a4a5ad; 
            padding: 10px;
            border-radius: 0.5rem; 
        }
        </style>
        """,
        unsafe_allow_html=True
    )
-    version_info = st.session_state.settings["version"]  
-    st.markdown(f'<div class="version-box"><b>OpenMS WebApp:<b/> V{version_info}</div>', unsafe_allow_html=True)
+    try:
+        version_info = st.session_state.settings.get("version", "Unknown")
+        st.markdown(f'<div class="version-box"><b>OpenMS WebApp:</b> V{version_info}</div>', unsafe_allow_html=True)
+    except Exception as e:
+        st.markdown('<div class="version-box"><b>OpenMS WebApp:</b> Version Unknown</div>', unsafe_allow_html=True)
+        st.error(f"Error retrieving version information: {str(e)}")

Also note that there's a small HTML error in the original code: <b>OpenMS WebApp:<b/> should be <b>OpenMS WebApp:</b> (closing tag uses the wrong slash direction).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f64a8bb and 9f370f6.

📒 Files selected for processing (3)
  • app.py (1 hunks)
  • settings.json (1 hunks)
  • src/common/common.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • settings.json
🧰 Additional context used
🪛 Ruff (0.8.2)
app.py

5-5: pyopenms imported but unused

Remove unused import: pyopenms

(F401)

🔇 Additional comments (3)
app.py (2)

3-3: Added necessary json import

This is appropriately added to support reading from the settings.json file.


13-13: Correctly implemented dynamic application name

Good job replacing the hardcoded application name with a dynamic reference from the settings.

src/common/common.py (1)

340-341: Verify version display rendering in various browsers

The version display uses custom CSS styling which may render differently across browsers. Ensure testing is done with different browsers to confirm consistent appearance.

Also, verify that the version string from settings.json is always a string format that will render properly when inserted into HTML.

Comment on lines +7 to +10
if "settings" not in st.session_state:
with open("settings.json", "r") as f:
st.session_state.settings = json.load(f)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Error handling needed for settings.json loading

The code adds functionality to load settings from a JSON file, but doesn't include error handling for cases where the file might be missing or contain invalid JSON.

Add error handling to gracefully manage file access or JSON parsing errors:

if "settings" not in st.session_state:
-        with open("settings.json", "r") as f:
-            st.session_state.settings = json.load(f)
+    try:
+        with open("settings.json", "r") as f:
+            st.session_state.settings = json.load(f)
+    except FileNotFoundError:
+        st.error("settings.json file not found. Please create this file with required settings.")
+        st.session_state.settings = {"app-name": "OpenMS Web App", "version": "Unknown"}
+    except json.JSONDecodeError:
+        st.error("settings.json contains invalid JSON. Please check the file format.")
+        st.session_state.settings = {"app-name": "OpenMS Web App", "version": "Unknown"}

Also, the indentation is inconsistent (8 spaces instead of 4), which differs from the rest of the file.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if "settings" not in st.session_state:
with open("settings.json", "r") as f:
st.session_state.settings = json.load(f)
if "settings" not in st.session_state:
try:
with open("settings.json", "r") as f:
st.session_state.settings = json.load(f)
except FileNotFoundError:
st.error("settings.json file not found. Please create this file with required settings.")
st.session_state.settings = {"app-name": "OpenMS Web App", "version": "Unknown"}
except json.JSONDecodeError:
st.error("settings.json contains invalid JSON. Please check the file format.")
st.session_state.settings = {"app-name": "OpenMS Web App", "version": "Unknown"}

@t0mdavid-m t0mdavid-m linked an issue Mar 5, 2025 that may be closed by this pull request
@t0mdavid-m t0mdavid-m self-requested a review March 5, 2025 09:14
Copy link
Member

@t0mdavid-m t0mdavid-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. Once the minor change requests are incorporated I think it is ready to merge.

unsafe_allow_html=True
)
version_info = st.session_state.settings["version"]
st.markdown(f'<div class="version-box"><b>OpenMS WebApp:<b/> V{version_info}</div>', unsafe_allow_html=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we either remove the OpenMS WebApp: prefix here or replace it by the App name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but app name is "OpenMS WebApp Template", @jcharkow mention it's very lengthy, so we can have OpenMS WebApp, so I have hard coded it

Copy link
Member

@t0mdavid-m t0mdavid-m Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see - sorry I missed that as its in the other PR.

@jcharkow I would suggest to display the version of the concrete WebApp instead of the version of the template used as this will likely have a greater effect on the WebApps output data and thus more relevant to the user. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@t0mdavid-m @jcharkow , you have discussed this already in #91, this PR is just to show the version info from the settings.json

We would implement and close the issue #91, so that whatever version in the settings.json will be displayed in the UI

Implemented text centering for improved visual presentation within the designated version.
Copy link
Contributor

@jcharkow jcharkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. After @t0mdavid-m review I think we can merge

@t0mdavid-m
Copy link
Member

One more thing I would like to have addressed:
It does not make sense to have the name "OpenMS WebApp" hardcoded above the version number of the individual WebApp. It is too generic and WebApps have individual names (e.g. FLASHApp, Umetaflow, PeakStorm, ...). @asterisk-ragavan is right - the name "OpenMS WebApp Template" is too lengthy to fit in the same line.

Hence, I request to display the following:

{App name from settings.json}
Version {Version number from settings.json}

The newline should resolve any issues regarding length.

Sorry for the back-and-forth @asterisk-ragavan!

@asterisk-ragavan
Copy link
Contributor Author

asterisk-ragavan commented Mar 6, 2025

One more thing I would like to have addressed: It does not make sense to have the name "OpenMS WebApp" hardcoded above the version number of the individual WebApp. It is too generic and WebApps have individual names (e.g. FLASHApp, Umetaflow, PeakStorm, ...). @asterisk-ragavan is right - the name "OpenMS WebApp Template" is too lengthy to fit in the same line.

Hence, I request to display the following:

{App name from settings.json} Version {Version number from settings.json}

The newline should resolve any issues regarding length.

Sorry for the back-and-forth @asterisk-ragavan!

@t0mdavid-m no sorry please, it's a great opportunity to work with you, and I am even learning new things.
will make the modifications and commit to the change.

post commit: done with the changes, added an image of how it looks on the UI
image

asterisk-ragavan and others added 2 commits March 6, 2025 14:21
{App name from settings.json}
Version {Version number from settings.json}
@t0mdavid-m
Copy link
Member

Thanks a lot for your contribution! I just removed the V before the version number as we already have the "Version: " prefix. Merging now!

@t0mdavid-m t0mdavid-m merged commit d65c9c9 into OpenMS:main Mar 6, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Display WebApp Versioning

3 participants