From 2c7aba415837f6f56ffa37547732da6bb257df60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Han?= Date: Wed, 30 Apr 2025 18:05:27 +0200 Subject: [PATCH] fix: enforce stricter ASCII rules lint rules in Ruff (#2062) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # What does this PR do? - Added new Ruff lint rules to detect ambiguous or non-ASCII characters: - Added per-file ignores where Unicode usage is still required. - Fixed whatever had to be fixed Signed-off-by: Sébastien Han --- llama_stack/cli/stack/run.py | 2 +- llama_stack/distribution/build.py | 3 +-- pyproject.toml | 36 +++++++++++++++++++++++-------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/llama_stack/cli/stack/run.py b/llama_stack/cli/stack/run.py index d8234bb46..2eee20883 100644 --- a/llama_stack/cli/stack/run.py +++ b/llama_stack/cli/stack/run.py @@ -119,7 +119,7 @@ class StackRun(Subcommand): if not config_file.is_file(): self.parser.error( - f"Config file must be a valid file path, '{config_file}’ is not a file: type={type(config_file)}" + f"Config file must be a valid file path, '{config_file}' is not a file: type={type(config_file)}" ) logger.info(f"Using run configuration: {config_file}") diff --git a/llama_stack/distribution/build.py b/llama_stack/distribution/build.py index 9664449f3..1d39063f0 100644 --- a/llama_stack/distribution/build.py +++ b/llama_stack/distribution/build.py @@ -47,14 +47,13 @@ def get_provider_dependencies( providers = config.distribution_spec.providers deps = [] registry = get_provider_registry(config) - for api_str, provider_or_providers in providers.items(): providers_for_api = registry[Api(api_str)] providers = provider_or_providers if isinstance(provider_or_providers, list) else [provider_or_providers] for provider in providers: - # Providers from BuildConfig and RunConfig are subtly different – not great + # Providers from BuildConfig and RunConfig are subtly different - not great provider_type = provider if isinstance(provider, str) else provider.provider_type if provider_type not in providers_for_api: diff --git a/pyproject.toml b/pyproject.toml index 36af789ef..f1f65be90 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -144,15 +144,25 @@ exclude = [ [tool.ruff.lint] select = [ - "B", # flake8-bugbear - "B9", # flake8-bugbear subset - "C", # comprehensions - "E", # pycodestyle - "F", # Pyflakes - "N", # Naming - "W", # Warnings - "DTZ", # datetime rules - "I", # isort (imports order) + "B", # flake8-bugbear + "B9", # flake8-bugbear subset + "C", # comprehensions + "E", # pycodestyle + "F", # Pyflakes + "N", # Naming + "W", # Warnings + "DTZ", # datetime rules + "I", # isort (imports order) + "RUF001", # Checks for ambiguous Unicode characters in strings + "RUF002", # Checks for ambiguous Unicode characters in docstrings + "RUF003", # Checks for ambiguous Unicode characters in comments + "PLC2401", # Checks for the use of non-ASCII characters in variable names + "PLC2403", # Checks for the use of non-ASCII characters in import statements + "PLE2510", # Checks for strings that contain the control character BS. + "PLE2512", # Checks for strings that contain the raw control character SUB. + "PLE2513", # Checks for strings that contain the raw control character ESC. + "PLE2514", # Checks for strings that contain the raw control character NUL (0 byte). + "PLE2515", # Checks for strings that contain the zero width space character. ] ignore = [ # The following ignores are desired by the project maintainers. @@ -165,10 +175,18 @@ ignore = [ # These are the additional ones we started ignoring after moving to ruff. We should look into each one of them later. "C901", # Complexity of the function is too high ] +unfixable = [ + "PLE2515", +] # Do not fix this automatically since ruff will replace the zero-width space with \u200b - let's do it manually # Ignore the following errors for the following files [tool.ruff.lint.per-file-ignores] "tests/**/*.py" = ["DTZ"] # Ignore datetime rules for tests +"llama_stack/providers/inline/scoring/basic/utils/ifeval_utils.py" = ["RUF001"] +"llama_stack/providers/inline/scoring/basic/scoring_fn/fn_defs/regex_parser_multiple_choice_answer.py" = [ + "RUF001", + "PLE2515", +] [tool.mypy] mypy_path = ["llama_stack"]