Skip to content

chore(lint): Update Ruff config to match yscope-dev-utils and resolve resulting lint issues. - #173

Merged
LinZhihao-723 merged 42 commits into
y-scope:mainfrom
sitaowang1998:python_lint
Aug 5, 2025
Merged

chore(lint): Update Ruff config to match yscope-dev-utils and resolve resulting lint issues.#173
LinZhihao-723 merged 42 commits into
y-scope:mainfrom
sitaowang1998:python_lint

Conversation

@sitaowang1998

@sitaowang1998 sitaowang1998 commented Aug 4, 2025

Copy link
Copy Markdown
Collaborator

Description

Note

This PR depends on #166.

This PR:

  • Updates yscope-dev-utils to include new python linting configs.
  • Adds latest ruff.toml from yscope-dev-utils.
  • Adds special treatment for python integration tests in ruff.toml
  • Updates lint tasks to mirror that in yscope-dev-utils.
  • Updates tests files to fix the python linting errors.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  • Python linting and formatting tests pass.
  • GitHub workflows pass.

Summary by CodeRabbit

  • Documentation

    • Added comprehensive docstrings and type annotations to integration tests and utility files for improved clarity and maintainability.
    • Enhanced configuration documentation for linting and formatting rules.
  • Style

    • Updated code style enforcement by expanding linting coverage, refining ignored rules, and removing reliance on Black in favour of Ruff.
  • Chores

    • Updated development dependencies and configuration files, including removal of Black and updating subproject references.
    • Refined linting tasks to separate checking and formatting flags, simplifying commands and removing directory changes.

sitaowang1998 and others added 30 commits July 15, 2025 13:40
Co-authored-by: Lin Zhihao <59785146+LinZhihao-723@users.noreply.github.com>
…ider into dep-concurrency"

This reverts commit 1769c95, reversing
changes made to 90aa5a2.
@sitaowang1998 sitaowang1998 changed the title feat(lin): Update ruff python linting from yscope-dev-utils. feat(lint): Update ruff python linting from yscope-dev-utils. Aug 4, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (4)
lint-tasks.yaml (4)

62-65: Reuse the cpp_source_files anchor in other tasks to avoid silent drift

&cpp_source_files is defined here but later the same list is repeated verbatim (Lines 96-97 and 107-108). Referencing the anchor would make future path changes single-point-edits.

-          ROOT_PATHS:
-            - "{{.G_SRC_SPIDER_DIR}}"
-            - "{{.G_TEST_DIR}}"
+          ROOT_PATHS: *cpp_source_files

Same for Lines 107-108.


85-98: Anchor can replace duplicated ROOT_PATHS in cpp-static-check

As noted above, duplicate path literals appear twice inside the cpp-static-check task. Swapping them for *cpp_source_files keeps the task definition short and guarantees both format and static analysis cover identical trees.


114-121: Clarify ruff flags for check vs. fix runs

The current pairing works, but:

  • py-check prints full diffs (--diff), which may add noisy logs; --check is quieter and still fails CI on style violations.
  • py-fix runs ruff format with no flags, which rewrites files in place. If accidental commits of formatted files are a concern, consider --unsafe-fixes or keeping the two-step “check → fix” symmetry.

No action required, just something to weigh.


124-134: Minor: avoid repeated venv activation inside very short loop

The loop currently activates the virtual-env once per ITEM (only one element today). If the list ever grows, wrapping the loop body in a function or hoisting activation outside will save a few process spawns.

Purely optional.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 406b514 and 80f0a10.

📒 Files selected for processing (1)
  • lint-tasks.yaml (3 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: sitaowang1998
PR: y-scope/spider#172
File: build-tasks.yaml:21-45
Timestamp: 2025-08-03T01:49:27.764Z
Learning: In the spider project, external tools like `uv`, Python, and Task are documented as requirements in README.md and are expected to be pre-installed by users rather than bootstrapped by the build system.
📚 Learning: antlr-generated c++ code in the g_src_dsl_dir (src/stdl) should not be included in linting tasks bec...
Learnt from: sitaowang1998
PR: y-scope/spider#168
File: lint-tasks.yaml:62-65
Timestamp: 2025-07-17T19:44:06.132Z
Learning: ANTLR-generated C++ code in the G_SRC_DSL_DIR (src/stdl) should not be included in linting tasks because it's auto-generated code that doesn't follow manual coding standards.

Applied to files:

  • lint-tasks.yaml
🔇 Additional comments (1)
lint-tasks.yaml (1)

48-58: Nice use of YAML anchors to de-duplicate the C++ source list

Introducing the &cpp_lint_source_files anchor and re-using it elsewhere keeps the three C++ lint tasks in sync and eliminates a maintenance hotspot.
👍 No issues spotted.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (2)
lint-tasks.yaml (2)

110-116: Order of operations may suppress the ruff format --diff output

ruff check will exit with a non-zero status when violations are detected. Because the two commands are in the same shell block, the ruff format --diff line on Line 134 will never run once ruff check fails, hiding the formatting diff that the task is meant to surface.
Consider running the format pass first or guarding the second command, e.g.:

-  ruff check {{.RUFF_CHECK_FLAGS}} "{{.ITEM}}"
-  ruff format {{.RUFF_FORMAT_FLAGS}} "{{.ITEM}}"
+  ruff format {{.RUFF_FORMAT_FLAGS}} "{{.ITEM}}"
+  ruff check {{.RUFF_CHECK_FLAGS}} "{{.ITEM}}" || true

This preserves the diff output while still letting the task fail overall on lint errors.


124-127: Minor template quoting nit

The Go-template default function already returns an empty string when the variable is undefined, so escaping the inner quotes is unnecessary noise. Using single quotes makes the expression easier to read:

-  RUFF_CHECK_FLAGS: "{{.RUFF_CHECK_FLAGS | default \"\"}}"
-  RUFF_FORMAT_FLAGS: "{{.RUFF_FORMAT_FLAGS | default \"\"}}"
+  RUFF_CHECK_FLAGS: '{{ .RUFF_CHECK_FLAGS | default "" }}'
+  RUFF_FORMAT_FLAGS: '{{ .RUFF_FORMAT_FLAGS | default "" }}'

Purely cosmetic, but it improves maintainability.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0f13d07 and ea2da33.

📒 Files selected for processing (2)
  • lint-requirements.txt (0 hunks)
  • lint-tasks.yaml (1 hunks)
💤 Files with no reviewable changes (1)
  • lint-requirements.txt
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: lint
  • GitHub Check: non-storage-unit-tests (ubuntu-24.04)
  • GitHub Check: non-storage-unit-tests (ubuntu-22.04)
🔇 Additional comments (1)
lint-tasks.yaml (1)

114-120: Verify that both flag sets are intentionally omitted/passed

py-check sets only RUFF_FORMAT_FLAGS, while py-fix sets only RUFF_CHECK_FLAGS. This means:

py-check lints (no flags) and shows a diff, but never formats.
py-fix fixes lint errors and formats in-place, but never prints a diff.

If that split is deliberate—great. If the intent was to use both flag groups in each task, update the variable blocks accordingly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Directly pushed some changes to this file to polish the docstring. What we should be aware of for the future docstrings to be consistent with our Python docstring guidelines:

  • For the docstring of a class, we just start with "Represents ...". Don't repeat the class name.
    • When u need to refer to a class name, a param name, or a variable name, use "`" to surround the symbols.
  • Docstring for functions should usually start with a verb in the singular form.
  • For parameters' docstring, capitalize the first char (and don't forget "the").
  • For return values' docstring, also capitalize the first char.
  • Don't document the return values if the function returns None.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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)
tests/integration/test_client.py (1)

80-82: Fix docstring formatting.

The docstring should be formatted as a one-liner according to the Ruff warning.

-        """
-        Executes the `client_test` program and checks for successful execution.
-        """
+        """Executes the `client_test` program and checks for successful execution."""
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 62352e5 and bb5d365.

📒 Files selected for processing (4)
  • tests/integration/test_client.py (3 hunks)
  • tests/integration/test_scheduler_worker.py (10 hunks)
  • tests/integration/test_signal.py (5 hunks)
  • tests/integration/utils.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/integration/utils.py
  • tests/integration/test_signal.py
  • tests/integration/test_scheduler_worker.py
🧰 Additional context used
🪛 Ruff (0.12.2)
tests/integration/test_client.py

80-82: One-line docstring should fit on one line

Reformat to one line

(D200)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: non-storage-unit-tests (ubuntu-24.04)
  • GitHub Check: non-storage-unit-tests (ubuntu-22.04)
  • GitHub Check: lint
🔇 Additional comments (7)
tests/integration/test_client.py (7)

1-1: LGTM! Clear module documentation.

The module docstring provides a clear description of the file's purpose.


5-5: LGTM! Appropriate imports for type annotations.

The new imports support the enhanced type annotations used throughout the file. Using collections.abc.Generator is the modern approach preferred over typing.Generator.

Also applies to: 8-8


19-25: LGTM! Improved type annotations and documentation.

The change from Tuple to tuple aligns with modern Python best practices for built-in types. The docstring is comprehensive and well-formatted, clearly documenting parameters and return values.


54-63: LGTM! Well-typed fixture with proper documentation.

The type annotations accurately reflect the fixture's interface. The docstring clearly explains the fixture's lifecycle and purpose. The explicit handling of the unused storage parameter with the ARG001 comment is a good practice for silencing linter warnings while maintaining dependency injection.


76-76: LGTM! Clear class documentation.

The class docstring appropriately describes the test class purpose.


78-79: LGTM! Cleaner test method signature.

Using @pytest.mark.usefixtures instead of accepting the fixture as a parameter results in a cleaner method signature while maintaining the fixture dependency.


90-91: LGTM! Improved error handling.

Adding check=True to the subprocess.run call is an excellent improvement. It will raise a CalledProcessError if the process fails, making test failures more explicit and informative compared to just checking the return code.

@LinZhihao-723 LinZhihao-723 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Directly pushed to polish the docstrings.


def _get_free_tcp_port() -> int:
"""Returns a free TCP port."""
""":return: A free TCP port number."""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The description is repetitive. In this case, keeping only the return should be fine.

Comment on lines +24 to +27
:return: A tuple of the started processes:
- The scheduler process.
- The first worker process.
- The second worker process.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is usually how we document tuples/pairs.

Comment on lines +280 to +281
:param storage:
:param success_job:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For these test parameters, you can just leave them empty.
The removed description isn't 100% correct: the parameter is a generator, not an object.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

These type annotations are actually wrong and are fixed in #174.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lol, alright. Let's fix the type annotation in #174.
Are u ok to leave the parameter docstrings empty?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes.

@LinZhihao-723 LinZhihao-723 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For the PR title, how about:

chore(lint): Update Ruff config to match `yscope-dev-utils` and resolve resulting lint issues.

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