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

Add a new parameter max_width to MyPrettyTable #2426

Merged
merged 10 commits into from
Jul 18, 2024

Conversation

DarkaMaul
Copy link
Contributor

@DarkaMaul DarkaMaul commented Apr 15, 2024

Add a new parameter max_width to MyPrettyTable to enhance its display for CLI usage

This PR adds a max_width parameter to MyPrettyTable to restrict the maximum width of its underlying table.

The value can be an integer, "max" (detect automatically the correct width) or None (no width limit)

The output is better, and will be even better once prettytable will be upgraded to 3.10.1 on PyPi
https://github.com/jazzband/prettytable/releases/tag/3.10.1

Summary by CodeRabbit

  • New Features

    • Table width in MyPrettyTable now dynamically adjusts based on terminal size with the new max_width parameter.
  • Bug Fixes

    • Improved formatting of help information in command-line outputs to ensure proper display.
  • Chores

    • Updated prettytable package requirement to version 3.10.2 for better compatibility and features.

…ay for CLI usage

This PR adds a `max_width` parameter to MyPrettyTable to restrict the maximum width of its underlying table.

The value can be an integer, "max" (detect automatically the correct width) or None (no width limit)
Copy link

coderabbitai bot commented Apr 15, 2024

Warning

Rate limit exceeded

@0xalpharush has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 47 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 12a5888 and a98f68f.

Walkthrough

Walkthrough

The modifications primarily focus on enhancing the MyPrettyTable class and related functionalities within the slither project. Key changes include updating the prettytable package version requirement, refining help text formatting for better display, and adding dynamic width handling in the table representation to adapt based on the terminal size. This improves the overall usability and readability of the output generated by the slither tool.

Changes

Files Change Summary
setup.py Updated the prettytable package version requirement from >=3.3.0 to >=3.10.2.
slither/printers/summary/loc.py Updated the HELP attribute in the LocPrinter class to remove trailing whitespace within the multi-line string.
slither/utils/command_line.py Modified output_printers to clean up multi-line help information before displaying it in a table. Updated output_detectors to include max_width="max" parameter for better formatting.
slither/utils/myprettytable.py Enhanced MyPrettyTable class with a new max_width parameter in the __init__ method, allowing dynamic adjustment based on terminal size. Simplified the make_pretty_table function and updated to_pretty_table method to set maximum table width using the max_width parameter. Added logic to handle the case where terminal size is not available.

Sequence Diagrams

sequenceDiagram
    participant User
    participant CommandLine
    participant MyPrettyTable

    User->>CommandLine: Executes command
    CommandLine->>MyPrettyTable: Initializes table with max_width="max"
    MyPrettyTable->>System: Checks terminal size
    System-->>MyPrettyTable: Returns terminal size
    MyPrettyTable->>CommandLine: Prepares table with adjusted width
    CommandLine->>User: Displays formatted table output
Loading
sequenceDiagram
    participant User
    participant CommandLine
    participant LocPrinter

    User->>CommandLine: Requests help information
    CommandLine->>LocPrinter: Fetches HELP attribute
    LocPrinter->>CommandLine: Returns cleaned HELP string
    CommandLine->>User: Displays formatted help information
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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.

@DarkaMaul
Copy link
Contributor Author

I would keep this onhold until prettytable is upgraded upstream.

@0xalpharush 0xalpharush marked this pull request as ready for review June 3, 2024 16:55
@0xalpharush 0xalpharush marked this pull request as draft June 4, 2024 13:10
@DarkaMaul DarkaMaul marked this pull request as ready for review June 11, 2024 12:49
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 and nitpick comments (3)
setup.py (1)

Line range hint 3-3: Remove unnecessary open mode parameters.

- with open("README.md", "r", encoding="utf-8") as f:
+ with open("README.md", encoding="utf-8") as f:
slither/utils/command_line.py (2)

Line range hint 126-126: Convert to not in for membership tests to improve readability.

- if not filter_wiki in detector.WIKI:
+ if filter_wiki not in detector.WIKI:

Also applies to: 240-240


Line range hint 157-157: Consider renaming the variable l to something more descriptive to avoid ambiguity.

- for l in lines:
+ for line in lines:

Also applies to: 171-171

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 02df0dc and dbe67f3.

Files selected for processing (4)
  • setup.py (1 hunks)
  • slither/printers/summary/loc.py (1 hunks)
  • slither/utils/command_line.py (2 hunks)
  • slither/utils/myprettytable.py (5 hunks)
Files skipped from review due to trivial changes (1)
  • slither/printers/summary/loc.py
Additional context used
Ruff
setup.py

3-3: Unnecessary open mode parameters (UP015)

Remove open mode parameters

slither/utils/command_line.py

126-126: Test for membership should be not in (E713)

Convert to not in


157-157: Ambiguous variable name: l (E741)


171-171: Ambiguous variable name: l (E741)


240-240: Test for membership should be not in (E713)

Convert to not in

Additional comments not posted (3)
setup.py (1)

16-16: Update to prettytable version requirement is aligned with the PR's objectives.

slither/utils/myprettytable.py (1)

Line range hint 11-37: The implementation of the max_width parameter in MyPrettyTable is well-handled, including terminal size detection.

slither/utils/command_line.py (1)

275-277: The use of the max_width="max" parameter in output functions aligns with the PR's objectives to improve table formatting.

Also applies to: 359-359

slither/utils/myprettytable.py Show resolved Hide resolved
setup.py Outdated Show resolved Hide resolved
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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dbe67f3 and f533843.

Files selected for processing (1)
  • setup.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • setup.py

setup.py Outdated Show resolved Hide resolved
Co-authored-by: dm <alexis.challande@trailofbits.com>
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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f533843 and 209c23a.

Files selected for processing (1)
  • setup.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • setup.py

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 209c23a and 5623018.

Files selected for processing (2)
  • slither/utils/command_line.py (1 hunks)
  • slither/utils/myprettytable.py (5 hunks)
Additional context used
Ruff
slither/utils/myprettytable.py

2-2: typing.Literal imported but unused

Remove unused import: typing.Literal

(F401)

GitHub Check: Lint Code Base
slither/utils/myprettytable.py

[warning] 2-2:
W0611: Unused Literal imported from typing (unused-import)

Additional comments not posted (5)
slither/utils/myprettytable.py (4)

11-16: LGTM! Ensure clarity of max_width logic.

The addition of the max_width parameter and the logic for setting it based on terminal size is correctly implemented. The comment about reducing terminal columns by 3 is helpful for understanding the logic.


28-36: LGTM! Logic for setting max_width is sound.

The logic for setting max_width based on terminal size is well-implemented and accounts for potential inconsistencies in terminal sizes.


47-48: LGTM! Dynamic table width adjustment.

The changes to the to_pretty_table method ensure that the table width is dynamically adjusted based on the max_width parameter.


85-85: LGTM! Addition of totals row.

The change to add a totals row if the totals parameter is set to True is correctly implemented.

slither/utils/command_line.py (1)

363-364: LGTM! Proper formatting of multi-line help information.

The change to clean up multi-line help information before adding it to the table ensures that the help information is properly formatted when displayed.

@@ -1,4 +1,5 @@
from typing import List, Dict, Union
from shutil import get_terminal_size
from typing import List, Dict, Union, Literal
Copy link

Choose a reason for hiding this comment

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

Remove unused import.

The Literal import from typing is unused and should be removed to clean up the code.

- from typing import List, Dict, Union, Literal
+ from typing import List, Dict, Union
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
from typing import List, Dict, Union, Literal
from typing import List, Dict, Union
Tools
Ruff

2-2: typing.Literal imported but unused

Remove unused import: typing.Literal

(F401)

GitHub Check: Lint Code Base

[warning] 2-2:
W0611: Unused Literal imported from typing (unused-import)

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

Outside diff range, codebase verification and nitpick comments (2)
slither/utils/myprettytable.py (2)

28-35: Clarify the reduction of terminal columns by 3.

Add a comment to explain why the terminal columns are reduced by 3.

+ # Reduce terminal_column by 3 to account for potential padding or margin inconsistencies

48-50: Issue Found: max_table_width Attribute Not Supported by prettytable Library

The max_table_width attribute set in slither/utils/myprettytable.py is not supported by the prettytable library, as there is no evidence of its existence in the library's source code. This could lead to runtime errors.

  • slither/utils/myprettytable.py, line 48-50

Please verify the correct attribute or remove this line if unnecessary.

Analysis chain

LGTM! But verify the usage of max_table_width.

The code changes are approved.

However, ensure that the max_table_width setting is correctly used and supported by the prettytable library.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `max_table_width` in the `prettytable` library.

# Test: Search for the `max_table_width` attribute in the `prettytable` library. Expect: Correct usage and support.
rg --type python -A 5 $'max_table_width'

Length of output: 70


Script:

#!/bin/bash
# Description: Verify the usage of `max_table_width` in the `prettytable` library.

# Test: Search for the `max_table_width` attribute in the `prettytable` library. Expect: Correct usage and support.
rg --type py -A 5 $'max_table_width'

Length of output: 455


Script:

#!/bin/bash
# Description: Verify the usage of `max_table_width` in the `prettytable` library.

# Test: Search for the `max_table_width` attribute in the `prettytable` library source code. Expect: Correct usage and support.
rg --type py -A 5 'max_table_width' $(python3 -c "import prettytable; print(prettytable.__path__[0])")

Length of output: 597


Script:

#!/bin/bash
# Description: Verify the usage of `max_table_width` in the repository.

# Test: Search for the `max_table_width` attribute in the entire repository. Expect: Correct usage and support.
rg --type py -A 5 'max_table_width'

Length of output: 455

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5623018 and 12a5888.

Files selected for processing (1)
  • slither/utils/myprettytable.py (5 hunks)
Additional context used
Ruff
slither/utils/myprettytable.py

2-2: typing.Literal imported but unused

Remove unused import: typing.Literal

(F401)

GitHub Check: Lint Code Base
slither/utils/myprettytable.py

[warning] 2-2:
W0611: Unused Literal imported from typing (unused-import)

Additional comments not posted (5)
slither/utils/myprettytable.py (5)

2-2: Remove unused import.

The Literal import from typing is unused and should be removed to clean up the code.

Tools
Ruff

2-2: typing.Literal imported but unused

Remove unused import: typing.Literal

(F401)

GitHub Check: Lint Code Base

[warning] 2-2:
W0611: Unused Literal imported from typing (unused-import)


38-38: LGTM!

The add_row method is simple and correct.


Line range hint 58-60: LGTM!

The to_json method is simple and correct.

Tools
Ruff

2-2: typing.Literal imported but unused

Remove unused import: typing.Literal

(F401)

GitHub Check: Lint Code Base

[warning] 2-2:
W0611: Unused Literal imported from typing (unused-import)


Line range hint 62-64: LGTM!

The __str__ method is simple and correct.

Tools
Ruff

2-2: typing.Literal imported but unused

Remove unused import: typing.Literal

(F401)

GitHub Check: Lint Code Base

[warning] 2-2:
W0611: Unused Literal imported from typing (unused-import)


86-86: LGTM! But verify the initialization of MyPrettyTable.

The code changes are approved.

However, ensure that the MyPrettyTable initialization is correct and compatible with the new max_width parameter.

@0xalpharush 0xalpharush merged commit 4881519 into dev Jul 18, 2024
83 checks passed
@0xalpharush 0xalpharush deleted the features/max-table-length branch July 18, 2024 14:59
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