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

Added python script linting #3264

Merged
merged 5 commits into from
Jan 12, 2025

Conversation

palisadoes
Copy link
Contributor

@palisadoes palisadoes commented Jan 12, 2025

What kind of change does this PR introduce?

Added python script linting

Issue Number:

  • N/A

Snapshots/Videos:

  • N/A

If relevant, did you update the documentation?

  • N/A

Summary

Added linting to ensure standardization in the python scripts we use in the repository

Does this PR introduce a breaking change?

  • N/A

Other information

  • N/A

Have you read the contributing guide?

Summary by CodeRabbit

  • New Features

    • Added Python code quality checks to GitHub Actions workflow.
    • Introduced a script for validating Python docstrings against the Google style guide.
    • Added configuration for code formatting tools (Black, Flake8, pydocstyle).
  • Documentation

    • Improved docstring standards and documentation checks across multiple scripts.
    • Added configuration files for code style and linting.
  • Chores

    • Updated GitHub Actions workflow to include Python compliance checks.
    • Added requirements for code quality tools.
    • Removed an obsolete script for Markdown formatting.
    • Updated ESLint configuration to ignore specific files.

@palisadoes palisadoes added the ignore-sensitive-files-pr The contributor has a legitimate reason for editiing protected files label Jan 12, 2025
Copy link
Contributor

coderabbitai bot commented Jan 12, 2025

Warning

Rate limit exceeded

@palisadoes has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 28 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

Reviewing files that changed from the base of the PR and between 83cc020 and ef9bb34.

📒 Files selected for processing (1)
  • .github/workflows/scripts/check_docstrings.py (1 hunks)

Walkthrough

This pull request introduces comprehensive code quality and style enforcement mechanisms for Python projects. It adds configuration files for tools like Flake8, Black, and pydocstyle to standardize code formatting and documentation. A new GitHub Actions workflow job called Python-Compliance is created to automatically check code style, docstring compliance, and formatting. Additionally, a custom Python script check_docstrings.py is added to validate docstrings against the Google style guide.

Changes

File Change Summary
.flake8 Added configuration to ignore specific linting errors and set max line length to 80
.github/workflows/pull-request.yml Added new Python-Compliance job for Python code style checks
.github/workflows/requirements.txt Added dependencies for code quality tools like Black, Flake8, pydocstyle
.github/workflows/scripts/check_docstrings.py New script to validate Python docstrings against Google style guide
.github/workflows/scripts/code_coverage_disable_check.py Updated docstring formatting and argument descriptions
.github/workflows/scripts/compare_translations.py Enhanced documentation and readability improvements
.github/workflows/scripts/countline.py Minor textual modifications in comments
.github/workflows/scripts/eslint_disable_check.py Updated docstring formatting for clarity
.github/workflows/scripts/talawa_admin_md_mdx_format_adjuster.py Deleted script for Markdown compatibility with MDX
.pydocstyle Added configuration to use Google style guide and ignore specific docstring errors
pyproject.toml Added Black formatter configuration with 79-character line length
.eslintrc.json Added pyproject.toml to ignore patterns during linting

Suggested labels

test

Suggested reviewers

  • noman2002
  • varshith257

Poem

🐰 Code quality hops along,
With Flake8 and Black's sweet song,
Docstrings dancing, neat and bright,
Our rabbit's workflow shines just right!
Compliance leaps from line to line! 🌈


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>, 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. (Beta)
  • @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.

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

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link
Contributor

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

🧹 Nitpick comments (10)
.github/workflows/scripts/check_docstrings.py (2)

53-54: Simplify nested if statements into a single condition

At lines 53-54, the nested if statements can be combined into a single if statement for better readability.

Apply this diff to simplify the code:

-    if bool(decorator):
-        if decorator_in_docstring_exception_list(decorator):
+    if decorator and decorator_in_docstring_exception_list(decorator):
🧰 Tools
🪛 Ruff (0.8.2)

53-54: Use a single if statement instead of nested if statements

(SIM102)


240-283: Consider using the ast module for robust function parsing

The extract_function_arguments function manually parses function definitions using string manipulation, which may not handle complex cases like decorators, annotations, or multiline definitions.

Refactor the function to use the ast module for accurate parsing. Here's an example:

import ast

def extract_function_arguments(start, lines):
    Function = namedtuple("Function", "name arguments")
    function_code = ''.join(lines[start:])
    try:
        node = ast.parse(function_code)
        for elem in node.body:
            if isinstance(elem, ast.FunctionDef):
                arguments = [arg.arg for arg in elem.args.args if arg.arg not in ('self', 'cls')]
                return Function(name=elem.name, arguments=arguments)
    except SyntaxError:
        pass
    return Function(name='', arguments=[])

This approach ensures that all function definitions are parsed correctly, improving maintainability and reducing errors.

.github/workflows/scripts/eslint_disable_check.py (2)

105-106: Omit Args section when there are no arguments

In the arg_parser_resolver() function's docstring (lines 105-106), you include Args: None. According to the Google Python Style Guide, you can omit the Args section if the function doesn't accept any arguments.

Apply this diff to simplify the docstring:

-        Args: None

Line range hint 131-160: Remove unnecessary Args and Returns sections

In the main() function's docstring (lines 131-160), the Args: None and Returns: None sections are not needed and can be omitted for brevity.

Apply this diff to clean up the docstring:

-    Args:
-        None
-
-    Returns:
-        None
-
.github/workflows/scripts/code_coverage_disable_check.py (2)

118-120: Omit Args section when no arguments are present

In arg_parser_resolver() function's docstring (lines 118-120), you include Args: with no arguments listed. It's recommended to omit this section if there are no arguments.

Apply this diff:

-        Args:
-            None

Line range hint 145-160: Remove unnecessary Args and Returns sections

The main() function's docstring (lines 145-160) includes Args: None and Returns: None, which are unnecessary when there are no arguments or return values.

Apply this diff to streamline the docstring:

-        Args:
-            None
-
-        Returns:
-            None
.github/workflows/scripts/compare_translations.py (2)

Line range hint 1-51: Improve module docstring structure.

The docstring structure could be enhanced by:

  1. Moving implementation details from "Methodology" to a new "Implementation" section
  2. Removing the redundant "Note" section about compliance standards
 """Script to encourage more efficient coding practices.

 Methodology:
-    Utility for comparing translations between default and other languages.
+    This utility ensures consistency across language translations by comparing
+    translation files against a default language file.
+
+Implementation:
     This module defines a function to compare two translations
     and print any missing keys in the other language's translation.

 Attributes:
     FileTranslation : Named tuple to represent a combination
                         of file and missing translations.
...
-Note:
-    This script complies with our python3 coding and documentation standards
-    and should be used as a reference guide. It complies with:
-
-        1) Pylint
-        2) Pydocstyle
-        3) Pycodestyle
-        4) Flake8
"""
🧰 Tools
🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch

[warning] 1-1:
File ignored by default.


87-89: Simplify error message formatting.

The error messages use unnecessary backslash line continuation. F-strings can span multiple lines within parentheses.

-            error_msg = f"""\
-Missing Key: '{key}' - This key from '{default_file}' \
-is missing in '{other_file}'."""
+            error_msg = (
+                f"Missing Key: '{key}' - This key from '{default_file}' "
+                f"is missing in '{other_file}'"
+            )

-            error_msg = f"""\
-Error Key: '{key}' - This key in '{other_file}' \
-does not match any key in '{default_file}'."""
+            error_msg = (
+                f"Error Key: '{key}' - This key in '{other_file}' "
+                f"does not match any key in '{default_file}'"
+            )

Also applies to: 95-97

.github/workflows/pull-request.yml (1)

491-493: Expand Flake8 check scope.

The Flake8 check is currently limited to the .github directory. Consider expanding it to check all Python files in the repository.

-          flake8 --docstring-convention google --ignore E402,E722,E203,F401,W503 .github
+          flake8 --docstring-convention google --ignore E402,E722,E203,F401,W503 .
.pydocstyle (1)

1-3: Consider enforcing D415 for better docstring quality.

D415 ensures that the first line of docstrings ends with a period, which promotes proper sentence structure. Consider removing it from the ignore list unless there's a specific reason to ignore it.

 [pydocstyle]
 convention=google
-add-ignore=D415,D205
+add-ignore=D205
🧰 Tools
🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch

[warning] 1-1:
File ignored by default.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 99fd263 and 6ffca5e.

📒 Files selected for processing (11)
  • .flake8 (1 hunks)
  • .github/workflows/pull-request.yml (2 hunks)
  • .github/workflows/requirements.txt (1 hunks)
  • .github/workflows/scripts/check_docstrings.py (1 hunks)
  • .github/workflows/scripts/code_coverage_disable_check.py (9 hunks)
  • .github/workflows/scripts/compare_translations.py (9 hunks)
  • .github/workflows/scripts/countline.py (1 hunks)
  • .github/workflows/scripts/eslint_disable_check.py (6 hunks)
  • .github/workflows/scripts/talawa_admin_md_mdx_format_adjuster.py (0 hunks)
  • .pydocstyle (1 hunks)
  • pyproject.toml (1 hunks)
💤 Files with no reviewable changes (1)
  • .github/workflows/scripts/talawa_admin_md_mdx_format_adjuster.py
✅ Files skipped from review due to trivial changes (2)
  • pyproject.toml
  • .github/workflows/scripts/countline.py
🧰 Additional context used
🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch
.github/workflows/requirements.txt

[warning] 1-1:
File ignored by default.

.github/workflows/scripts/check_docstrings.py

[warning] 1-1:
File ignored by default.

.flake8

[warning] 1-1:
File ignored by default.

.pydocstyle

[warning] 1-1:
File ignored by default.

🪛 GitHub Actions: PR Workflow
.github/workflows/requirements.txt

[warning] File ignored by default. Use a negated ignore pattern (like "--ignore-pattern '!<relative/path/to/filename>'")

.github/workflows/pull-request.yml

[warning] File ignored by default. Use a negated ignore pattern (like "--ignore-pattern '!<relative/path/to/filename>'")

.github/workflows/scripts/eslint_disable_check.py

[warning] File ignored by default. Use a negated ignore pattern (like "--ignore-pattern '!<relative/path/to/filename>'")

.github/workflows/scripts/compare_translations.py

[warning] File ignored by default. Use a negated ignore pattern (like "--ignore-pattern '!<relative/path/to/filename>'")

.github/workflows/scripts/code_coverage_disable_check.py

[warning] File ignored by default. Use a negated ignore pattern (like "--ignore-pattern '!<relative/path/to/filename>'")

.github/workflows/scripts/check_docstrings.py

[warning] File ignored by default. Use a negated ignore pattern (like "--ignore-pattern '!<relative/path/to/filename>'")

.flake8

[warning] File ignored by default. Use a negated ignore pattern (like "--ignore-pattern '!<relative/path/to/filename>'")

.pydocstyle

[warning] File ignored by default. Use a negated ignore pattern (like "--ignore-pattern '!<relative/path/to/filename>'")

🪛 actionlint (1.7.4)
.github/workflows/pull-request.yml

468-468: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🪛 Ruff (0.8.2)
.github/workflows/scripts/check_docstrings.py

53-54: Use a single if statement instead of nested if statements

(SIM102)


138-138: Loop control variable argument_function not used within loop body

(B007)


162-162: Loop control variable argument_docstring not used within loop body

(B007)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyse Code With CodeQL (javascript)
🔇 Additional comments (2)
.flake8 (2)

3-3: The max line length of 80 characters is reasonable.

Setting max-line-length to 80 characters is a widely accepted standard that:

  • Ensures code readability across different environments
  • Allows side-by-side file comparison
  • Works well with most terminal windows

1-3: Consider documenting and reviewing ignored error codes.

While ignoring certain Flake8 errors can be necessary, some of the ignored codes could hide important issues:

  • E722: Ignoring bare except clauses can mask errors and complicate debugging
  • F401: Ignoring unused imports can lead to code bloat

Consider:

  1. Documenting the rationale for each ignored error code in comments
  2. Gradually addressing these issues in the codebase instead of ignoring them
  3. Only ignoring specific error codes where absolutely necessary

Let's check the codebase for instances of bare except clauses and unused imports:

🧰 Tools
🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch

[warning] 1-1:
File ignored by default.

Comment on lines +138 to +157
for argument_function in arguments_function:
# Track whether the argument is defined
# in the docstring parameters
for argument_docstring in arguments_docstring:
if argument_docstring not in arguments_function:
violations.append(
Violation(
line=line_number + 1,
function=function.name,
issue=f"""\
Argument '{argument_docstring}' defined in the docstring is not \
an argument in the function""",
action=f"""\
Remove argument '{argument_docstring}' from the docstring""",
)
)
bad_argument_function = True
break
if bad_argument_function:
break
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unused loop variable argument_function

The loop variable argument_function at line 138 is not used within the loop body, which may lead to confusion.

Apply this diff to fix the issue:

-        for argument_function in arguments_function:
+        for _ in arguments_function:

Alternatively, refactor the code to remove the unnecessary loop if it's not needed.

📝 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
for argument_function in arguments_function:
# Track whether the argument is defined
# in the docstring parameters
for argument_docstring in arguments_docstring:
if argument_docstring not in arguments_function:
violations.append(
Violation(
line=line_number + 1,
function=function.name,
issue=f"""\
Argument '{argument_docstring}' defined in the docstring is not \
an argument in the function""",
action=f"""\
Remove argument '{argument_docstring}' from the docstring""",
)
)
bad_argument_function = True
break
if bad_argument_function:
break
for _ in arguments_function:
# Track whether the argument is defined
# in the docstring parameters
for argument_docstring in arguments_docstring:
if argument_docstring not in arguments_function:
violations.append(
Violation(
line=line_number + 1,
function=function.name,
issue=f"""\
Argument '{argument_docstring}' defined in the docstring is not \
an argument in the function""",
action=f"""\
Remove argument '{argument_docstring}' from the docstring""",
)
)
bad_argument_function = True
break
if bad_argument_function:
break
🧰 Tools
🪛 Ruff (0.8.2)

138-138: Loop control variable argument_function not used within loop body

(B007)

Comment on lines +162 to +181
for argument_docstring in arguments_docstring:
# Track whether the argument is defined
# in the function parameters
for argument_function in arguments_function:
if argument_function not in arguments_docstring:
violations.append(
Violation(
line=line_number + 1,
function=function.name,
issue=f"""\
Argument '{argument_function}' defined in the function is not \
an argument in the docstring""",
action=f"""\
Add argument '{argument_function}' to the Docstring""",
)
)
bad_argument_docstring = True
break
if bad_argument_docstring:
break
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove unused loop variable argument_docstring

Similarly, at line 162, the loop variable argument_docstring is not used within the loop body.

Apply this diff to fix the issue:

-        for argument_docstring in arguments_docstring:
+        for _ in arguments_docstring:

Consider adjusting the logic to utilize the loop variable appropriately or eliminate the loop if it's unnecessary.

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 Ruff (0.8.2)

162-162: Loop control variable argument_docstring not used within loop body

(B007)

Comment on lines +10 to +14
black
pydocstyle
flake8
flake8-docstrings
docstring_parser
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Pin package versions for reproducible builds.

Dependencies should have version constraints to ensure reproducible builds and avoid breaking changes.

-black
-pydocstyle 
-flake8
-flake8-docstrings
-docstring_parser
+black==24.1.1
+pydocstyle==6.3.0
+flake8==7.0.0
+flake8-docstrings==1.7.0
+docstring_parser==0.15
📝 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
black
pydocstyle
flake8
flake8-docstrings
docstring_parser
black==24.1.1
pydocstyle==6.3.0
flake8==7.0.0
flake8-docstrings==1.7.0
docstring_parser==0.15

Comment on lines +467 to +470
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.11
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Update setup-python action to latest version.

The setup-python action version is outdated.

-        uses: actions/setup-python@v4
+        uses: actions/setup-python@v5
         with:
           python-version: 3.11
📝 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
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
🧰 Tools
🪛 actionlint (1.7.4)

468-468: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

Copy link

codecov bot commented Jan 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.27%. Comparing base (99fd263) to head (ef9bb34).
Report is 1 commits behind head on develop-postgres.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #3264       +/-   ##
=====================================================
+ Coverage              8.49%   90.27%   +81.78%     
=====================================================
  Files                   309      330       +21     
  Lines                  7831     8491      +660     
  Branches               1730     1875      +145     
=====================================================
+ Hits                    665     7665     +7000     
+ Misses                 7092      598     -6494     
- Partials                 74      228      +154     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

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

🧹 Nitpick comments (1)
.github/workflows/scripts/check_docstrings.py (1)

201-206: Simplify decorator check logic.

The nested if statements can be combined for better readability.

Apply this diff to simplify the code:

-    if start > 0:
-        previous_line = lines[start - 1].strip()
-        if previous_line.startswith("@"):
-            result = previous_line
+    result = lines[start - 1].strip() if start > 0 and lines[start - 1].strip().startswith("@") else None
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b24349e and 83cc020.

📒 Files selected for processing (2)
  • .github/workflows/pull-request.yml (2 hunks)
  • .github/workflows/scripts/check_docstrings.py (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/pull-request.yml

468-468: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🪛 Ruff (0.8.2)
.github/workflows/scripts/check_docstrings.py

53-54: Use a single if statement instead of nested if statements

(SIM102)


138-138: Loop control variable argument_function not used within loop body

(B007)


162-162: Loop control variable argument_docstring not used within loop body

(B007)

🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch
.github/workflows/scripts/check_docstrings.py

[warning] 1-1:
File ignored by default.

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test Application
  • GitHub Check: Analyse Code With CodeQL (javascript)
🔇 Additional comments (4)
.github/workflows/pull-request.yml (3)

99-101: LGTM! Python linting configuration files added to sensitive files list.

The Python linting configuration files are correctly added to the list of sensitive files that require authorization for changes.


457-461: LGTM! Python-Compliance job correctly configured.

The job is properly integrated into the workflow with appropriate dependencies.


467-470: Update setup-python action to latest version.

The setup-python action version is outdated.

Apply this diff to update the action:

-        uses: actions/setup-python@v4
+        uses: actions/setup-python@v5
         with:
           python-version: 3.11
🧰 Tools
🪛 actionlint (1.7.4)

468-468: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

.github/workflows/scripts/check_docstrings.py (1)

1-11: LGTM! Script header and imports are well-structured.

The script has appropriate imports and a clear namedtuple definition for violations.

🧰 Tools
🪛 GitHub Check: Performs linting, formatting, type-checking, checking for different source and target branch

[warning] 1-1:
File ignored by default.

default=".",
nargs="+",
type=str,
help="Directory where the cache files are located.",
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix CLI argument help message.

The help message incorrectly refers to cache files instead of describing the directory to scan for Python files.

Apply this diff to fix the help message:

-        help="Directory where the cache files are located.",
+        help="Directories to scan for Python files to check docstring compliance.",
📝 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
help="Directory where the cache files are located.",
help="Directories to scan for Python files to check docstring compliance.",

Comment on lines +137 to +182
# Check whether docstring arguments match function arguments
for argument_function in arguments_function:
# Track whether the argument is defined
# in the docstring parameters
for argument_docstring in arguments_docstring:
if argument_docstring not in arguments_function:
violations.append(
Violation(
line=line_number + 1,
function=function.name,
issue=f"""\
Argument '{argument_docstring}' defined in the docstring is not \
an argument in the function""",
action=f"""\
Remove argument '{argument_docstring}' from the docstring""",
)
)
bad_argument_function = True
break
if bad_argument_function:
break

# We found an error, no need to continue generating violations
if not bad_argument_function:
# Check whether docstring arguments match function arguments
for argument_docstring in arguments_docstring:
# Track whether the argument is defined
# in the function parameters
for argument_function in arguments_function:
if argument_function not in arguments_docstring:
violations.append(
Violation(
line=line_number + 1,
function=function.name,
issue=f"""\
Argument '{argument_function}' defined in the function is not \
an argument in the docstring""",
action=f"""\
Add argument '{argument_function}' to the Docstring""",
)
)
bad_argument_docstring = True
break
if bad_argument_docstring:
break

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Simplify nested loops and fix unused variables.

The nested loops can be simplified, and there are unused loop variables that should be addressed.

Apply this diff to improve the code:

-    for argument_function in arguments_function:
-        # Track whether the argument is defined
-        # in the docstring parameters
-        for argument_docstring in arguments_docstring:
+    # Check for arguments in docstring that aren't in function
+    for argument_docstring in arguments_docstring:
+        if argument_docstring not in arguments_function:
+            violations.append(
+                Violation(
+                    line=line_number + 1,
+                    function=function.name,
+                    issue=f"Argument '{argument_docstring}' defined in the docstring is not an argument in the function",
+                    action=f"Remove argument '{argument_docstring}' from the docstring",
+                )
+            )
+            break

+    # Check for arguments in function that aren't in docstring
+    for argument_function in arguments_function:
+        if argument_function not in arguments_docstring:
+            violations.append(
+                Violation(
+                    line=line_number + 1,
+                    function=function.name,
+                    issue=f"Argument '{argument_function}' defined in the function is not an argument in the docstring",
+                    action=f"Add argument '{argument_function}' to the Docstring",
+                )
+            )
+            break
📝 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
# Check whether docstring arguments match function arguments
for argument_function in arguments_function:
# Track whether the argument is defined
# in the docstring parameters
for argument_docstring in arguments_docstring:
if argument_docstring not in arguments_function:
violations.append(
Violation(
line=line_number + 1,
function=function.name,
issue=f"""\
Argument '{argument_docstring}' defined in the docstring is not \
an argument in the function""",
action=f"""\
Remove argument '{argument_docstring}' from the docstring""",
)
)
bad_argument_function = True
break
if bad_argument_function:
break
# We found an error, no need to continue generating violations
if not bad_argument_function:
# Check whether docstring arguments match function arguments
for argument_docstring in arguments_docstring:
# Track whether the argument is defined
# in the function parameters
for argument_function in arguments_function:
if argument_function not in arguments_docstring:
violations.append(
Violation(
line=line_number + 1,
function=function.name,
issue=f"""\
Argument '{argument_function}' defined in the function is not \
an argument in the docstring""",
action=f"""\
Add argument '{argument_function}' to the Docstring""",
)
)
bad_argument_docstring = True
break
if bad_argument_docstring:
break
# Check for arguments in docstring that aren't in function
for argument_docstring in arguments_docstring:
if argument_docstring not in arguments_function:
violations.append(
Violation(
line=line_number + 1,
function=function.name,
issue=f"Argument '{argument_docstring}' defined in the docstring is not an argument in the function",
action=f"Remove argument '{argument_docstring}' from the docstring",
)
)
break
# Check for arguments in function that aren't in docstring
for argument_function in arguments_function:
if argument_function not in arguments_docstring:
violations.append(
Violation(
line=line_number + 1,
function=function.name,
issue=f"Argument '{argument_function}' defined in the function is not an argument in the docstring",
action=f"Add argument '{argument_function}' to the Docstring",
)
)
break
🧰 Tools
🪛 Ruff (0.8.2)

138-138: Loop control variable argument_function not used within loop body

(B007)


162-162: Loop control variable argument_docstring not used within loop body

(B007)

@palisadoes palisadoes merged commit d3657e1 into PalisadoesFoundation:develop-postgres Jan 12, 2025
18 of 19 checks passed
@palisadoes palisadoes deleted the lint branch January 12, 2025 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ignore-sensitive-files-pr The contributor has a legitimate reason for editiing protected files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant