chore(cli): fix some ruff preview rules (#32803)

This commit is contained in:
Christophe Bornet
2025-09-07 22:53:19 +02:00
committed by GitHub
parent 4e39c164bb
commit 5bf0b218c8
5 changed files with 15 additions and 29 deletions

View File

@@ -72,9 +72,7 @@ def new(
name_str = name name_str = name
pip_bool = bool(pip) # None should be false pip_bool = bool(pip) # None should be false
else: else:
name_str = ( name_str = name or typer.prompt("What folder would you like to create?")
name if name else typer.prompt("What folder would you like to create?")
)
if not has_packages: if not has_packages:
package = [] package = []
package_prompt = "What package would you like to add? (leave blank to skip)" package_prompt = "What package would you like to add? (leave blank to skip)"

View File

@@ -34,7 +34,7 @@ def new(
package_name_split = computed_name.split("/") package_name_split = computed_name.split("/")
package_name = ( package_name = (
package_name_split[-2] package_name_split[-2]
if len(package_name_split) > 1 and package_name_split[-1] == "" if len(package_name_split) > 1 and not package_name_split[-1]
else package_name_split[-1] else package_name_split[-1]
) )
module_name = re.sub( module_name = re.sub(

View File

@@ -138,8 +138,8 @@ def parse_dependencies(
if ( if (
(dependencies and len(dependencies) != num_deps) (dependencies and len(dependencies) != num_deps)
or (api_path and len(api_path) != num_deps) or (api_path and len(api_path) != num_deps)
or (repo and len(repo) not in [1, num_deps]) or (repo and len(repo) not in {1, num_deps})
or (branch and len(branch) not in [1, num_deps]) or (branch and len(branch) not in {1, num_deps})
): ):
msg = ( msg = (
"Number of defined repos/branches/api_paths did not match the " "Number of defined repos/branches/api_paths did not match the "
@@ -151,15 +151,15 @@ def parse_dependencies(
inner_repos = _list_arg_to_length(repo, num_deps) inner_repos = _list_arg_to_length(repo, num_deps)
inner_branches = _list_arg_to_length(branch, num_deps) inner_branches = _list_arg_to_length(branch, num_deps)
return [ return list(
parse_dependency_string(iter_dep, iter_repo, iter_branch, iter_api_path) map(
for iter_dep, iter_repo, iter_branch, iter_api_path in zip( parse_dependency_string,
inner_deps, inner_deps,
inner_repos, inner_repos,
inner_branches, inner_branches,
inner_api_paths, inner_api_paths,
) )
] )
def _get_repo_path(gitstring: str, ref: Optional[str], repo_dir: Path) -> Path: def _get_repo_path(gitstring: str, ref: Optional[str], repo_dir: Path) -> Path:
@@ -167,7 +167,7 @@ def _get_repo_path(gitstring: str, ref: Optional[str], repo_dir: Path) -> Path:
ref_str = ref if ref is not None else "" ref_str = ref if ref is not None else ""
hashed = hashlib.sha256((f"{gitstring}:{ref_str}").encode()).hexdigest()[:8] hashed = hashlib.sha256((f"{gitstring}:{ref_str}").encode()).hexdigest()[:8]
removed_protocol = gitstring.split("://")[-1] removed_protocol = gitstring.split("://", maxsplit=1)[-1]
removed_basename = re.split(r"[/:]", removed_protocol, maxsplit=1)[-1] removed_basename = re.split(r"[/:]", removed_protocol, maxsplit=1)[-1]
removed_extras = removed_basename.split("#")[0] removed_extras = removed_basename.split("#")[0]
foldername = re.sub(r"\W", "_", removed_extras) foldername = re.sub(r"\W", "_", removed_extras)

View File

@@ -73,7 +73,7 @@ def generic(
else: else:
dumped = dump_migrations_as_grit(name, migrations) dumped = dump_migrations_as_grit(name, migrations)
Path(output).write_text(dumped) Path(output).write_text(dumped, encoding="utf-8")
def handle_partner(pkg: str, output: Optional[str] = None) -> None: def handle_partner(pkg: str, output: Optional[str] = None) -> None:
@@ -84,7 +84,7 @@ def handle_partner(pkg: str, output: Optional[str] = None) -> None:
data = dump_migrations_as_grit(name, migrations) data = dump_migrations_as_grit(name, migrations)
output_name = f"{name}.grit" if output is None else output output_name = f"{name}.grit" if output is None else output
if migrations: if migrations:
Path(output_name).write_text(data) Path(output_name).write_text(data, encoding="utf-8")
click.secho(f"LangChain migration script saved to {output_name}") click.secho(f"LangChain migration script saved to {output_name}")
else: else:
click.secho(f"No migrations found for {pkg}", fg="yellow") click.secho(f"No migrations found for {pkg}", fg="yellow")
@@ -109,7 +109,7 @@ def json_to_grit(json_file: str) -> None:
name = file.stem name = file.stem
data = dump_migrations_as_grit(name, migrations) data = dump_migrations_as_grit(name, migrations)
output_name = f"{name}.grit" output_name = f"{name}.grit"
Path(output_name).write_text(data) Path(output_name).write_text(data, encoding="utf-8")
click.secho(f"GritQL migration script saved to {output_name}") click.secho(f"GritQL migration script saved to {output_name}")

18
libs/cli/uv.lock generated
View File

@@ -629,18 +629,14 @@ typing = [
[[package]] [[package]]
name = "langchain-text-splitters" name = "langchain-text-splitters"
version = "0.3.10" version = "0.3.11"
source = { editable = "../text-splitters" } source = { editable = "../text-splitters" }
dependencies = [ dependencies = [
{ name = "langchain-core" }, { name = "langchain-core" },
{ name = "pip" },
] ]
[package.metadata] [package.metadata]
requires-dist = [ requires-dist = [{ name = "langchain-core", editable = "../core" }]
{ name = "langchain-core", editable = "../core" },
{ name = "pip", specifier = ">=25.2" },
]
[package.metadata.requires-dev] [package.metadata.requires-dev]
dev = [ dev = [
@@ -662,6 +658,7 @@ test = [
{ name = "pytest-xdist", specifier = ">=3.6.1,<4.0.0" }, { name = "pytest-xdist", specifier = ">=3.6.1,<4.0.0" },
] ]
test-integration = [ test-integration = [
{ name = "en-core-web-sm", url = "https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.8.0/en_core_web_sm-3.8.0-py3-none-any.whl" },
{ name = "nltk", specifier = ">=3.9.1,<4.0.0" }, { name = "nltk", specifier = ">=3.9.1,<4.0.0" },
{ name = "sentence-transformers", specifier = ">=3.0.1" }, { name = "sentence-transformers", specifier = ">=3.0.1" },
{ name = "spacy", specifier = ">=3.8.7,<4.0.0" }, { name = "spacy", specifier = ">=3.8.7,<4.0.0" },
@@ -887,15 +884,6 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/cc/20/ff623b09d963f88bfde16306a54e12ee5ea43e9b597108672ff3a408aad6/pathspec-0.12.1-py3-none-any.whl", hash = "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08", size = 31191, upload-time = "2023-12-10T22:30:43.14Z" }, { url = "https://files.pythonhosted.org/packages/cc/20/ff623b09d963f88bfde16306a54e12ee5ea43e9b597108672ff3a408aad6/pathspec-0.12.1-py3-none-any.whl", hash = "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08", size = 31191, upload-time = "2023-12-10T22:30:43.14Z" },
] ]
[[package]]
name = "pip"
version = "25.2"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/20/16/650289cd3f43d5a2fadfd98c68bd1e1e7f2550a1a5326768cddfbcedb2c5/pip-25.2.tar.gz", hash = "sha256:578283f006390f85bb6282dffb876454593d637f5d1be494b5202ce4877e71f2", size = 1840021, upload-time = "2025-07-30T21:50:15.401Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/b7/3f/945ef7ab14dc4f9d7f40288d2df998d1837ee0888ec3659c813487572faa/pip-25.2-py3-none-any.whl", hash = "sha256:6d67a2b4e7f14d8b31b8b52648866fa717f45a1eb70e83002f4331d07e953717", size = 1752557, upload-time = "2025-07-30T21:50:13.323Z" },
]
[[package]] [[package]]
name = "pluggy" name = "pluggy"
version = "1.5.0" version = "1.5.0"