Skip to content

Remove pytest plugin functionality#55

Closed
upview wants to merge 1 commit intomainfrom
remove-pytest-plugin
Closed

Remove pytest plugin functionality#55
upview wants to merge 1 commit intomainfrom
remove-pytest-plugin

Conversation

@upview
Copy link
Copy Markdown
Collaborator

@upview upview commented Mar 4, 2025

Summary by CodeRabbit

  • New Features

    • Improved network reliability with enhanced retry and timeout management for a more consistent API experience.
  • Chores

    • Streamlined package dependencies by removing outdated testing integrations.
    • Increased security by automatically clearing sensitive authentication credentials after use.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 4, 2025

Walkthrough

This pull request removes pytest integration and dependencies from the package while enhancing network request handling and bolstering security. The setup has been modified to exclude pytest from dependencies and plugin registration, with related imports and configuration removed. Additionally, the TofuPilotClient now clears its API key from memory after use. Significant changes in the network utilities include added retry logic, timeout management via a decorator, and session handling improvements.

Changes

File(s) Change Summary
setup.py, tofupilot/__init__.py, tofupilot/plugin.py, tofupilot/pytest.ini Removed pytest dependency and related plugin integration: omitted pytest from install_requires, removed entry_points, deleted pytest plugin code and custom markers, and eliminated imports referencing the pytest plugin.
tofupilot/client.py Updated TofuPilotClient constructor to clear the API key from memory immediately after setting the authorization header.
tofupilot/utils/network.py Added a create_session function with retry logic, introduced a timeout_decorator for enforcing request timeouts, and updated secure_request to use these enhancements with improved HTTP and SSL error handling.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant NetworkModule as tofupilot/utils/network.py
    participant SESSION
    participant HTTPServer

    Caller->>NetworkModule: Call secure_request(method, url, kwargs)
    Note right of NetworkModule: @timeout_decorator applies timeout
    NetworkModule->>SESSION: Execute HTTP request with retry logic
    SESSION->>HTTPServer: Send request
    HTTPServer-->>SESSION: Return response
    SESSION-->>NetworkModule: Relay response or error
    NetworkModule-->>Caller: Return final result
Loading
sequenceDiagram
    participant ClientCaller
    participant TofuPilotClient

    ClientCaller->>TofuPilotClient: Initialize client(api_key, ...)
    TofuPilotClient->>TofuPilotClient: Set authorization header using api_key
    TofuPilotClient->>TofuPilotClient: Clear _api_key (set to None)
Loading

Poem

I’m a bouncing bunny with code so light,
Hopping past pytest’s removed old fright.
API keys vanish like dew in the dawn,
While network retries make errors be gone.
With timeout and headers now perfectly aligned,
I celebrate these changes with a joyful mind!
🐰✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 (1)
tofupilot/utils/network.py (1)

1-2: Clean up unused imports

The static analysis indicates that Union and os are imported but never used in this file.

-from typing import Dict, List, Optional, Any, Union, Callable
+from typing import Dict, List, Optional, Any, Callable
-import os
🧰 Tools
🪛 Ruff (0.8.2)

1-1: typing.Union imported but unused

Remove unused import: typing.Union

(F401)


2-2: os imported but unused

Remove unused import: os

(F401)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4540f3f and f33cdfff1c8b0a99a5234e72dc02e06be999424d.

📒 Files selected for processing (6)
  • setup.py (1 hunks)
  • tofupilot/__init__.py (0 hunks)
  • tofupilot/client.py (1 hunks)
  • tofupilot/plugin.py (0 hunks)
  • tofupilot/pytest.ini (0 hunks)
  • tofupilot/utils/network.py (1 hunks)
💤 Files with no reviewable changes (3)
  • tofupilot/init.py
  • tofupilot/pytest.ini
  • tofupilot/plugin.py
🧰 Additional context used
🪛 Ruff (0.8.2)
tofupilot/utils/network.py

1-1: typing.Union imported but unused

Remove unused import: typing.Union

(F401)


2-2: os imported but unused

Remove unused import: os

(F401)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test (windows-latest)
  • GitHub Check: test (ubuntu-latest)
🔇 Additional comments (7)
tofupilot/client.py (1)

52-53: Excellent security enhancement!

Clearing the API key from memory immediately after setting the authorization header reduces the risk of sensitive credential leakage. This is especially important in case of memory dumps, application crashes, or debugging scenarios.

setup.py (1)

10-10: Correctly removes pytest dependency as part of plugin removal

This change aligns perfectly with the PR objective of removing pytest plugin functionality. Removing the dependency ensures that users don't have unnecessary packages installed.

tofupilot/utils/network.py (5)

9-12: Well-defined retry configuration constants

Good practice to define retry behavior constants at the module level. The comment about reducing the timeout from 60 to 30 seconds is helpful for understanding the change.


15-38: Great implementation of resilient session creation

The create_session function is well-implemented with configurable retry parameters. This improves the robustness of network operations by automatically retrying failed requests with exponential backoff.


40-51: Well-designed timeout decorator

This decorator elegantly adds timeout functionality to request functions without modifying their core logic. The use of functools.wraps properly preserves the function's metadata, which is important for documentation and debugging.


53-53: Good use of global session for connection pooling

Creating a single global session instance allows connection pooling across multiple requests, which improves performance by reusing connections.


55-76: Enhanced secure_request function with proper error handling

The updated function now includes:

  1. Timeout management via the decorator
  2. Connection pooling via the session
  3. Forced SSL verification
  4. Automatic error raising with raise_for_status()

These changes make network requests more secure and resilient.

@Sporarum Sporarum force-pushed the remove-pytest-plugin branch from f33cdff to 3148aa6 Compare May 9, 2025 13:49
@Sporarum
Copy link
Copy Markdown
Contributor

Sporarum commented Aug 8, 2025

Probably outdated, feel free to reopen if not

@Sporarum Sporarum closed this Aug 8, 2025
@upview upview deleted the remove-pytest-plugin branch August 11, 2025 15:04
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.

2 participants