mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-17 15:35:14 +00:00
refactor(cli): target ruff 310 (#32985)
Use union types for optional parameters
This commit is contained in:
@@ -5,7 +5,7 @@ import subprocess
|
||||
import sys
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
from typing import Annotated, Optional
|
||||
from typing import Annotated
|
||||
|
||||
import typer
|
||||
import uvicorn
|
||||
@@ -35,18 +35,18 @@ app_cli = typer.Typer(no_args_is_help=True, add_completion=False)
|
||||
@app_cli.command()
|
||||
def new(
|
||||
name: Annotated[
|
||||
Optional[str],
|
||||
str | None,
|
||||
typer.Argument(
|
||||
help="The name of the folder to create",
|
||||
),
|
||||
] = None,
|
||||
*,
|
||||
package: Annotated[
|
||||
Optional[list[str]],
|
||||
list[str] | None,
|
||||
typer.Option(help="Packages to seed the project with"),
|
||||
] = None,
|
||||
pip: Annotated[
|
||||
Optional[bool],
|
||||
bool | None,
|
||||
typer.Option(
|
||||
"--pip/--no-pip",
|
||||
help="Pip install the template(s) as editable dependencies",
|
||||
@@ -127,24 +127,24 @@ def new(
|
||||
@app_cli.command()
|
||||
def add(
|
||||
dependencies: Annotated[
|
||||
Optional[list[str]],
|
||||
list[str] | None,
|
||||
typer.Argument(help="The dependency to add"),
|
||||
] = None,
|
||||
*,
|
||||
api_path: Annotated[
|
||||
Optional[list[str]],
|
||||
list[str] | None,
|
||||
typer.Option(help="API paths to add"),
|
||||
] = None,
|
||||
project_dir: Annotated[
|
||||
Optional[Path],
|
||||
Path | None,
|
||||
typer.Option(help="The project directory"),
|
||||
] = None,
|
||||
repo: Annotated[
|
||||
Optional[list[str]],
|
||||
list[str] | None,
|
||||
typer.Option(help="Install templates from a specific github repo instead"),
|
||||
] = None,
|
||||
branch: Annotated[
|
||||
Optional[list[str]],
|
||||
list[str] | None,
|
||||
typer.Option(help="Install templates from a specific branch"),
|
||||
] = None,
|
||||
pip: Annotated[
|
||||
@@ -186,7 +186,7 @@ def add(
|
||||
)
|
||||
|
||||
# group by repo/ref
|
||||
grouped: dict[tuple[str, Optional[str]], list[DependencySource]] = {}
|
||||
grouped: dict[tuple[str, str | None], list[DependencySource]] = {}
|
||||
for dep in parsed_deps:
|
||||
key_tup = (dep["git"], dep["ref"])
|
||||
lst = grouped.get(key_tup, [])
|
||||
@@ -305,7 +305,7 @@ def remove(
|
||||
api_paths: Annotated[list[str], typer.Argument(help="The API paths to remove")],
|
||||
*,
|
||||
project_dir: Annotated[
|
||||
Optional[Path],
|
||||
Path | None,
|
||||
typer.Option(help="The project directory"),
|
||||
] = None,
|
||||
) -> None:
|
||||
@@ -344,15 +344,15 @@ def remove(
|
||||
def serve(
|
||||
*,
|
||||
port: Annotated[
|
||||
Optional[int],
|
||||
int | None,
|
||||
typer.Option(help="The port to run the server on"),
|
||||
] = None,
|
||||
host: Annotated[
|
||||
Optional[str],
|
||||
str | None,
|
||||
typer.Option(help="The host to run the server on"),
|
||||
] = None,
|
||||
app: Annotated[
|
||||
Optional[str],
|
||||
str | None,
|
||||
typer.Option(help="The app to run, e.g. `app.server:app`"),
|
||||
] = None,
|
||||
) -> None:
|
||||
|
@@ -5,7 +5,7 @@ import re
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import Annotated, Optional, cast
|
||||
from typing import Annotated, cast
|
||||
|
||||
import typer
|
||||
from typing_extensions import TypedDict
|
||||
@@ -66,14 +66,14 @@ def new(
|
||||
),
|
||||
],
|
||||
name_class: Annotated[
|
||||
Optional[str],
|
||||
str | None,
|
||||
typer.Option(
|
||||
help="The name of the integration in PascalCase. e.g. `MyIntegration`."
|
||||
" This is used to name classes like `MyIntegrationVectorStore`",
|
||||
),
|
||||
] = None,
|
||||
src: Annotated[
|
||||
Optional[list[str]],
|
||||
list[str] | None,
|
||||
typer.Option(
|
||||
help="The name of the single template file to copy."
|
||||
" e.g. `--src integration_template/chat_models.py "
|
||||
@@ -81,7 +81,7 @@ def new(
|
||||
),
|
||||
] = None,
|
||||
dst: Annotated[
|
||||
Optional[list[str]],
|
||||
list[str] | None,
|
||||
typer.Option(
|
||||
help="The relative path to the integration package to place the new file in"
|
||||
". e.g. `my-integration/my_integration.py`",
|
||||
@@ -220,7 +220,7 @@ def create_doc(
|
||||
),
|
||||
],
|
||||
name_class: Annotated[
|
||||
Optional[str],
|
||||
str | None,
|
||||
typer.Option(
|
||||
help=(
|
||||
"The PascalCase name of the integration (e.g. `OpenAI`, "
|
||||
|
@@ -6,7 +6,6 @@ import os
|
||||
import pathlib
|
||||
from pathlib import Path
|
||||
from types import ModuleType
|
||||
from typing import Optional
|
||||
|
||||
from typing_extensions import override
|
||||
|
||||
@@ -22,7 +21,7 @@ PARTNER_PKGS = PKGS_ROOT / "partners"
|
||||
class ImportExtractor(ast.NodeVisitor):
|
||||
"""Import extractor."""
|
||||
|
||||
def __init__(self, *, from_package: Optional[str] = None) -> None:
|
||||
def __init__(self, *, from_package: str | None = None) -> None:
|
||||
"""Extract all imports from the given code, optionally filtering by package."""
|
||||
self.imports: list[tuple[str, str]] = []
|
||||
self.package = from_package
|
||||
@@ -105,7 +104,7 @@ def _get_all_classnames_from_file(file: Path, pkg: str) -> list[tuple[str, str]]
|
||||
def identify_all_imports_in_file(
|
||||
file: str,
|
||||
*,
|
||||
from_package: Optional[str] = None,
|
||||
from_package: str | None = None,
|
||||
) -> list[tuple[str, str]]:
|
||||
"""Identify all the imports in the given file.
|
||||
|
||||
@@ -191,7 +190,7 @@ def list_init_imports_by_package(pkg_root: str) -> list[tuple[str, str]]:
|
||||
def find_imports_from_package(
|
||||
code: str,
|
||||
*,
|
||||
from_package: Optional[str] = None,
|
||||
from_package: str | None = None,
|
||||
) -> list[tuple[str, str]]:
|
||||
"""Find imports in code.
|
||||
|
||||
|
@@ -4,7 +4,7 @@ import re
|
||||
import shutil
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import Annotated, Optional
|
||||
from typing import Annotated
|
||||
|
||||
import typer
|
||||
import uvicorn
|
||||
@@ -88,15 +88,15 @@ def new(
|
||||
def serve(
|
||||
*,
|
||||
port: Annotated[
|
||||
Optional[int],
|
||||
int | None,
|
||||
typer.Option(help="The port to run the server on"),
|
||||
] = None,
|
||||
host: Annotated[
|
||||
Optional[str],
|
||||
str | None,
|
||||
typer.Option(help="The host to run the server on"),
|
||||
] = None,
|
||||
configurable: Annotated[
|
||||
Optional[bool],
|
||||
bool | None,
|
||||
typer.Option(
|
||||
"--configurable/--no-configurable",
|
||||
help="Whether to include a configurable route",
|
||||
@@ -140,7 +140,7 @@ def serve(
|
||||
|
||||
|
||||
@package_cli.command()
|
||||
def list(contains: Annotated[Optional[str], typer.Argument()] = None) -> None: # noqa: A001
|
||||
def list(contains: Annotated[str | None, typer.Argument()] = None) -> None: # noqa: A001
|
||||
"""List all or search for available templates."""
|
||||
packages = list_packages(contains=contains)
|
||||
for package in packages:
|
||||
|
@@ -39,9 +39,6 @@ test_integration = []
|
||||
langchain-core = { path = "../core", editable = true }
|
||||
langchain = { path = "../langchain", editable = true }
|
||||
|
||||
[tool.ruff]
|
||||
target-version = "py39"
|
||||
|
||||
[tool.ruff.format]
|
||||
docstring-code-format = true
|
||||
|
||||
|
Reference in New Issue
Block a user