Skip to content

Conversation

@Marcusfam-RB
Copy link

@Marcusfam-RB Marcusfam-RB commented May 19, 2025

Integrate Black code formatter across the project

  • Added Black to requirements-lint.txt
  • Created pyproject.toml with Black configuration
  • Added pre-commit requirements file and .pre-commit-config.yaml to enable automatic formatting on commit
  • Updated VS Code settings.json to enable Black as default formatter
  • Applied Black formatting to all Python files

This change is Reviewable

Summary by CodeRabbit

  • New Features

    • Introduced automatic code formatting using the Black formatter, integrated with pre-commit hooks for consistency.
    • Updated project guidelines to require code formatting with Black before commits.
  • Style

    • Reformatted code across multiple files for improved readability and consistency, including line spacing, alignment, and use of trailing commas.
    • Standardized string delimiters in schema definitions.
  • Chores

    • Added configuration files and dependencies for Black and pre-commit tools.
    • Updated VSCode settings to use Black as the default Python formatter.

@coderabbitai
Copy link

coderabbitai bot commented May 19, 2025

Walkthrough

This update introduces Black as the project's standard Python code formatter. It adds configuration files for Black and pre-commit, updates VSCode settings to use Black, modifies linting and pre-commit requirements, and documents formatting requirements in the contributing guidelines. All Python source files are reformatted for consistency, without changing any logic.

Changes

Files/Paths Change Summary
.pre-commit-config.yaml, pyproject.toml, requirements-pre-commit Added configuration for pre-commit and Black formatter, specifying versions and formatting options.
requirements-lint.txt Added Black as a linting dependency alongside flake8.
.vscode/settings.json Changed default Python formatter from autopep8 to Black in VSCode workspace settings.
CONTRIBUTING.md Added a new section detailing Black formatting requirements and pre-commit usage; renumbered subsequent sections.
databases/player_database.py, main.py, models/player_model.py, routes/health_route.py, routes/player_route.py, schemas/player_schema.py, services/player_service.py, tests/player_stub.py, tests/test_main.py Reformatted code for consistency with Black: adjusted whitespace, blank lines, argument alignment, string delimiters, and added trailing commas. No functional or logic changes were made.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant Git
    participant Pre-commit
    participant Black

    Developer->>Git: git commit
    Git->>Pre-commit: Run pre-commit hooks
    Pre-commit->>Black: Format Python files
    Black-->>Pre-commit: Formatted code (if needed)
    Pre-commit-->>Git: Allow or block commit based on formatting
Loading

Possibly related issues

Possibly related PRs

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch feature/black-formatting
  • Post Copyable Unit Tests in Comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests 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

@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)
.pre-commit-config.yaml (1)

6-6: Add newline at end of file
YAML linters expect a trailing newline. Please append an empty line after line 6.

+ 
🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 6-6: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 92c93db and 8d4ffda.

📒 Files selected for processing (15)
  • .pre-commit-config.yaml (1 hunks)
  • .vscode/settings.json (1 hunks)
  • CONTRIBUTING.md (1 hunks)
  • databases/player_database.py (2 hunks)
  • main.py (3 hunks)
  • models/player_model.py (3 hunks)
  • pyproject.toml (1 hunks)
  • requirements-lint.txt (1 hunks)
  • requirements-pre-commit (1 hunks)
  • routes/health_route.py (1 hunks)
  • routes/player_route.py (9 hunks)
  • schemas/player_schema.py (2 hunks)
  • services/player_service.py (5 hunks)
  • tests/player_stub.py (2 hunks)
  • tests/test_main.py (16 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/test_main.py (2)
tests/player_stub.py (3)
  • existing_player (33-49)
  • nonexistent_player (52-68)
  • unknown_player (71-81)
tests/conftest.py (1)
  • client (11-22)
🪛 YAMLlint (1.37.1)
.pre-commit-config.yaml

[error] 6-6: no new line character at the end of file

(new-line-at-end-of-file)

🪛 Ruff (0.11.9)
routes/player_route.py

45-45: Do not perform function call Body in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


46-46: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


76-76: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


105-105: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


135-135: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


169-169: Do not perform function call Body in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


170-170: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


201-201: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (36)
routes/health_route.py (1)

7-12: Formatting changes applied by Black.
Blank lines were added before and after the import statement and before the route decorator to conform with the Black formatter’s default spacing rules.

requirements-pre-commit (1)

1-1: Add pre-commit dependency.
Pinning pre-commit==4.2.0 ensures the Git hook framework is consistently installed across environments.

schemas/player_schema.py (1)

34-40: Update SQLAlchemy column naming delimiters.
String delimiters for the name parameter in Column(...) calls have been converted from single to double quotes, aligning with Black’s default string normalization. No functional behavior was altered.

.vscode/settings.json (1)

11-11: Set Black as the default VSCode formatter.
The workspace setting for Python formatting has been updated to use ms-python.black-formatter on save, matching the project’s new formatting standard.

pyproject.toml (1)

1-3: Add Black configuration to pyproject.toml.
Defined Black’s settings (line length 88, target Python 3.12) to drive consistent formatting via CLI and editor integrations.

requirements-lint.txt (1)

2-2: Add Black to lint requirements.
The addition of black==25.1.0 complements the existing flake8 dependency and enables automatic code formatting as intended.

tests/player_stub.py (2)

18-18: Add trailing comma for Black compliance.
The trailing comma on starting11=None aligns with Black’s style for multi-line argument lists.


80-80: Add trailing comma for Black compliance.
Including a comma after position="Lipsum", ensures consistency with Black’s default formatting.

databases/player_database.py (3)

11-11: Insert blank line after module docstring.
A blank line was added following the docstring, improving separation and matching Black’s formatting rules.


25-25: Reformat create_async_engine call.
Black consolidated the arguments onto a single line without altering functionality, enhancing conciseness.


29-29: Reformat sessionmaker instantiation.
The inline formatting of sessionmaker(...) follows Black’s conventions for cleaner code style.

services/player_service.py (4)

14-14: Add blank line after module docstring.
This blank line separation is consistent with Black’s default layout between docstrings and imports.


46-46: Insert blank line for section separation.
Black formatted a blank line after the function’s closing docstring to delineate sections clearly.


82-84: Split long function signature per Black style.
The retrieve_by_squad_number_async signature is now broken into multiple lines, adhering to Black’s line-length and readability rules.


100-100: Add blank line before next section.
A blank line was introduced to separate the retrieve and update sections, matching Black’s formatting.

models/player_model.py (3)

9-9: Insert blank line after module docstring.
This blank line placement aligns with Black’s standard for spacing between docstring and imports.


28-28: Add blank line before class attribute.
Separates the class-level docstring from the model_config attribute, consistent with Black’s formatting.


49-49: Add blank line before field definitions.
Improves readability by inserting a blank line between the PlayerModel docstring and its field declarations, per Black’s style.

main.py (3)

10-10: Approve blank line after module docstring
The added blank line after the docstring improves separation between documentation and imports, enhancing readability.


21-22: Approve blank line before lifespan handler
Inserting a blank line before the @asynccontextmanager decorator cleanly separates lifecycle logic from global setup.


31-36: Approve multi-line FastAPI instantiation
Reformatting the FastAPI constructor to multi-line promotes clarity and aligns with the Black configuration. No logic was changed.

CONTRIBUTING.md (1)

47-53: Approve new "6. Formatting" section
The guidelines clearly mandate Black as the standard formatter and recommend setting up a pre-commit hook. This aligns perfectly with the rest of the PR.

.pre-commit-config.yaml (2)

1-6: Approve pre-commit configuration for Black
Pinning Black to 25.1.0 and configuring the hook ensures consistent formatting on every commit.

🧰 Tools
🪛 YAMLlint (1.37.1)

[error] 6-6: no new line character at the end of file

(new-line-at-end-of-file)


2-4: Verify Python language version alignment
The hook uses language_version: python3.13.3 but pyproject.toml targets Python 3.12. Ensure the pre-commit environment matches the supported Python runtime (or update one of the configurations).

routes/player_route.py (10)

19-19: Approve blank line after module docstring
The inserted blank line enhances readability by separating the top-level documentation from code.


32-33: Approve constant separation
Adding a blank line between CACHE_KEY and CACHE_TTL groups related constants clearly.


42-42: Approve trailing comma on decorator tags argument
Including a trailing comma is consistent with Black's style and future-proofs against adding more tags.


45-46: Approve multi-line post_async signature formatting
Splitting the Body and Depends parameters onto separate lines improves readability without changing functionality.

🧰 Tools
🪛 Ruff (0.11.9)

45-45: Do not perform function call Body in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


46-46: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


75-76: Approve multi-line get_all_async signature formatting
Aligning parameters on their own line follows the Black formatter's conventions.

🧰 Tools
🪛 Ruff (0.11.9)

76-76: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


101-101: Approve trailing comma on get_by_id_async decorator tags
Consistent use of trailing commas in decorator arguments improves diff friendliness.


105-105: Approve trailing comma on get_by_id_async dependency
Maintains consistency in argument list formatting across functions.

🧰 Tools
🪛 Ruff (0.11.9)

105-105: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


135-135: Approve trailing comma on get_by_squad_number_async dependency
Helps keep argument formatting consistent and aligned.

🧰 Tools
🪛 Ruff (0.11.9)

135-135: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


169-170: Approve multi-line put_async signature formatting
Separating Body and Depends parameters onto individual lines improves clarity.

🧰 Tools
🪛 Ruff (0.11.9)

169-169: Do not perform function call Body in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


170-170: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


201-201: Approve trailing comma on delete_async dependency
Consistent formatting for function parameters, no behavior change.

🧰 Tools
🪛 Ruff (0.11.9)

201-201: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)

tests/test_main.py (2)

18-18: Approve blank line after module-level docstring
Separating the file docstring from imports/tests with a blank line enhances readability.


27-29: Approve multi-line test function signatures
Reformatting the test definitions to place client on its own line and align docstrings is consistent with Black formatting and does not alter any assertions or logic.

Also applies to: 45-47, 61-63, 78-80, 92-94, 113-115, 129-131, 145-147, 165-167, 181-183, 197-199, 217-219, 233-235, 250-252, 270-272, 287-289, 305-307, 344-346

@nanotaboada nanotaboada linked an issue May 20, 2025 that may be closed by this pull request
@codecov
Copy link

codecov bot commented May 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.65%. Comparing base (92c93db) to head (8d4ffda).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #368   +/-   ##
=======================================
  Coverage   89.65%   89.65%           
=======================================
  Files           3        3           
  Lines         116      116           
=======================================
  Hits          104      104           
  Misses         12       12           
Components Coverage Δ
Services 79.31% <100.00%> (ø)
Routes 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nanotaboada
Copy link
Owner

Thanks for this contribution @Marcusfam-RB! 🙌

The changes look great — clean, thoughtful, and very well put together. I’ve added a couple of review comments just to clarify a few details, but overall everything looks solid and really well aligned with the project.

Appreciate the attention to detail here — great work so far! 💯

@sonarqubecloud
Copy link

@nanotaboada
Copy link
Owner

Thanks again for this contribution @Marcusfam-RB — it's clear you've put in solid effort and your changes are mostly spot on. I left a few review comments a few days ago that still need to be addressed.

Since it's been a bit quiet, I'm going to close this PR for now to avoid it lingering indefinitely. That said, I really appreciate your work — I’ll incorporate your changes (along with the requested tweaks) in a follow-up commit so your effort still makes it into the project.

If you'd like to revisit this in the future, feel free to re-open or submit a new PR. Thanks again!

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.

Introduce black as the standard Python code formatter

2 participants