Skip to content

chore(dev): use ruff as linter and formatter #991

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

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0

hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/pycqa/isort
rev: 5.12.0

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.6

hooks:
- id: isort
args: [ "--profile", "black" ]
name: isort (python)
- repo: https://github.com/psf/black
rev: 23.3.0
- id: ruff
args: ["--fix"]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.11.2
hooks:
- id: black
# Run the linter.
- id: ruff
args: [--fix]
# Run the formatter.
- id: ruff-format

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.4.2
hooks:
Expand All @@ -23,7 +31,6 @@ repos:
args:
- --license-filepath
- LICENSE.md

# Deactivating this for now.
# - repo: https://github.com/pycqa/pylint
# rev: v2.17.0
Expand Down
6 changes: 2 additions & 4 deletions build_notebook_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _fix_prefix_and_type_in_code_blocks(md_file_path):
updated_block = "\n".join(lines)
content = content.replace(block, updated_block)
block = updated_block
except:
except yaml.YAMLError:
Copy link
Preview

Copilot AI Mar 31, 2025

Choose a reason for hiding this comment

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

Catching only yaml.YAMLError might not cover all unexpected exceptions during YAML processing. Consider logging or re-raising other exceptions so that critical errors are not silently ignored.

Copilot uses AI. Check for mistakes.

pass

if lines[0] == "```" and "from nemoguardrails" in block:
Expand Down Expand Up @@ -194,9 +194,7 @@ def rename_md_to_readme(start_dir):

# We do some additional post-processing
_remove_code_blocks_with_text(readme_path.absolute(), "# Init:")
_remove_code_blocks_with_text(
readme_path.absolute(), "# Hide from documentation page."
)
_remove_code_blocks_with_text(readme_path.absolute(), "# Hide from documentation page.")

_remove_code_blocks_with_text(
readme_path.absolute(),
Expand Down
10 changes: 3 additions & 7 deletions docs/colang-2/examples/test_csl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
import sys

import pytest
from utils import compare_interaction_with_test_script

pathlib.Path(__file__).parent.parent.parent.resolve()
sys.path.append(str(pathlib.Path(__file__).parent.parent.parent.parent.resolve()))
print(sys.path)

from utils import compare_interaction_with_test_script

########################################################################################################################
# CORE
Expand Down Expand Up @@ -637,9 +637,7 @@ async def test_repeating_timer():
# USAGE_END: test_repeating_timer
"""

await compare_interaction_with_test_script(
test_script, colang_code, wait_time_s=2.0
)
await compare_interaction_with_test_script(test_script, colang_code, wait_time_s=2.0)


@pytest.mark.asyncio
Expand Down Expand Up @@ -809,9 +807,7 @@ async def test_polling_llm_request_response():
# USAGE_END: test_polling_llm_request_response
"""

await compare_interaction_with_test_script(
test_script, colang_code, llm_responses=['"nine"']
)
await compare_interaction_with_test_script(test_script, colang_code, llm_responses=['"nine"'])


@pytest.mark.asyncio
Expand Down
6 changes: 3 additions & 3 deletions docs/colang-2/examples/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ async def compare_interaction_with_test_script(
)
clean_test_script = cleanup(test_script)
clean_result = cleanup(result)
assert (
clean_test_script == clean_result
), f"\n----\n{clean_result}\n----\n\ndoes not match test script\n\n----\n{clean_test_script}\n----"
assert clean_test_script == clean_result, (
f"\n----\n{clean_result}\n----\n\ndoes not match test script\n\n----\n{clean_test_script}\n----"
)
Loading
Loading