Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream apis #44

Merged
merged 7 commits into from
Oct 15, 2024
Merged

Stream apis #44

merged 7 commits into from
Oct 15, 2024

Conversation

chakrabandla
Copy link
Contributor

@chakrabandla chakrabandla commented Oct 15, 2024

PR Type

enhancement, dependencies


Description

  • Introduced streaming capabilities for both project and file metadata using new methods in Files and Project classes.
  • Added new CLI commands to facilitate streaming of metadata to files.
  • Enhanced utility functions to support asynchronous streaming with httpx.
  • Updated dependencies to include httpx for handling asynchronous HTTP requests.
  • Updated package version and author email in setup.py.

Changes walkthrough 📝

Relevant files
Enhancement
files.py
Add streaming capability for file metadata                             

pridepy/files/files.py

  • Added a new method stream_all_files_metadata for streaming file
    metadata.
  • Introduced V3_API_BASE_URL for API requests.
  • +18/-0   
    pridepy.py
    Add CLI commands for streaming metadata                                   

    pridepy/pridepy.py

  • Added CLI commands for streaming project and file metadata.
  • Utilized asyncio for asynchronous operations.
  • +38/-1   
    project.py
    Implement project metadata streaming functionality             

    pridepy/project/project.py

  • Added stream_all_projects method for streaming project metadata.
  • Introduced V3_API_BASE_URL for API requests.
  • +14/-0   
    api_handling.py
    Add utility for handling streaming API responses                 

    pridepy/util/api_handling.py

  • Added stream_response_to_file method for handling streaming responses.
  • Utilized httpx for asynchronous HTTP requests.
  • +29/-0   
    Miscellaneous
    setup.py
    Update package version and author email                                   

    setup.py

  • Updated package version to 0.0.5.
  • Changed author email to [email protected].
  • +2/-2     
    Dependencies
    environment.yml
    Add httpx to dependencies                                                               

    environment.yml

    • Added httpx to the list of dependencies.
    +2/-1     
    requirements.txt
    Add httpx to requirements                                                               

    requirements.txt

    • Added httpx to the list of dependencies.
    +2/-1     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link
    Contributor

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

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling
    The new stream_all_files_metadata method lacks proper error handling for API requests and file operations.

    Input Validation
    The new CLI commands for streaming metadata lack input validation for the output file path.

    Resource Management
    The stream_response_to_file method doesn't use a context manager for file handling, which could lead to resource leaks.

    Copy link
    Contributor

    codiumai-pr-agent-pro bot commented Oct 15, 2024

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

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Best practice
    ✅ Use a context manager for file operations to ensure proper resource management
    Suggestion Impact:The commit implemented the suggestion by replacing the manual file open and close operations with a context manager using 'with open(out_file, 'w') as cfile:'.

    code diff:

    -                        cfile = open(out_file, 'w')
    -                        # Iterate over the streaming content line by line
    -                        async for line in response.aiter_lines():
    -                            if line:  # Avoid printing empty lines (common with text/event-stream)
    -                                cfile.write(line + "\n")
    -                                # Check if the pattern exists in the string
    -                                if re.search(regex_search_pattern, line):
    -                                    pbar.update(1)  # Update progress bar by 1 for each detection
    -                        cfile.close()
    +                        with open(out_file, 'w') as cfile:

    Consider using a context manager for file operations to ensure proper file closure,
    even in case of exceptions.

    pridepy/util/api_handling.py [49-57]

    -cfile = open(out_file, 'w')
    -# ... file operations ...
    -cfile.close()
    +with open(out_file, 'w') as cfile:
    +    # ... file operations ...
    Suggestion importance[1-10]: 8

    Why: Implementing a context manager for file operations ensures that files are properly closed even if an exception occurs, which is a best practice for resource management.

    8
    Maintainability
    Use a constant for API version to improve maintainability

    Consider using a constant for the API version number instead of hardcoding it in the
    URL. This will make it easier to update the API version across the entire codebase
    in the future.

    pridepy/files/files.py [53]

    -V3_API_BASE_URL = "https://www.ebi.ac.uk/pride/ws/archive/v3"
    +API_VERSION = "v3"
    +V3_API_BASE_URL = f"https://www.ebi.ac.uk/pride/ws/archive/{API_VERSION}"
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: Using a constant for the API version enhances maintainability by centralizing the version number, making future updates easier and reducing the risk of errors from hardcoded values.

    7
    Enhancement
    ✅ Use f-strings for string formatting to improve readability and performance

    Consider using f-strings for string formatting instead of the .format() method for
    improved readability and performance.

    pridepy/files/files.py [71-72]

    -request_url = ("{0}/files/all".format(self.V3_API_BASE_URL))
    -count_request_url = ("{0}/files/count".format(self.V3_API_BASE_URL))
    +request_url = f"{self.V3_API_BASE_URL}/files/all"
    +count_request_url = f"{self.V3_API_BASE_URL}/files/count"

    [Suggestion has been applied]

    Suggestion importance[1-10]: 6

    Why: Replacing the .format() method with f-strings improves code readability and performance, aligning with modern Python practices.

    6

    💡 Need additional feedback ? start a PR chat

    Copy link
    Contributor

    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

    Failed stage: Install mamba, boa and conda-build [❌]

    Relevant error logs:
    1:  ##[group]Operating System
    2:  Ubuntu
    ...
    
    405:  download_only: False
    406:  dry_run: False
    407:  enable_private_envs: False
    408:  env_prompt: ({default_env}) 
    409:  envs_dirs:
    410:  - /usr/share/miniconda/envs
    411:  - /home/runner/.conda/envs
    412:  envvars_force_uppercase: True
    413:  error_upload_url: https://conda.io/conda-post/unexpected-error
    ...
    
    443:  remote_connect_timeout_secs: 9.15
    444:  remote_max_retries: 3
    445:  remote_read_timeout_secs: 60.0
    446:  repodata_fns:
    447:  - current_repodata.json
    448:  - repodata.json
    449:  repodata_threads: None
    450:  repodata_use_zst: True
    451:  report_errors: None
    ...
    
    747:  Executing transaction: ...working... done
    748:  Channels:
    749:  - conda-forge
    750:  - defaults
    751:  - bioconda
    752:  Platform: linux-64
    753:  Collecting package metadata (repodata.json): ...working... done
    754:  warning  libmamba Added empty dependency for problem type SOLVER_RULE_UPDATE
    755:  Solving environment: ...working... failed
    756:  LibMambaUnsatisfiableError: Encountered problems while solving:
    ...
    
    813:  │        ├─ conda-build [24.1.0|24.1.1|...|3.28.4], which can be installed (as previously explained);
    814:  │        ├─ conda-build [24.1.0|24.1.1|...|3.28.4], which can be installed (as previously explained);
    815:  │        └─ conda-build [24.1.0|24.1.1|...|24.5.1] would require
    816:  │           └─ python >=3.12,<3.13.0a0 , which can be installed;
    817:  └─ pin-1 is not installable because it requires
    818:  └─ python 3.13.* , which conflicts with any installable versions previously reported.
    819:  Pins seem to be involved in the conflict. Currently pinned specs:
    820:  - python 3.13.* (labeled as 'pin-1')
    821:  ##[error]Process completed with exit code 1.
    

    ✨ 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.

    Co-authored-by: codiumai-pr-agent-pro[bot] <151058649+codiumai-pr-agent-pro[bot]@users.noreply.github.com>
    Copy link
    Contributor

    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

    Failed stage: Install mamba, boa and conda-build [❌]

    Failure summary:

    The action failed due to a dependency resolution conflict in the Conda environment:

  • The conda-build package requires python version >=3.12,<3.13.0a0.
  • However, there is a pin on python version 3.13.*, which conflicts with the required version range
    for conda-build.
  • This conflict resulted in a LibMambaUnsatisfiableError, preventing the environment from being
    solved.

  • Relevant error logs:
    1:  ##[group]Operating System
    2:  Ubuntu
    ...
    
    405:  download_only: False
    406:  dry_run: False
    407:  enable_private_envs: False
    408:  env_prompt: ({default_env}) 
    409:  envs_dirs:
    410:  - /usr/share/miniconda/envs
    411:  - /home/runner/.conda/envs
    412:  envvars_force_uppercase: True
    413:  error_upload_url: https://conda.io/conda-post/unexpected-error
    ...
    
    443:  remote_connect_timeout_secs: 9.15
    444:  remote_max_retries: 3
    445:  remote_read_timeout_secs: 60.0
    446:  repodata_fns:
    447:  - current_repodata.json
    448:  - repodata.json
    449:  repodata_threads: None
    450:  repodata_use_zst: True
    451:  report_errors: None
    ...
    
    747:  Executing transaction: ...working... done
    748:  Channels:
    749:  - conda-forge
    750:  - defaults
    751:  - bioconda
    752:  Platform: linux-64
    753:  Collecting package metadata (repodata.json): ...working... done
    754:  warning  libmamba Added empty dependency for problem type SOLVER_RULE_UPDATE
    755:  Solving environment: ...working... failed
    756:  LibMambaUnsatisfiableError: Encountered problems while solving:
    ...
    
    813:  │        ├─ conda-build [24.1.0|24.1.1|...|3.28.4], which can be installed (as previously explained);
    814:  │        ├─ conda-build [24.1.0|24.1.1|...|3.28.4], which can be installed (as previously explained);
    815:  │        └─ conda-build [24.1.0|24.1.1|...|24.5.1] would require
    816:  │           └─ python >=3.12,<3.13.0a0 , which can be installed;
    817:  └─ pin-1 is not installable because it requires
    818:  └─ python 3.13.* , which conflicts with any installable versions previously reported.
    819:  Pins seem to be involved in the conflict. Currently pinned specs:
    820:  - python 3.13.* (labeled as 'pin-1')
    821:  ##[error]Process completed with exit code 1.
    

    ✨ 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.

    Copy link
    Contributor

    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

    Failed stage: Install mamba, boa and conda-build [❌]

    Failure summary:

    The action failed due to a dependency resolution conflict in the Conda environment:

  • The package conda-build requires python version >=3.12,<3.13.0a0.
  • However, there is a pinned requirement for python version 3.13.*, which conflicts with the required
    version range for conda-build.
  • This conflict resulted in a LibMambaUnsatisfiableError during the environment solving process.

  • Relevant error logs:
    1:  ##[group]Operating System
    2:  Ubuntu
    ...
    
    405:  download_only: False
    406:  dry_run: False
    407:  enable_private_envs: False
    408:  env_prompt: ({default_env}) 
    409:  envs_dirs:
    410:  - /usr/share/miniconda/envs
    411:  - /home/runner/.conda/envs
    412:  envvars_force_uppercase: True
    413:  error_upload_url: https://conda.io/conda-post/unexpected-error
    ...
    
    443:  remote_connect_timeout_secs: 9.15
    444:  remote_max_retries: 3
    445:  remote_read_timeout_secs: 60.0
    446:  repodata_fns:
    447:  - current_repodata.json
    448:  - repodata.json
    449:  repodata_threads: None
    450:  repodata_use_zst: True
    451:  report_errors: None
    ...
    
    747:  Executing transaction: ...working... done
    748:  Channels:
    749:  - conda-forge
    750:  - defaults
    751:  - bioconda
    752:  Platform: linux-64
    753:  Collecting package metadata (repodata.json): ...working... done
    754:  warning  libmamba Added empty dependency for problem type SOLVER_RULE_UPDATE
    755:  Solving environment: ...working... failed
    756:  LibMambaUnsatisfiableError: Encountered problems while solving:
    ...
    
    813:  │        ├─ conda-build [24.1.0|24.1.1|...|3.28.4], which can be installed (as previously explained);
    814:  │        ├─ conda-build [24.1.0|24.1.1|...|3.28.4], which can be installed (as previously explained);
    815:  │        └─ conda-build [24.1.0|24.1.1|...|24.5.1] would require
    816:  │           └─ python >=3.12,<3.13.0a0 , which can be installed;
    817:  └─ pin-1 is not installable because it requires
    818:  └─ python 3.13.* , which conflicts with any installable versions previously reported.
    819:  Pins seem to be involved in the conflict. Currently pinned specs:
    820:  - python 3.13.* (labeled as 'pin-1')
    821:  ##[error]Process completed with exit code 1.
    

    ✨ 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.

    Copy link
    Contributor

    CI Failure Feedback 🧐

    Action: build

    Failed stage: Install mamba, boa and conda-build [❌]

    Failure summary:

    The action failed due to a dependency conflict while solving the environment with conda:

  • The package conda-build requires python version >=3.12,<3.13.0a0.
  • However, there is a pin for python version 3.13.* which conflicts with the required version range
    for conda-build.
  • This conflict resulted in a LibMambaUnsatisfiableError, preventing the environment from being solved
    successfully.

  • Relevant error logs:
    1:  ##[group]Operating System
    2:  Ubuntu
    ...
    
    405:  download_only: False
    406:  dry_run: False
    407:  enable_private_envs: False
    408:  env_prompt: ({default_env}) 
    409:  envs_dirs:
    410:  - /usr/share/miniconda/envs
    411:  - /home/runner/.conda/envs
    412:  envvars_force_uppercase: True
    413:  error_upload_url: https://conda.io/conda-post/unexpected-error
    ...
    
    443:  remote_connect_timeout_secs: 9.15
    444:  remote_max_retries: 3
    445:  remote_read_timeout_secs: 60.0
    446:  repodata_fns:
    447:  - current_repodata.json
    448:  - repodata.json
    449:  repodata_threads: None
    450:  repodata_use_zst: True
    451:  report_errors: None
    ...
    
    747:  Executing transaction: ...working... done
    748:  Channels:
    749:  - conda-forge
    750:  - defaults
    751:  - bioconda
    752:  Platform: linux-64
    753:  Collecting package metadata (repodata.json): ...working... done
    754:  warning  libmamba Added empty dependency for problem type SOLVER_RULE_UPDATE
    755:  Solving environment: ...working... failed
    756:  LibMambaUnsatisfiableError: Encountered problems while solving:
    ...
    
    813:  │        ├─ conda-build [24.1.0|24.1.1|...|3.28.4], which can be installed (as previously explained);
    814:  │        ├─ conda-build [24.1.0|24.1.1|...|3.28.4], which can be installed (as previously explained);
    815:  │        └─ conda-build [24.1.0|24.1.1|...|24.5.1] would require
    816:  │           └─ python >=3.12,<3.13.0a0 , which can be installed;
    817:  └─ pin-1 is not installable because it requires
    818:  └─ python 3.13.* , which conflicts with any installable versions previously reported.
    819:  Pins seem to be involved in the conflict. Currently pinned specs:
    820:  - python 3.13.* (labeled as 'pin-1')
    821:  ##[error]Process completed with exit code 1.
    

    ✨ 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.

    @ypriverol ypriverol merged commit b1c55b5 into master Oct 15, 2024
    6 of 7 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants