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

chore: add ruff linter and code formatter #166

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

evansims
Copy link
Member

Description

This pull request does not include any functionality changes. It introduces a faster and more streamlined linter and code formatted tool and applies some suggested code formatting rules.

Changes include:

  • Updates the linter and code formatting tools used.

    • Adds the ruff linter and code formatted tool.
    • Removes the (now redundant) pyupgrade, isort, autoflake and black tools.
    • Replaces the previous setup.cfg file with a modern pyproject.toml equivalent.
  • Applies improvements suggested by the tool:

    • Whitespace improvements.
    • Removal of unused imports.
    • Adds __all__ definitions to the __init__.py files as a best practice for exposing the SDK's public API to developer IDEs.
  • Fixes a few minor issues in the examples and unit tests I identified while working on updating things:

    • Fixes the examples' setup.py files using incorrect header comment blocks.
    • Fixes minor issues identified in the example apps, like unused variable assignments.
    • Fixes a duplicately named unit test in api_test, which may have caused test_500_error_retry not to be run as intended.
  • Ensures the partial_header block is imported in all Python source files.

References

Please review DXAZT-368 for additional context.

Generated from: openfga/sdk-generator#478

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

@evansims evansims added the styling Issues related to code styling/best practices label Jan 28, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jan 28, 2025

Codecov Report

Attention: Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.

Project coverage is 69.58%. Comparing base (28945cb) to head (2ec56b1).

Files with missing lines Patch % Lines
openfga_sdk/exceptions.py 0.00% 1 Missing ⚠️

❌ Your project status has failed because the head coverage (69.58%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #166      +/-   ##
==========================================
+ Coverage   69.56%   69.58%   +0.01%     
==========================================
  Files         135      135              
  Lines       10857    10864       +7     
==========================================
+ Hits         7553     7560       +7     
  Misses       3304     3304              

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

@evansims evansims marked this pull request as ready for review January 28, 2025 01:52
@evansims evansims requested a review from a team as a code owner January 28, 2025 01:52
@@ -31,28 +31,16 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: |
**/setup.cfg
**/pyproject.toml
**/requirements*.txt
**/test-requirements*.txt

- name: Install dependencies
run: pip install -r test-requirements.txt --upgrade pip

- if: matrix.python-version == '3.10'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- if: matrix.python-version == '3.10'
- if: matrix.python-version == '3.10'

Should we make it so that only testing happens on 3.10 and the linting and such run on latest (3.12 in this case?)

Copy link
Member

@rhamzeh rhamzeh Jan 28, 2025

Choose a reason for hiding this comment

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

Same for uploading to Codecov and releasing below

Copy link
Member Author

Choose a reason for hiding this comment

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

👋 Thanks for your review!

Should we make it so that only testing happens on 3.10 and the linting and such run on latest (3.12 in this case?)

It's probably best for us to keep any linters targeting 3.10, as it's our minimum supported target. Running with later versions could potentially result in linter suggestions that leverage language features unavailable in older versions.

In terms of testing, I think there are two significant advantages to running them against our full gauntlet of supported runtimes: avoiding incorporating language features that aren't supported across all our targets and catching potential compatibility issues with dependencies that could be installed differently between those various runtimes.

Same for uploading to Codecov and releasing below

For releasing, it's best to build in an environment configured for the minimum supported runtime version just to guarantee the built package will work as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
styling Issues related to code styling/best practices
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants