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 <evantahler@gmail.com>
This commit is contained in:
parent
de7b655214
commit
a30fc9379a
4 changed files with 79 additions and 3 deletions
|
|
@ -75,7 +75,7 @@ def write_template(path: Path, content: str) -> None:
|
||||||
path.write_text(content, encoding="utf-8")
|
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."""
|
"""Create an ignore pattern based on user preferences."""
|
||||||
patterns = [
|
patterns = [
|
||||||
"__pycache__",
|
"__pycache__",
|
||||||
|
|
@ -96,6 +96,9 @@ def create_ignore_pattern(include_evals: bool) -> re.Pattern[str]:
|
||||||
if not include_evals:
|
if not include_evals:
|
||||||
patterns.append("evals")
|
patterns.append("evals")
|
||||||
|
|
||||||
|
if not community_toolkit:
|
||||||
|
patterns.extend([".ruff.toml", ".pre-commit-config.yaml", "README.md"])
|
||||||
|
|
||||||
return re.compile(f"({'|'.join(patterns)})$")
|
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
|
"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 = {
|
context = {
|
||||||
"package_name": package_name,
|
"package_name": package_name,
|
||||||
"toolkit_name": toolkit_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_min_version": ARCADE_AI_MIN_VERSION,
|
||||||
"arcade_ai_max_version": ARCADE_AI_MAX_VERSION,
|
"arcade_ai_max_version": ARCADE_AI_MAX_VERSION,
|
||||||
"creation_year": datetime.now().year,
|
"creation_year": datetime.now().year,
|
||||||
|
"community_toolkit": community_toolkit,
|
||||||
}
|
}
|
||||||
template_directory = Path(__file__).parent / "templates" / "{{ toolkit_name }}"
|
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
|
# 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:
|
try:
|
||||||
create_package(env, template_directory, toolkit_directory, context, ignore_pattern)
|
create_package(env, template_directory, toolkit_directory, context, ignore_pattern)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[project]
|
[project]
|
||||||
name = "arcade-ai"
|
name = "arcade-ai"
|
||||||
version = "2.0.4"
|
version = "2.0.5"
|
||||||
description = "Arcade.dev - Tool Calling platform for Agents"
|
description = "Arcade.dev - Tool Calling platform for Agents"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = {file = "LICENSE"}
|
license = {file = "LICENSE"}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue