From a30fc9379a91d3e505fc76298e929876101ba16d Mon Sep 17 00:00:00 2001 From: Mateo Torres Date: Wed, 9 Jul 2025 14:04:30 -0300 Subject: [PATCH] added ruff toml and pre-comit files to template if community (#477) This reintroduces a question into `arcade new`, which adds the ruff and pre-commit files into new toolkits that are aimed to be contributed back to Arcade AI. I use it in the toolkit building tutorial --------- Co-authored-by: Evan Tahler --- libs/arcade-cli/arcade_cli/new.py | 18 +++++++- .../.pre-commit-config.yaml | 18 ++++++++ .../templates/{{ toolkit_name }}/.ruff.toml | 44 +++++++++++++++++++ pyproject.toml | 2 +- 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 libs/arcade-cli/arcade_cli/templates/{{ toolkit_name }}/.pre-commit-config.yaml create mode 100644 libs/arcade-cli/arcade_cli/templates/{{ toolkit_name }}/.ruff.toml diff --git a/libs/arcade-cli/arcade_cli/new.py b/libs/arcade-cli/arcade_cli/new.py index 1551a5a0..c4a4c26b 100644 --- a/libs/arcade-cli/arcade_cli/new.py +++ b/libs/arcade-cli/arcade_cli/new.py @@ -75,7 +75,7 @@ def write_template(path: Path, content: str) -> None: path.write_text(content, encoding="utf-8") -def create_ignore_pattern(include_evals: bool) -> re.Pattern[str]: +def create_ignore_pattern(include_evals: bool, community_toolkit: bool) -> re.Pattern[str]: """Create an ignore pattern based on user preferences.""" patterns = [ "__pycache__", @@ -96,6 +96,9 @@ def create_ignore_pattern(include_evals: bool) -> re.Pattern[str]: if not include_evals: patterns.append("evals") + if not community_toolkit: + patterns.extend([".ruff.toml", ".pre-commit-config.yaml", "README.md"]) + return re.compile(f"({'|'.join(patterns)})$") @@ -174,6 +177,16 @@ def create_new_toolkit(output_directory: str, toolkit_name: str) -> None: "Do you want an evals directory created for you?", default=True ) + cwd = Path.cwd() + # TODO: this detection mechanism works only for people that didn't change the + # name of the repo, a better detection method is required here + community_toolkit = False + if cwd.name == "toolkits" and cwd.parent.name == "arcade-ai": + community_toolkit = ask_yes_no_question( + "Is your toolkit a community contribution (to be merged into Arcade's `arcade-ai` repo)?", + default=False, # False for now to keep the default behavior + ) + context = { "package_name": package_name, "toolkit_name": toolkit_name, @@ -187,6 +200,7 @@ def create_new_toolkit(output_directory: str, toolkit_name: str) -> None: "arcade_ai_min_version": ARCADE_AI_MIN_VERSION, "arcade_ai_max_version": ARCADE_AI_MAX_VERSION, "creation_year": datetime.now().year, + "community_toolkit": community_toolkit, } template_directory = Path(__file__).parent / "templates" / "{{ toolkit_name }}" @@ -196,7 +210,7 @@ def create_new_toolkit(output_directory: str, toolkit_name: str) -> None: ) # Create dynamic ignore pattern based on user preferences - ignore_pattern = create_ignore_pattern(include_evals) + ignore_pattern = create_ignore_pattern(include_evals, community_toolkit) try: create_package(env, template_directory, toolkit_directory, context, ignore_pattern) diff --git a/libs/arcade-cli/arcade_cli/templates/{{ toolkit_name }}/.pre-commit-config.yaml b/libs/arcade-cli/arcade_cli/templates/{{ toolkit_name }}/.pre-commit-config.yaml new file mode 100644 index 00000000..f502c3f3 --- /dev/null +++ b/libs/arcade-cli/arcade_cli/templates/{{ toolkit_name }}/.pre-commit-config.yaml @@ -0,0 +1,18 @@ +files: ^.*/{{toolkit_name}}/.* +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: "v4.4.0" + hooks: + - id: check-case-conflict + - id: check-merge-conflict + - id: check-toml + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.6.7 + hooks: + - id: ruff + args: [--fix] + - id: ruff-format diff --git a/libs/arcade-cli/arcade_cli/templates/{{ toolkit_name }}/.ruff.toml b/libs/arcade-cli/arcade_cli/templates/{{ toolkit_name }}/.ruff.toml new file mode 100644 index 00000000..9519fe6c --- /dev/null +++ b/libs/arcade-cli/arcade_cli/templates/{{ toolkit_name }}/.ruff.toml @@ -0,0 +1,44 @@ +target-version = "py310" +line-length = 100 +fix = true + +[lint] +select = [ + # flake8-2020 + "YTT", + # flake8-bandit + "S", + # flake8-bugbear + "B", + # flake8-builtins + "A", + # flake8-comprehensions + "C4", + # flake8-debugger + "T10", + # flake8-simplify + "SIM", + # isort + "I", + # mccabe + "C90", + # pycodestyle + "E", "W", + # pyflakes + "F", + # pygrep-hooks + "PGH", + # pyupgrade + "UP", + # ruff + "RUF", + # tryceratops + "TRY", +] + +[lint.per-file-ignores] +"**/tests/*" = ["S101"] + +[format] +preview = true +skip-magic-trailing-comma = false diff --git a/pyproject.toml b/pyproject.toml index e5c39193..c73b4732 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "arcade-ai" -version = "2.0.4" +version = "2.0.5" description = "Arcade.dev - Tool Calling platform for Agents" readme = "README.md" license = {file = "LICENSE"}