Skip to content

window exec work with pyinstaller issue #180#183

Closed
Srajald wants to merge 1 commit intoOpenMS:mainfrom
Srajald:window-exec-pyinstaller
Closed

window exec work with pyinstaller issue #180#183
Srajald wants to merge 1 commit intoOpenMS:mainfrom
Srajald:window-exec-pyinstaller

Conversation

@Srajald
Copy link
Copy Markdown
Contributor

@Srajald Srajald commented Mar 14, 2025

Summary by CodeRabbit

  • New Features

    • The app now features an intuitive sidebar for navigation with expandable categories, offering clear page selection and load feedback.
    • Configuration handling has been improved to provide clear error notifications and default settings when expected configuration data is missing.
  • Chores

    • The packaging and resource collection process has been streamlined to support smoother deployment and maintenance.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 14, 2025

Walkthrough

This pull request introduces new asynchronous event loop management and settings handling in the application. An ensure_event_loop function ensures an event loop is available, while a new load_settings function manages reading the settings.json file and handling errors using Streamlit. Modifications include updating navigation logic to use a sidebar with buttons and storing the selected page in session state. Additionally, the application’s entry point is refactored into a main function. The PyInstaller configuration in run_app_temp.spec is also updated by consolidating resource paths, hidden imports, and setting the project directory in pathex.

Changes

File(s) Change Summary
app.py Added ensure_event_loop and load_settings functions, updated session state initialization for current_page, refactored navigation to use sidebar buttons with tuple-based page definitions, and modified the entry point to call a main function.
run_app_temp.spec Introduced variables hiddenimports and datas for PyInstaller configuration, updated Analysis parameters to use these variables, and changed pathex from an empty list to ['.'].

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant EventLoop
    participant Loader
    participant Session

    User->>App: Launch Application
    App->>EventLoop: ensure_event_loop()
    EventLoop-->>App: Return event loop (new or existing)
    App->>Loader: load_settings()
    Loader-->>App: Return settings or defaults with error (if file missing)
    App->>Session: Update session state (initialize current_page)
    App->>User: Render sidebar with navigation buttons
    User->>App: Select a page
    App->>User: Display selected page content
Loading

Poem

I'm a bunny coding away,
Hoping loops will guide my day.
With settings loaded nice and clear,
My sidebar wizardry appears!
Jumping through code with a playful stride,
This rabbit's joy can't hide! 🐰🌟

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 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
Copy Markdown

@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: 0

🧹 Nitpick comments (2)
run_app_temp.spec (1)

11-18: Consider using relative paths instead of environment-specific paths

The current paths are tied to a specific virtual environment location (./myenv/), which might cause issues when building on different machines or CI/CD environments.

Consider using a more environment-agnostic approach:

- datas += [
-     ("./myenv/Lib/site-packages/altair/vegalite/v5/schema/vega-lite-schema.json", "./altair/vegalite/v5/schema/"),
-     ("./myenv/Lib/site-packages/streamlit/static", "./streamlit/static"),
-     ("./myenv/Lib/site-packages/streamlit/runtime", "./streamlit/runtime"),
-     ("./myenv/Lib/site-packages/pyopenms", "./pyopenms/"),
-     ("./myenv/Lib/site-packages/captcha", "./captcha/"),
-     ("./myenv/Lib/site-packages/pyarrow", "./pyarrow/"),
- ]
+ import site
+ site_packages = site.getsitepackages()[0]
+ datas += [
+     (f"{site_packages}/altair/vegalite/v5/schema/vega-lite-schema.json", "./altair/vegalite/v5/schema/"),
+     (f"{site_packages}/streamlit/static", "./streamlit/static"),
+     (f"{site_packages}/streamlit/runtime", "./streamlit/runtime"),
+     (f"{site_packages}/pyopenms", "./pyopenms/"),
+     (f"{site_packages}/captcha", "./captcha/"),
+     (f"{site_packages}/pyarrow", "./pyarrow/"),
+ ]
🧰 Tools
🪛 RuboCop (1.73)

[fatal] 12-12: unexpected token tCOMMA
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)

(Lint/Syntax)


[fatal] 13-13: unexpected token tCOMMA
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)

(Lint/Syntax)


[fatal] 14-14: unexpected token tCOMMA
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)

(Lint/Syntax)


[fatal] 15-15: unexpected token tCOMMA
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)

(Lint/Syntax)


[fatal] 16-16: unexpected token tCOMMA
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)

(Lint/Syntax)


[fatal] 17-17: unexpected token tCOMMA
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)

(Lint/Syntax)

app.py (1)

15-25: Good error handling in settings loading

The load_settings function handles the case where settings.json is missing gracefully, providing default values and informing the user. This is a robust approach to configuration management.

However, consider adding error handling for JSON parsing issues:

 def load_settings():
     settings_path = Path(__file__).parent / "settings.json" 
     if not settings_path.exists():
         st.error("⚠️ Error: 'settings.json' is missing! Using default settings.")
         return {
             "app-name": "Default App",
             "version": "1.0.0",
             "analytics": {"google-analytics": {"enabled": False, "tag": ""}},
         }
-    with open(settings_path, "r") as f:
-        return json.load(f)
+    try:
+        with open(settings_path, "r") as f:
+            return json.load(f)
+    except json.JSONDecodeError:
+        st.error("⚠️ Error: 'settings.json' contains invalid JSON! Using default settings.")
+        return {
+            "app-name": "Default App",
+            "version": "1.0.0",
+            "analytics": {"google-analytics": {"enabled": False, "tag": ""}},
+        }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1619a14 and afbe542.

📒 Files selected for processing (2)
  • app.py (1 hunks)
  • run_app_temp.spec (1 hunks)
🧰 Additional context used
🪛 RuboCop (1.73)
run_app_temp.spec

[fatal] 9-9: unexpected token tCOMMA
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)

(Lint/Syntax)


[fatal] 12-12: unexpected token tCOMMA
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)

(Lint/Syntax)


[fatal] 13-13: unexpected token tCOMMA
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)

(Lint/Syntax)


[fatal] 14-14: unexpected token tCOMMA
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)

(Lint/Syntax)


[fatal] 15-15: unexpected token tCOMMA
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)

(Lint/Syntax)


[fatal] 16-16: unexpected token tCOMMA
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)

(Lint/Syntax)


[fatal] 17-17: unexpected token tCOMMA
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)

(Lint/Syntax)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build-simple-app
  • GitHub Check: build-full-app
  • GitHub Check: build-openms
🔇 Additional comments (10)
run_app_temp.spec (3)

2-2: Good addition of PyInstaller utility hooks

Adding these utility functions is an excellent approach for automatically collecting submodules and data files, which helps solve dependency resolution issues with PyInstaller.


7-9: Comprehensive hidden imports and data collection

This is a good solution to fix the PyInstaller packaging issue. Collecting submodules automatically and explicitly adding "pyexpat" addresses common PyInstaller bundling problems with these libraries. Including settings.json in the data files ensures it's properly packaged with the application.

🧰 Tools
🪛 RuboCop (1.73)

[fatal] 9-9: unexpected token tCOMMA
(Using Ruby 2.7 parser; configure using TargetRubyVersion parameter, under AllCops)

(Lint/Syntax)


22-25: Good configuration of Analysis parameters

Setting pathex=['.'] is a good practice to ensure the project directory is in the Python path. Using the previously defined datas and hiddenimports variables improves code organization and maintainability.

app.py (7)

1-2: Appropriate import additions

Adding json and asyncio imports is necessary for the new functionality being implemented.


6-13: Good implementation of event loop management

The ensure_event_loop function correctly handles event loop creation when needed, which is important for asynchronous operations in a Streamlit application. This helps prevent "no running event loop" errors.


28-30: Good initialization of session state variables

Properly initializing session state variables ensures consistent application state. Adding current_page tracking is a good enhancement for managing navigation.


32-54: Improved navigation structure with tuples

The change from st.Page objects to tuples simplifies the page definitions while maintaining all necessary information. This approach is more maintainable and readable.


56-67: Enhanced sidebar navigation with expandable categories

The new navigation system using expandable categories and buttons is a significant improvement for user experience. The code correctly tracks the selected page in session state for persistence.


68-70: Page loading feedback is helpful

Providing feedback when loading a page improves user experience by indicating that an action is being performed.


71-72: Good encapsulation with main function

Moving the application logic into a dedicated main() function is a good practice for better code organization and potential reusability.

@Arslan-Siraj
Copy link
Copy Markdown
Contributor

@Srajald can you please build via https://github.com/OpenMS/streamlit-template/blob/main/.github/workflows/build-windows-executable-app-with-pyinstaller.yaml (please try latest streamlit version and then test via install the executable and launched the app) try out to build in PR with
pull_request:
branches: [ "main" ]

@Srajald
Copy link
Copy Markdown
Contributor Author

Srajald commented Mar 17, 2025

@Arslan-Siraj
Sure Sir, I will follow your instructions ...
thanks

@t0mdavid-m t0mdavid-m closed this Apr 16, 2025
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.

check if window exec work with pyinstaller with latest version of streamlit

3 participants