Skip to content

Commit 70ed8b6

Browse files
authored
chore: use ruff linter and formatter (#1351)
* chore(pre-commit): switch to ruff for linting and formatting Replace isort and black with ruff and ruff-format in pre-commit config. Update hooks to use ruff for both linting and formatting, specifying versions v0.9.6 and v0.11.2. Remove isort and black hooks, and keep other hooks unchanged. * feat(imports): add utilities for optional dependencies Introduced a new `imports.py` module providing utilities to handle optional dependencies. This includes functions for importing optional modules with customizable error handling, checking for their presence, and version validation. Also added a mapping for commonly used optional dependencies and a helper to retrieve them with predefined settings.
1 parent 0a40c61 commit 70ed8b6

File tree

383 files changed

+5731
-11132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

383 files changed

+5731
-11132
lines changed

.pre-commit-config.yaml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ repos:
55
- id: check-yaml
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
8-
- repo: https://github.com/pycqa/isort
9-
rev: 5.12.0
8+
9+
- repo: https://github.com/astral-sh/ruff-pre-commit
10+
# Ruff version.
11+
rev: v0.14.6
1012
hooks:
11-
- id: isort
12-
args: [ "--profile", "black" ]
13-
name: isort (python)
14-
- repo: https://github.com/psf/black
15-
rev: 23.3.0
16-
hooks:
17-
- id: black
13+
# Run the linter.
14+
- id: ruff
15+
args: [--fix]
16+
# Run the formatter.
17+
- id: ruff-format
18+
1819
- repo: https://github.com/Lucas-C/pre-commit-hooks
1920
rev: v1.4.2
2021
hooks:
@@ -32,9 +33,3 @@ repos:
3233
language: system
3334
types: [python]
3435
pass_filenames: false
35-
# Deactivating this for now.
36-
# - repo: https://github.com/pycqa/pylint
37-
# rev: v2.17.0
38-
# hooks:
39-
# - id: pylint
40-
# language_version: python3.10

build_notebook_docs.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def _fix_prefix_and_type_in_code_blocks(md_file_path):
8787
updated_block = "\n".join(lines)
8888
content = content.replace(block, updated_block)
8989
block = updated_block
90-
except:
90+
except Exception:
9191
pass
9292

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

195195
# We do some additional post-processing
196196
_remove_code_blocks_with_text(readme_path.absolute(), "# Init:")
197-
_remove_code_blocks_with_text(
198-
readme_path.absolute(), "# Hide from documentation page."
199-
)
197+
_remove_code_blocks_with_text(readme_path.absolute(), "# Hide from documentation page.")
200198

201199
_remove_code_blocks_with_text(
202200
readme_path.absolute(),

docs/colang-2/examples/csl.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
sys.path.append(str(pathlib.Path(__file__).parent.parent.parent.parent.resolve()))
2323
print(sys.path)
2424

25-
from utils import compare_interaction_with_test_script
25+
from utils import compare_interaction_with_test_script # noqa: E402
2626

2727
########################################################################################################################
2828
# CORE
@@ -637,9 +637,7 @@ async def test_repeating_timer():
637637
# USAGE_END: test_repeating_timer
638638
"""
639639

640-
await compare_interaction_with_test_script(
641-
test_script, colang_code, wait_time_s=2.0
642-
)
640+
await compare_interaction_with_test_script(test_script, colang_code, wait_time_s=2.0)
643641

644642

645643
@pytest.mark.asyncio
@@ -809,9 +807,7 @@ async def test_polling_llm_request_response():
809807
# USAGE_END: test_polling_llm_request_response
810808
"""
811809

812-
await compare_interaction_with_test_script(
813-
test_script, colang_code, llm_responses=['"nine"']
814-
)
810+
await compare_interaction_with_test_script(test_script, colang_code, llm_responses=['"nine"'])
815811

816812

817813
@pytest.mark.asyncio

docs/colang-2/examples/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@ async def compare_interaction_with_test_script(
9292
)
9393
clean_test_script = cleanup(test_script)
9494
clean_result = cleanup(result)
95-
assert (
96-
clean_test_script == clean_result
97-
), f"\n----\n{clean_result}\n----\n\ndoes not match test script\n\n----\n{clean_test_script}\n----"
95+
assert clean_test_script == clean_result, (
96+
f"\n----\n{clean_result}\n----\n\ndoes not match test script\n\n----\n{clean_test_script}\n----"
97+
)

0 commit comments

Comments
 (0)