style(cli): linting pass (#33078)

This commit is contained in:
Mason Daugherty
2025-09-24 01:24:52 -04:00
committed by GitHub
parent ae4976896e
commit 05ba941230
13 changed files with 39 additions and 47 deletions

View File

@@ -1,3 +0,0 @@
# Contributing to langchain-cli
Update CLI versions with `poe bump` to ensure that version commands display correctly.

View File

@@ -18,7 +18,7 @@ def create_demo_server(
Args:
config_keys: Optional sequence of config keys to expose in the playground.
playground_type: The type of playground to use. Can be `'default'` or `'chat'`.
playground_type: The type of playground to use.
Returns:
The demo server.

View File

@@ -18,7 +18,5 @@ class Test__ModuleName__Retriever(RetrieversIntegrationTests):
@property
def retriever_query_example(self) -> str:
"""
Returns a str representing the "query" of an example retriever call.
"""
"""Returns a str representing the "query" of an example retriever call."""
return "example query"

View File

@@ -21,7 +21,7 @@ class TestParrotMultiplyToolIntegration(ToolsIntegrationTests):
"""
Returns a dictionary representing the "args" of an example tool call.
This should NOT be a ToolCall dict - i.e. it should not
have {"name", "id", "args"} keys.
This should NOT be a ToolCall dict - i.e. it should not have
`{"name", "id", "args"}` keys.
"""
return {"a": 2, "b": 3}

View File

@@ -11,7 +11,7 @@ class TestParrotMultiplyToolUnit(ToolsUnitTests):
@property
def tool_constructor_params(self) -> dict:
# if your tool constructor instead required initialization arguments like
# If your tool constructor instead required initialization arguments like
# `def __init__(self, some_arg: int):`, you would return those here
# as a dictionary, e.g.: `return {'some_arg': 42}`
return {}
@@ -21,7 +21,7 @@ class TestParrotMultiplyToolUnit(ToolsUnitTests):
"""
Returns a dictionary representing the "args" of an example tool call.
This should NOT be a ToolCall dict - i.e. it should not
have {"name", "id", "args"} keys.
This should NOT be a ToolCall dict - i.e. it should not have
`{"name", "id", "args"}` keys.
"""
return {"a": 2, "b": 3}

View File

@@ -159,8 +159,8 @@ def add(
"""Add the specified template to the current LangServe app.
e.g.:
langchain app add extraction-openai-functions
langchain app add git+ssh://git@github.com/efriis/simple-pirate.git
`langchain app add extraction-openai-functions`
`langchain app add git+ssh://git@github.com/efriis/simple-pirate.git`
"""
if branch is None:
branch = []

View File

@@ -116,17 +116,17 @@ def new(
typer.echo(f"Folder {destination_dir} exists.")
raise typer.Exit(code=1)
# copy over template from ../integration_template
# Copy over template from ../integration_template
shutil.copytree(project_template_dir, destination_dir, dirs_exist_ok=False)
# folder movement
# Folder movement
package_dir = destination_dir / replacements["__module_name__"]
shutil.move(destination_dir / "integration_template", package_dir)
# replacements in files
# Replacements in files
replace_glob(destination_dir, "**/*", cast("dict[str, str]", replacements))
# dependency install
# Dependency install
try:
# Use --no-progress to avoid tty issues in CI/test environments
env = os.environ.copy()
@@ -149,7 +149,7 @@ def new(
"`uv sync --dev` manually in the package directory.",
)
else:
# confirm src and dst are the same length
# Confirm src and dst are the same length
if not src:
typer.echo("Cannot provide --dst without --src.")
raise typer.Exit(code=1)
@@ -158,7 +158,7 @@ def new(
typer.echo("Number of --src and --dst arguments must match.")
raise typer.Exit(code=1)
if not dst:
# assume we're in a package dir, copy to equivalent path
# Assume we're in a package dir, copy to equivalent path
dst_paths = [destination_dir / p for p in src]
else:
dst_paths = [Path.cwd() / p for p in dst]
@@ -169,7 +169,7 @@ def new(
for p in dst_paths
]
# confirm no duplicate dst_paths
# Confirm no duplicate dst_paths
if len(dst_paths) != len(set(dst_paths)):
typer.echo(
"Duplicate destination paths provided or computed - please "
@@ -177,7 +177,7 @@ def new(
)
raise typer.Exit(code=1)
# confirm no files exist at dst_paths
# Confirm no files exist at dst_paths
for dst_path in dst_paths:
if dst_path.exists():
typer.echo(f"File {dst_path} exists.")

View File

@@ -75,7 +75,7 @@ def generate_raw_migrations(
def generate_top_level_imports(pkg: str) -> list[tuple[str, str]]:
"""Look at all the top level modules in langchain_community.
Attempt to import everything from each ``__init__`` file. For example,
Attempt to import everything from each `__init__` file. For example,
langchain_community/
chat_models/
@@ -83,16 +83,15 @@ def generate_top_level_imports(pkg: str) -> list[tuple[str, str]]:
llm/
__init__.py # <-- import everything from here
It'll collect all the imports, import the classes / functions it can find
there. It'll return a list of 2-tuples
Each tuple will contain the fully qualified path of the class / function to where
its logic is defined
(e.g., ``langchain_community.chat_models.xyz_implementation.ver2.XYZ``)
its logic is defined.
(e.g., `langchain_community.chat_models.xyz_implementation.ver2.XYZ`)
and the second tuple will contain the path
to importing it from the top level namespaces
(e.g., ``langchain_community.chat_models.XYZ``)
(e.g., `langchain_community.chat_models.XYZ`)
Args:
pkg: The package to scan.

View File

@@ -28,7 +28,6 @@ def get_migrations_for_partner_package(pkg_name: str) -> list[tuple[str, str]]:
Returns:
List of 2-tuples containing old and new import paths.
"""
package = importlib.import_module(pkg_name)
classes_ = find_subclasses_in_module(

View File

@@ -38,19 +38,19 @@ def parse_dependency_string(
branch: str | None,
api_path: str | None,
) -> DependencySource:
"""Parse a dependency string into a DependencySource.
"""Parse a dependency string into a `DependencySource`.
Args:
dep: the dependency string.
repo: optional repository.
branch: optional branch.
api_path: optional API path.
dep: The dependency string
repo: Optional repository
branch: Optional branch
api_path: Optional API path
Returns:
The parsed dependency source information.
The parsed dependency source information
Raises:
ValueError: if the dependency string is invalid.
ValueError: If the dependency string is invalid
"""
if dep is not None and dep.startswith("git+"):
if repo is not None or branch is not None:
@@ -147,8 +147,8 @@ def parse_dependencies(
"""Parse dependencies.
Args:
dependencies: the dependencies to parse
repo: the repositories to use
dependencies: The dependencies to parse
repo: The repositories to use
branch: the branches to use
api_path: the api paths to use
@@ -244,7 +244,7 @@ def copy_repo(
) -> None:
"""Copiy a repo, ignoring git folders.
Raises FileNotFound error if it can't find source
Raises `FileNotFound` if it can't find source
"""
def ignore_func(_: str, files: list[str]) -> list[str]:

View File

@@ -37,13 +37,12 @@ def get_package_root(cwd: Path | None = None) -> Path:
class LangServeExport(TypedDict):
"""Fields from pyproject.toml that are relevant to LangServe.
"""Fields from `pyproject.toml` that are relevant to LangServe.
Attributes:
module: The module to import from, tool.langserve.export_module
attr: The attribute to import from the module, tool.langserve.export_attr
package_name: The name of the package, tool.poetry.name
module: The module to import from, `tool.langserve.export_module`
attr: The attribute to import from the module, `tool.langserve.export_attr`
package_name: The name of the package, `tool.poetry.name`
"""
module: str

View File

@@ -19,7 +19,7 @@ def add_dependencies_to_pyproject_toml(
pyproject_toml: Path,
local_editable_dependencies: Iterable[tuple[str, Path]],
) -> None:
"""Add dependencies to pyproject.toml."""
"""Add dependencies to `pyproject.toml`."""
with pyproject_toml.open(encoding="utf-8") as f:
# tomlkit types aren't amazing - treat as Dict instead
pyproject: dict[str, Any] = load(f)
@@ -37,7 +37,7 @@ def remove_dependencies_from_pyproject_toml(
pyproject_toml: Path,
local_editable_dependencies: Iterable[str],
) -> None:
"""Remove dependencies from pyproject.toml."""
"""Remove dependencies from `pyproject.toml`."""
with pyproject_toml.open(encoding="utf-8") as f:
pyproject: dict[str, Any] = load(f)
# tomlkit types aren't amazing - treat as Dict instead

View File

@@ -9,7 +9,7 @@ from langchain_cli.namespaces.migrate.generate.generic import (
@pytest.mark.xfail(reason="Unknown reason")
def test_create_json_agent_migration() -> None:
"""Test the migration of create_json_agent from langchain to langchain_community."""
"""Test migration of `create_json_agent` from langchain to `langchain_community`."""
with sup1(), sup2():
raw_migrations = generate_simplified_migrations(
from_package="langchain",
@@ -40,7 +40,7 @@ def test_create_json_agent_migration() -> None:
@pytest.mark.xfail(reason="Unknown reason")
def test_create_single_store_retriever_db() -> None:
"""Test migration from langchain to langchain_core."""
"""Test migration from `langchain` to `langchain_core`."""
with sup1(), sup2():
raw_migrations = generate_simplified_migrations(
from_package="langchain",