Skip to content

Conversation

@t0mdavid-m
Copy link
Member

@t0mdavid-m t0mdavid-m commented Jul 2, 2024

User description

This PR adds a download page to give the user the option to download the results generated as a zip file.

Fixes #53.

Developers simply have to specify a folder in the workspace, where all output is saved. Each run should be saved in a different subfolder. For instance, consider these folder locations for output_folder="output_folder":

workspace/output_folder/run_1/
workspace/output_folder/run_2/
workspace/output_folder/run_3/

This would result in three download options: run_1, run_2, and run_3.

Downloads are prepared on demand. The zip file is only created when the Prepare Download button is clicked.

In FLASHViewer it looks like this:

image

PR Type

Enhancement


Description

  • Added a new download page to the application, allowing users to download results as zip files.
  • Implemented directory listing and zip file preparation functionality.
  • Included error handling for cases where no results are available.

Changes walkthrough 📝

Relevant files
Enhancement
16_Download_Section.py
Add download page for exporting results as zip files         

pages/16_Download_Section.py

  • Added a new page for downloading results as zip files.
  • Implemented a function to list directories and prepare zip files for
    download.
  • Included error handling for missing directories and empty results.
  • +64/-0   

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @qodo-code-review qodo-code-review bot added the enhancement New feature or request label Jul 2, 2024
    @qodo-code-review
    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review [1-5] 3
    🧪 Relevant tests No
    🔒 Security concerns No
    ⚡ Key issues to review Possible Bug:
    The list comprehension used to filter directories might not work as expected because isfile(entry) does not use the full path. It should be isfile(join(dirpath, entry)).
    Error Handling:
    The error handling for file reading within the zip file creation loop does not specify what types of exceptions it expects, which could lead to silent failures or unhandled exceptions.
    Performance Concern:
    The zip file is being created every time the button is clicked, even if it already exists. This could be optimized by checking if the zip file exists before attempting to create it.

    @qodo-code-review
    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Correct the directory filtering logic to accurately list directories

    Replace the isfile check in the list comprehension with isdir to ensure that only
    directories are listed. Currently, the isfile function is used incorrectly to filter
    directories.

    pages/16_Download_Section.py [21]

    -[entry for entry in listdir(dirpath) if not isfile(entry)]
    +[entry for entry in listdir(dirpath) if isdir(join(dirpath, entry))]
     
    • Apply this suggestion
    Suggestion importance[1-10]: 10

    Why: The suggestion correctly identifies a bug where isfile is used instead of isdir, which would result in incorrect directory listings. This is a crucial fix for the functionality of the code.

    10
    Enhancement
    Improve robustness by handling file read errors during the zip creation process

    Add error handling for the open function when reading files to include in the zip. This
    will prevent the entire download process from failing if a single file cannot be opened.

    pages/16_Download_Section.py [53-54]

    -with open(join(dirpath, directory, output), 'r') as f:
    -    zip_file.writestr(basename(output), f.read())
    +try:
    +    with open(join(dirpath, directory, output), 'r') as f:
    +        zip_file.writestr(basename(output), f.read())
    +except IOError as e:
    +    st.error(f"Failed to read {output}: {str(e)}")
    +    continue
     
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: Adding error handling for file reading improves the robustness of the code by ensuring that a single file read error does not cause the entire process to fail. This is a significant enhancement.

    9
    Maintainability
    Refactor file path manipulations to use pathlib.Path for better readability and maintainability

    Use pathlib.Path for file and directory path manipulations to make the code more readable
    and pythonic.

    pages/16_Download_Section.py [17]

    -dirpath = join(st.session_state["workspace"], output_folder)
    +from pathlib import Path
    +dirpath = Path(st.session_state["workspace"]) / output_folder
     
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Using pathlib.Path makes the code more readable and maintainable. However, this is more of a code style improvement and does not fix any functional issues.

    7
    Performance
    Optimize performance by reducing redundant calls to create column layouts

    Replace the repeated creation of st.columns inside the loop with a single creation outside
    the loop to improve performance.

    pages/16_Download_Section.py [36-39]

    +columns = st.columns((0.4, 0.6))
     for i, directory in enumerate(directories):
         st.divider()
    -    columns = st.columns((0.4, 0.6))
         columns[0].empty().write(directory)
     
    • Apply this suggestion
    Suggestion importance[1-10]: 3

    Why: While reducing redundant calls can improve performance, the suggestion is incorrect because each iteration requires a new set of columns. This would break the intended functionality.

    3

    @t0mdavid-m t0mdavid-m self-assigned this Jul 2, 2024
    @t0mdavid-m t0mdavid-m requested a review from axelwalter July 2, 2024 13:48
    @qodo-code-review
    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    CI Failure Feedback 🧐

    Action: build-executable

    Failed stage: Delete OpenMS bin artifact [❌]

    Failure summary:

    The action failed because the geekyeggo/delete-artifact@v4 step encountered an HttpError.
    The specific error message was Resource not accessible by integration, indicating that the action
    did not have the necessary permissions to access the resource.

    Relevant error logs:
    1:  ##[group]Operating System
    2:  Microsoft Windows Server 2022
    ...
    
    458:  �[32;1mMode   �[0m�[32;1m              LastWriteTime�[0m �[32;1;3m        Length�[0m�[32;1m Name�[0m
    459:  �[32;1m----   �[0m �[32;1m             -------------�[0m �[32;1m        ------�[0m �[32;1m----�[0m
    460:  d----            7/2/2024  3:08 PM                �[44;1mstreamlit_exe�[0m
    461:  ##[group]Run geekyeggo/delete-artifact@v4
    462:  with:
    463:  name: OpenMS-bin
    464:  token: ***
    465:  useGlob: true
    466:  failOnError: true
    467:  env:
    468:  PYTHON_VERSION: 3.11.0
    469:  ##[endgroup]
    470:  ##[error]HttpError: Resource not accessible by integration
    

    ✨ CI feedback usage guide:

    The CI feedback tool (/checks) automatically triggers when a PR has a failed check.
    The tool analyzes the failed checks and provides several feedbacks:

    • Failed stage
    • Failed test name
    • Failure summary
    • Relevant error logs

    In addition to being automatically triggered, the tool can also be invoked manually by commenting on a PR:

    /checks "https://github.com/{repo_name}/actions/runs/{run_number}/job/{job_number}"
    

    where {repo_name} is the name of the repository, {run_number} is the run number of the failed check, and {job_number} is the job number of the failed check.

    Configuration options

    • enable_auto_checks_feedback - if set to true, the tool will automatically provide feedback when a check is failed. Default is true.
    • excluded_checks_list - a list of checks to exclude from the feedback, for example: ["check1", "check2"]. Default is an empty list.
    • enable_help_text - if set to true, the tool will provide a help message with the feedback. Default is true.
    • persistent_comment - if set to true, the tool will overwrite a previous checks comment with the new feedback. Default is true.
    • final_update_message - if persistent_comment is true and updating a previous checks message, the tool will also create a new message: "Persistent checks updated to latest commit". Default is true.

    See more information about the checks tool in the docs.

    @t0mdavid-m
    Copy link
    Member Author

    t0mdavid-m commented Jul 2, 2024

    CI is failing since geekyeggo/delete-artifact@v4 has been deprecated. I will update it in #68 as this changes the window build CI artifacts.

    @qodo-code-review
    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    CI Failure Feedback 🧐

    Action: build-executable

    Failed stage: Delete OpenMS bin artifact [❌]

    Failure summary:

    The action failed because the geekyeggo/delete-artifact@v4 action encountered an HttpError.

  • The specific error message was Resource not accessible by integration.
  • This likely indicates that the action did not have the necessary permissions to access the specified
    resource.

  • Relevant error logs:
    1:  ##[group]Operating System
    2:  Microsoft Windows Server 2022
    ...
    
    458:  �[32;1mMode   �[0m�[32;1m              LastWriteTime�[0m �[32;1;3m        Length�[0m�[32;1m Name�[0m
    459:  �[32;1m----   �[0m �[32;1m             -------------�[0m �[32;1m        ------�[0m �[32;1m----�[0m
    460:  d----            7/2/2024  3:19 PM                �[44;1mstreamlit_exe�[0m
    461:  ##[group]Run geekyeggo/delete-artifact@v4
    462:  with:
    463:  name: OpenMS-bin
    464:  token: ***
    465:  useGlob: true
    466:  failOnError: true
    467:  env:
    468:  PYTHON_VERSION: 3.11.0
    469:  ##[endgroup]
    470:  ##[error]HttpError: Resource not accessible by integration
    

    ✨ CI feedback usage guide:

    The CI feedback tool (/checks) automatically triggers when a PR has a failed check.
    The tool analyzes the failed checks and provides several feedbacks:

    • Failed stage
    • Failed test name
    • Failure summary
    • Relevant error logs

    In addition to being automatically triggered, the tool can also be invoked manually by commenting on a PR:

    /checks "https://github.com/{repo_name}/actions/runs/{run_number}/job/{job_number}"
    

    where {repo_name} is the name of the repository, {run_number} is the run number of the failed check, and {job_number} is the job number of the failed check.

    Configuration options

    • enable_auto_checks_feedback - if set to true, the tool will automatically provide feedback when a check is failed. Default is true.
    • excluded_checks_list - a list of checks to exclude from the feedback, for example: ["check1", "check2"]. Default is an empty list.
    • enable_help_text - if set to true, the tool will provide a help message with the feedback. Default is true.
    • persistent_comment - if set to true, the tool will overwrite a previous checks comment with the new feedback. Default is true.
    • final_update_message - if persistent_comment is true and updating a previous checks message, the tool will also create a new message: "Persistent checks updated to latest commit". Default is true.

    See more information about the checks tool in the docs.

    @t0mdavid-m t0mdavid-m mentioned this pull request Jul 19, 2024
    @axelwalter axelwalter merged commit 0f2aad0 into main Jul 23, 2024
    JohannesvKL pushed a commit to JohannesvKL/PTMScanner that referenced this pull request Dec 19, 2024
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    add download section for results

    3 participants