Skip to content

Conversation

@Pouyanpi
Copy link
Collaborator

No description provided.

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.
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.
@github-actions
Copy link
Contributor

Documentation preview

https://nvidia.github.io/NeMo-Guardrails/review/pr-1351

@codecov-commenter
Copy link

codecov-commenter commented Aug 26, 2025

Codecov Report

❌ Patch coverage is 68.43100% with 334 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.55%. Comparing base (2732d3b) to head (c54f0f0).
⚠️ Report is 19 commits behind head on develop.

Files with missing lines Patch % Lines
nemoguardrails/imports.py 37.03% 34 Missing ⚠️
nemoguardrails/eval/ui/common.py 0.00% 17 Missing ⚠️
nemoguardrails/colang/v1_0/lang/colang_parser.py 58.82% 14 Missing ⚠️
nemoguardrails/eval/check.py 0.00% 13 Missing ⚠️
nemoguardrails/cli/chat.py 0.00% 12 Missing ⚠️
nemoguardrails/actions/v2_x/generation.py 64.51% 11 Missing ⚠️
nemoguardrails/colang/v2_x/runtime/runtime.py 52.17% 11 Missing ⚠️
nemoguardrails/actions/llm/generation.py 84.37% 10 Missing ⚠️
nemoguardrails/evaluate/evaluate_topical.py 0.00% 10 Missing ⚠️
nemoguardrails/colang/v2_x/runtime/statemachine.py 91.66% 9 Missing ⚠️
... and 67 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1351      +/-   ##
===========================================
- Coverage    71.59%   71.55%   -0.04%     
===========================================
  Files          168      169       +1     
  Lines        16862    16887      +25     
===========================================
+ Hits         12072    12084      +12     
- Misses        4790     4803      +13     
Flag Coverage Δ
python 71.55% <68.43%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
nemoguardrails/__init__.py 100.00% <100.00%> (ø)
nemoguardrails/actions/__init__.py 100.00% <100.00%> (ø)
nemoguardrails/actions/core.py 100.00% <100.00%> (ø)
nemoguardrails/actions/langchain/actions.py 28.57% <ø> (ø)
nemoguardrails/actions/math.py 44.82% <100.00%> (ø)
nemoguardrails/actions/retrieve_relevant_chunks.py 95.83% <100.00%> (ø)
nemoguardrails/actions/validation/__init__.py 100.00% <100.00%> (ø)
nemoguardrails/actions/validation/base.py 81.42% <100.00%> (ø)
nemoguardrails/cli/__init__.py 48.10% <100.00%> (ø)
nemoguardrails/colang/runtime.py 90.24% <100.00%> (ø)
... and 120 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Pouyanpi Pouyanpi marked this pull request as ready for review August 28, 2025 10:19
@Pouyanpi Pouyanpi self-assigned this Sep 2, 2025
@Pouyanpi Pouyanpi added this to the v0.17.0 milestone Sep 2, 2025
@tgasser-nv
Copy link
Collaborator

We already have Black in our pre-commits, but this would add a linter which would be really valuable. Can we merge this after the functional and type-check MRs?

@Pouyanpi
Copy link
Collaborator Author

We already have Black in our pre-commits, but this would add a linter which would be really valuable. Can we merge this after the functional and type-check MRs?

yes, let's merge it at the end. It is not urgent we can even include it for 0.18

@tgasser-nv
Copy link
Collaborator

Should we enable this as a formatter first (ruff format)? Then later on we can turn on the linting mode too (ruff check)?

Just out of curiousity I ran ruff check on develop SHA 2af64d62ecd90f3891595ac47530ea9033a970aa and we have 78 errors in the nemoguardrails code and 126 errors in the tests. Wouldn't take too long to clean up, but we could have this as a P1 for v0.17

$ ruff check nemoguardrails/ --statistics
27	F401	[ ] unused-import
16	F541	[*] f-string-missing-placeholders
16	F821	[ ] undefined-name
 7	F841	[*] unused-variable
 4	E402	[ ] module-import-not-at-top-of-file
 4	E722	[ ] bare-except
 1	E721	[ ] type-comparison
 1	F403	[ ] undefined-local-with-import-star
 1	F811	[ ] redefined-while-unused
 1	F901	[*] raise-not-implemented
Found 78 errors.
[*] 38 fixable with the `--fix` option (5 hidden fixes can be enabled with the `--unsafe-fixes` option).

And on the tests/ directory:

$ ruff check tests --statistics
91	F401	[ ] unused-import
18	F841	[ ] unused-variable
 7	F541	[*] f-string-missing-placeholders
 6	E712	[ ] true-false-comparison
 3	F811	[ ] redefined-while-unused
 1	E711	[ ] none-comparison
Found 126 errors.
[*] 77 fixable with the `--fix` option (24 hidden fixes can be enabled with the `--unsafe-fixes` option).

Copy link
Collaborator

@tgasser-nv tgasser-nv left a comment

Choose a reason for hiding this comment

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

Looks good, let's turn on the formatter for 0.17. If we have time we can do the linting (P1)

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.

3 participants