-
Notifications
You must be signed in to change notification settings - Fork 78
Asset library changes with ruff format #2542
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
Draft
ohmayr
wants to merge
2
commits into
asset-library-changes-with-black-isort-format
Choose a base branch
from
asset-library-changes-with-ruff-format
base: asset-library-changes-with-black-isort-format
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,131
−863
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,10 +31,12 @@ | |||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| showcase_version = os.environ.get("SHOWCASE_VERSION", "0.35.0") | ||||||||||||||||||||||||||||||||||||||||
| ADS_TEMPLATES = path.join(path.dirname(__file__), "gapic", "ads-templates") | ||||||||||||||||||||||||||||||||||||||||
| BLACK_VERSION = "black==25.1.0" | ||||||||||||||||||||||||||||||||||||||||
| BLACK_PATHS = ["docs", "gapic", "tests", "test_utils", "noxfile.py", "setup.py"] | ||||||||||||||||||||||||||||||||||||||||
| # exclude golden files and generated protobuf code | ||||||||||||||||||||||||||||||||||||||||
| BLACK_EXCLUDES = "|".join([".*golden.*", ".*pb2.py"]) | ||||||||||||||||||||||||||||||||||||||||
| RUFF_VERSION = "ruff==0.14.14" | ||||||||||||||||||||||||||||||||||||||||
| LINT_PATHS = ["docs", "gapic", "tests", "test_utils", "noxfile.py", "setup.py"] | ||||||||||||||||||||||||||||||||||||||||
| # Ruff uses globs for excludes (different from Black's regex) | ||||||||||||||||||||||||||||||||||||||||
| # .*golden.* -> *golden* | ||||||||||||||||||||||||||||||||||||||||
| # .*pb2.py -> *pb2.py | ||||||||||||||||||||||||||||||||||||||||
| RUFF_EXCLUDES = "*golden*,*pb2.py,*pb2.pyi" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| ALL_PYTHON = ( | ||||||||||||||||||||||||||||||||||||||||
| "3.7", | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -80,6 +82,7 @@ def unit(session): | |||||||||||||||||||||||||||||||||||||||
| path.join("tests", "unit"), | ||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||
| external=True, | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -294,7 +297,7 @@ def showcase_library( | |||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||
| update_service_yaml = _add_python_settings(tmp_dir, python_settings) | ||||||||||||||||||||||||||||||||||||||||
| session.run("python", "-c" f"{update_service_yaml}") | ||||||||||||||||||||||||||||||||||||||||
| session.run("python", f"-c{update_service_yaml}") | ||||||||||||||||||||||||||||||||||||||||
| # END TODO section to remove. | ||||||||||||||||||||||||||||||||||||||||
| if retry_config: | ||||||||||||||||||||||||||||||||||||||||
| session.run( | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -755,14 +758,19 @@ def lint(session): | |||||||||||||||||||||||||||||||||||||||
| Returns a failure if the linters find linting errors or sufficiently | ||||||||||||||||||||||||||||||||||||||||
| serious code quality issues. | ||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||
| session.install("flake8", BLACK_VERSION) | ||||||||||||||||||||||||||||||||||||||||
| session.install("flake8", RUFF_VERSION) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # 2. Check formatting | ||||||||||||||||||||||||||||||||||||||||
| session.run( | ||||||||||||||||||||||||||||||||||||||||
| "black", | ||||||||||||||||||||||||||||||||||||||||
| "ruff", | ||||||||||||||||||||||||||||||||||||||||
| "format", | ||||||||||||||||||||||||||||||||||||||||
| "--check", | ||||||||||||||||||||||||||||||||||||||||
| *BLACK_PATHS, | ||||||||||||||||||||||||||||||||||||||||
| "--extend-exclude", | ||||||||||||||||||||||||||||||||||||||||
| BLACK_EXCLUDES, | ||||||||||||||||||||||||||||||||||||||||
| *LINT_PATHS, | ||||||||||||||||||||||||||||||||||||||||
| "--exclude", | ||||||||||||||||||||||||||||||||||||||||
| RUFF_EXCLUDES, | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # 3. Run Flake8 | ||||||||||||||||||||||||||||||||||||||||
| session.run( | ||||||||||||||||||||||||||||||||||||||||
| "flake8", | ||||||||||||||||||||||||||||||||||||||||
| "gapic", | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -772,11 +780,54 @@ def lint(session): | |||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| @nox.session(python="3.10") | ||||||||||||||||||||||||||||||||||||||||
| def blacken(session): | ||||||||||||||||||||||||||||||||||||||||
| """Run black. Format code to uniform standard.""" | ||||||||||||||||||||||||||||||||||||||||
| session.install(BLACK_VERSION) | ||||||||||||||||||||||||||||||||||||||||
| """Run ruff format. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| DEPRECATED: This session now uses Ruff instead of Black. | ||||||||||||||||||||||||||||||||||||||||
| It formats code style only (indentation, quotes, etc). | ||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||
| session.log( | ||||||||||||||||||||||||||||||||||||||||
| "WARNING: The 'blacken' session is deprecated and will be removed in the next release. Please use 'nox -s format' in the future." | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| session.install(RUFF_VERSION) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # 1. Format Code (Replaces black) | ||||||||||||||||||||||||||||||||||||||||
| # We do NOT run 'ruff check --select I' here, preserving strict parity. | ||||||||||||||||||||||||||||||||||||||||
| session.run( | ||||||||||||||||||||||||||||||||||||||||
| "ruff", | ||||||||||||||||||||||||||||||||||||||||
| "format", | ||||||||||||||||||||||||||||||||||||||||
| "--line-length=88", # Standard Black line length | ||||||||||||||||||||||||||||||||||||||||
| *LINT_PATHS, | ||||||||||||||||||||||||||||||||||||||||
| "--exclude", | ||||||||||||||||||||||||||||||||||||||||
| RUFF_EXCLUDES, | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| @nox.session(python=NEWEST_PYTHON) | ||||||||||||||||||||||||||||||||||||||||
| def format(session): | ||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||
| Run ruff to sort imports and format code. | ||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||
| # 1. Install ruff (skipped automatically if you run with --no-venv) | ||||||||||||||||||||||||||||||||||||||||
| session.install(RUFF_VERSION) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # 2. Run Ruff to fix imports | ||||||||||||||||||||||||||||||||||||||||
| # check --select I: Enables strict import sorting | ||||||||||||||||||||||||||||||||||||||||
| # --fix: Applies the changes automatically | ||||||||||||||||||||||||||||||||||||||||
| session.run( | ||||||||||||||||||||||||||||||||||||||||
| "ruff", | ||||||||||||||||||||||||||||||||||||||||
| "check", | ||||||||||||||||||||||||||||||||||||||||
| "--select", | ||||||||||||||||||||||||||||||||||||||||
| "I", | ||||||||||||||||||||||||||||||||||||||||
| "--fix", | ||||||||||||||||||||||||||||||||||||||||
| "--line-length=88", # Standard Black line length | ||||||||||||||||||||||||||||||||||||||||
| *LINT_PATHS, | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # 3. Run Ruff to format code | ||||||||||||||||||||||||||||||||||||||||
| session.run( | ||||||||||||||||||||||||||||||||||||||||
| "black", | ||||||||||||||||||||||||||||||||||||||||
| *BLACK_PATHS, | ||||||||||||||||||||||||||||||||||||||||
| "--extend-exclude", | ||||||||||||||||||||||||||||||||||||||||
| BLACK_EXCLUDES, | ||||||||||||||||||||||||||||||||||||||||
| "ruff", | ||||||||||||||||||||||||||||||||||||||||
| "format", | ||||||||||||||||||||||||||||||||||||||||
| "--line-length=88", # Standard Black line length | ||||||||||||||||||||||||||||||||||||||||
| *LINT_PATHS, | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
828
to
833
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To avoid formatting generated or golden files, the
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To maintain consistency with other
ruffcommands in this file and to avoid formatting generated or golden files, it's best to add theexcludeflag here as well.