mirror of
https://github.com/hwchase17/langchain.git
synced 2025-11-03 09:48:05 +00:00
style(cli): linting pass (#33078)
This commit is contained in:
@@ -1,3 +0,0 @@
|
|||||||
# Contributing to langchain-cli
|
|
||||||
|
|
||||||
Update CLI versions with `poe bump` to ensure that version commands display correctly.
|
|
||||||
@@ -18,7 +18,7 @@ def create_demo_server(
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
config_keys: Optional sequence of config keys to expose in the playground.
|
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:
|
Returns:
|
||||||
The demo server.
|
The demo server.
|
||||||
|
|||||||
@@ -18,7 +18,5 @@ class Test__ModuleName__Retriever(RetrieversIntegrationTests):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def retriever_query_example(self) -> str:
|
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"
|
return "example query"
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class TestParrotMultiplyToolIntegration(ToolsIntegrationTests):
|
|||||||
"""
|
"""
|
||||||
Returns a dictionary representing the "args" of an example tool call.
|
Returns a dictionary representing the "args" of an example tool call.
|
||||||
|
|
||||||
This should NOT be a ToolCall dict - i.e. it should not
|
This should NOT be a ToolCall dict - i.e. it should not have
|
||||||
have {"name", "id", "args"} keys.
|
`{"name", "id", "args"}` keys.
|
||||||
"""
|
"""
|
||||||
return {"a": 2, "b": 3}
|
return {"a": 2, "b": 3}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class TestParrotMultiplyToolUnit(ToolsUnitTests):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def tool_constructor_params(self) -> dict:
|
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
|
# `def __init__(self, some_arg: int):`, you would return those here
|
||||||
# as a dictionary, e.g.: `return {'some_arg': 42}`
|
# as a dictionary, e.g.: `return {'some_arg': 42}`
|
||||||
return {}
|
return {}
|
||||||
@@ -21,7 +21,7 @@ class TestParrotMultiplyToolUnit(ToolsUnitTests):
|
|||||||
"""
|
"""
|
||||||
Returns a dictionary representing the "args" of an example tool call.
|
Returns a dictionary representing the "args" of an example tool call.
|
||||||
|
|
||||||
This should NOT be a ToolCall dict - i.e. it should not
|
This should NOT be a ToolCall dict - i.e. it should not have
|
||||||
have {"name", "id", "args"} keys.
|
`{"name", "id", "args"}` keys.
|
||||||
"""
|
"""
|
||||||
return {"a": 2, "b": 3}
|
return {"a": 2, "b": 3}
|
||||||
|
|||||||
@@ -159,8 +159,8 @@ def add(
|
|||||||
"""Add the specified template to the current LangServe app.
|
"""Add the specified template to the current LangServe app.
|
||||||
|
|
||||||
e.g.:
|
e.g.:
|
||||||
langchain app add extraction-openai-functions
|
`langchain app add extraction-openai-functions`
|
||||||
langchain app add git+ssh://git@github.com/efriis/simple-pirate.git
|
`langchain app add git+ssh://git@github.com/efriis/simple-pirate.git`
|
||||||
"""
|
"""
|
||||||
if branch is None:
|
if branch is None:
|
||||||
branch = []
|
branch = []
|
||||||
|
|||||||
@@ -116,17 +116,17 @@ def new(
|
|||||||
typer.echo(f"Folder {destination_dir} exists.")
|
typer.echo(f"Folder {destination_dir} exists.")
|
||||||
raise typer.Exit(code=1)
|
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)
|
shutil.copytree(project_template_dir, destination_dir, dirs_exist_ok=False)
|
||||||
|
|
||||||
# folder movement
|
# Folder movement
|
||||||
package_dir = destination_dir / replacements["__module_name__"]
|
package_dir = destination_dir / replacements["__module_name__"]
|
||||||
shutil.move(destination_dir / "integration_template", package_dir)
|
shutil.move(destination_dir / "integration_template", package_dir)
|
||||||
|
|
||||||
# replacements in files
|
# Replacements in files
|
||||||
replace_glob(destination_dir, "**/*", cast("dict[str, str]", replacements))
|
replace_glob(destination_dir, "**/*", cast("dict[str, str]", replacements))
|
||||||
|
|
||||||
# dependency install
|
# Dependency install
|
||||||
try:
|
try:
|
||||||
# Use --no-progress to avoid tty issues in CI/test environments
|
# Use --no-progress to avoid tty issues in CI/test environments
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
@@ -149,7 +149,7 @@ def new(
|
|||||||
"`uv sync --dev` manually in the package directory.",
|
"`uv sync --dev` manually in the package directory.",
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# confirm src and dst are the same length
|
# Confirm src and dst are the same length
|
||||||
if not src:
|
if not src:
|
||||||
typer.echo("Cannot provide --dst without --src.")
|
typer.echo("Cannot provide --dst without --src.")
|
||||||
raise typer.Exit(code=1)
|
raise typer.Exit(code=1)
|
||||||
@@ -158,7 +158,7 @@ def new(
|
|||||||
typer.echo("Number of --src and --dst arguments must match.")
|
typer.echo("Number of --src and --dst arguments must match.")
|
||||||
raise typer.Exit(code=1)
|
raise typer.Exit(code=1)
|
||||||
if not dst:
|
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]
|
dst_paths = [destination_dir / p for p in src]
|
||||||
else:
|
else:
|
||||||
dst_paths = [Path.cwd() / p for p in dst]
|
dst_paths = [Path.cwd() / p for p in dst]
|
||||||
@@ -169,7 +169,7 @@ def new(
|
|||||||
for p in dst_paths
|
for p in dst_paths
|
||||||
]
|
]
|
||||||
|
|
||||||
# confirm no duplicate dst_paths
|
# Confirm no duplicate dst_paths
|
||||||
if len(dst_paths) != len(set(dst_paths)):
|
if len(dst_paths) != len(set(dst_paths)):
|
||||||
typer.echo(
|
typer.echo(
|
||||||
"Duplicate destination paths provided or computed - please "
|
"Duplicate destination paths provided or computed - please "
|
||||||
@@ -177,7 +177,7 @@ def new(
|
|||||||
)
|
)
|
||||||
raise typer.Exit(code=1)
|
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:
|
for dst_path in dst_paths:
|
||||||
if dst_path.exists():
|
if dst_path.exists():
|
||||||
typer.echo(f"File {dst_path} exists.")
|
typer.echo(f"File {dst_path} exists.")
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ def generate_raw_migrations(
|
|||||||
def generate_top_level_imports(pkg: str) -> list[tuple[str, str]]:
|
def generate_top_level_imports(pkg: str) -> list[tuple[str, str]]:
|
||||||
"""Look at all the top level modules in langchain_community.
|
"""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/
|
langchain_community/
|
||||||
chat_models/
|
chat_models/
|
||||||
@@ -83,16 +83,15 @@ def generate_top_level_imports(pkg: str) -> list[tuple[str, str]]:
|
|||||||
llm/
|
llm/
|
||||||
__init__.py # <-- import everything from here
|
__init__.py # <-- import everything from here
|
||||||
|
|
||||||
|
|
||||||
It'll collect all the imports, import the classes / functions it can find
|
It'll collect all the imports, import the classes / functions it can find
|
||||||
there. It'll return a list of 2-tuples
|
there. It'll return a list of 2-tuples
|
||||||
|
|
||||||
Each tuple will contain the fully qualified path of the class / function to where
|
Each tuple will contain the fully qualified path of the class / function to where
|
||||||
its logic is defined
|
its logic is defined.
|
||||||
(e.g., ``langchain_community.chat_models.xyz_implementation.ver2.XYZ``)
|
(e.g., `langchain_community.chat_models.xyz_implementation.ver2.XYZ`)
|
||||||
and the second tuple will contain the path
|
and the second tuple will contain the path
|
||||||
to importing it from the top level namespaces
|
to importing it from the top level namespaces
|
||||||
(e.g., ``langchain_community.chat_models.XYZ``)
|
(e.g., `langchain_community.chat_models.XYZ`)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
pkg: The package to scan.
|
pkg: The package to scan.
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ def get_migrations_for_partner_package(pkg_name: str) -> list[tuple[str, str]]:
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
List of 2-tuples containing old and new import paths.
|
List of 2-tuples containing old and new import paths.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
package = importlib.import_module(pkg_name)
|
package = importlib.import_module(pkg_name)
|
||||||
classes_ = find_subclasses_in_module(
|
classes_ = find_subclasses_in_module(
|
||||||
|
|||||||
@@ -38,19 +38,19 @@ def parse_dependency_string(
|
|||||||
branch: str | None,
|
branch: str | None,
|
||||||
api_path: str | None,
|
api_path: str | None,
|
||||||
) -> DependencySource:
|
) -> DependencySource:
|
||||||
"""Parse a dependency string into a DependencySource.
|
"""Parse a dependency string into a `DependencySource`.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
dep: the dependency string.
|
dep: The dependency string
|
||||||
repo: optional repository.
|
repo: Optional repository
|
||||||
branch: optional branch.
|
branch: Optional branch
|
||||||
api_path: optional API path.
|
api_path: Optional API path
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The parsed dependency source information.
|
The parsed dependency source information
|
||||||
|
|
||||||
Raises:
|
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 dep is not None and dep.startswith("git+"):
|
||||||
if repo is not None or branch is not None:
|
if repo is not None or branch is not None:
|
||||||
@@ -147,8 +147,8 @@ def parse_dependencies(
|
|||||||
"""Parse dependencies.
|
"""Parse dependencies.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
dependencies: the dependencies to parse
|
dependencies: The dependencies to parse
|
||||||
repo: the repositories to use
|
repo: The repositories to use
|
||||||
branch: the branches to use
|
branch: the branches to use
|
||||||
api_path: the api paths to use
|
api_path: the api paths to use
|
||||||
|
|
||||||
@@ -244,7 +244,7 @@ def copy_repo(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Copiy a repo, ignoring git folders.
|
"""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]:
|
def ignore_func(_: str, files: list[str]) -> list[str]:
|
||||||
|
|||||||
@@ -37,13 +37,12 @@ def get_package_root(cwd: Path | None = None) -> Path:
|
|||||||
|
|
||||||
|
|
||||||
class LangServeExport(TypedDict):
|
class LangServeExport(TypedDict):
|
||||||
"""Fields from pyproject.toml that are relevant to LangServe.
|
"""Fields from `pyproject.toml` that are relevant to LangServe.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
module: The module to import from, tool.langserve.export_module
|
module: The module to import from, `tool.langserve.export_module`
|
||||||
attr: The attribute to import from the module, tool.langserve.export_attr
|
attr: The attribute to import from the module, `tool.langserve.export_attr`
|
||||||
package_name: The name of the package, tool.poetry.name
|
package_name: The name of the package, `tool.poetry.name`
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
module: str
|
module: str
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ def add_dependencies_to_pyproject_toml(
|
|||||||
pyproject_toml: Path,
|
pyproject_toml: Path,
|
||||||
local_editable_dependencies: Iterable[tuple[str, Path]],
|
local_editable_dependencies: Iterable[tuple[str, Path]],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Add dependencies to pyproject.toml."""
|
"""Add dependencies to `pyproject.toml`."""
|
||||||
with pyproject_toml.open(encoding="utf-8") as f:
|
with pyproject_toml.open(encoding="utf-8") as f:
|
||||||
# tomlkit types aren't amazing - treat as Dict instead
|
# tomlkit types aren't amazing - treat as Dict instead
|
||||||
pyproject: dict[str, Any] = load(f)
|
pyproject: dict[str, Any] = load(f)
|
||||||
@@ -37,7 +37,7 @@ def remove_dependencies_from_pyproject_toml(
|
|||||||
pyproject_toml: Path,
|
pyproject_toml: Path,
|
||||||
local_editable_dependencies: Iterable[str],
|
local_editable_dependencies: Iterable[str],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Remove dependencies from pyproject.toml."""
|
"""Remove dependencies from `pyproject.toml`."""
|
||||||
with pyproject_toml.open(encoding="utf-8") as f:
|
with pyproject_toml.open(encoding="utf-8") as f:
|
||||||
pyproject: dict[str, Any] = load(f)
|
pyproject: dict[str, Any] = load(f)
|
||||||
# tomlkit types aren't amazing - treat as Dict instead
|
# tomlkit types aren't amazing - treat as Dict instead
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from langchain_cli.namespaces.migrate.generate.generic import (
|
|||||||
|
|
||||||
@pytest.mark.xfail(reason="Unknown reason")
|
@pytest.mark.xfail(reason="Unknown reason")
|
||||||
def test_create_json_agent_migration() -> None:
|
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():
|
with sup1(), sup2():
|
||||||
raw_migrations = generate_simplified_migrations(
|
raw_migrations = generate_simplified_migrations(
|
||||||
from_package="langchain",
|
from_package="langchain",
|
||||||
@@ -40,7 +40,7 @@ def test_create_json_agent_migration() -> None:
|
|||||||
|
|
||||||
@pytest.mark.xfail(reason="Unknown reason")
|
@pytest.mark.xfail(reason="Unknown reason")
|
||||||
def test_create_single_store_retriever_db() -> None:
|
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():
|
with sup1(), sup2():
|
||||||
raw_migrations = generate_simplified_migrations(
|
raw_migrations = generate_simplified_migrations(
|
||||||
from_package="langchain",
|
from_package="langchain",
|
||||||
|
|||||||
Reference in New Issue
Block a user