ruff: more rules across the board & fixes (#31898)

* standardizes ruff dep version across all `pyproject.toml` files
* cli: ruff rules and corrections
* langchain: rules and corrections
This commit is contained in:
Mason Daugherty
2025-07-07 17:48:01 -04:00
committed by GitHub
parent 706a66eccd
commit e7eac27241
408 changed files with 2783 additions and 1671 deletions

View File

@@ -79,7 +79,9 @@ def new(
package_prompt = "What package would you like to add? (leave blank to skip)"
while True:
package_str = typer.prompt(
package_prompt, default="", show_default=False
package_prompt,
default="",
show_default=False,
)
if not package_str:
break
@@ -121,26 +123,29 @@ def new(
typer.echo("Then add templates with commands like:\n")
typer.echo(" langchain app add extraction-openai-functions")
typer.echo(
" langchain app add git+ssh://git@github.com/efriis/simple-pirate.git\n\n"
" langchain app add git+ssh://git@github.com/efriis/simple-pirate.git\n\n",
)
@app_cli.command()
def add(
dependencies: Annotated[
Optional[list[str]], typer.Argument(help="The dependency to add")
Optional[list[str]],
typer.Argument(help="The dependency to add"),
] = None,
*,
api_path: Annotated[list[str], typer.Option(help="API paths to add")] = [],
project_dir: Annotated[
Optional[Path], typer.Option(help="The project directory")
Optional[Path],
typer.Option(help="The project directory"),
] = None,
repo: Annotated[
list[str],
typer.Option(help="Install templates from a specific github repo instead"),
] = [],
branch: Annotated[
list[str], typer.Option(help="Install templates from a specific branch")
list[str],
typer.Option(help="Install templates from a specific branch"),
] = [],
pip: Annotated[
bool,
@@ -152,13 +157,12 @@ def add(
),
],
) -> None:
"""Adds the specified template to the current LangServe app.
"""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
"""
if not branch and not repo:
warnings.warn(
"Adding templates from the default branch and repo is deprecated."
@@ -173,7 +177,7 @@ def add(
package_dir = project_root / "packages"
create_events(
[{"event": "serve add", "properties": {"parsed_dep": d}} for d in parsed_deps]
[{"event": "serve add", "properties": {"parsed_dep": d}} for d in parsed_deps],
)
# group by repo/ref
@@ -248,7 +252,7 @@ def add(
cmd = ["pip", "install", "-e", *installed_destination_strs]
cmd_str = " \\\n ".join(installed_destination_strs)
typer.echo(f"Running: pip install -e \\\n {cmd_str}")
subprocess.run(cmd, cwd=cwd)
subprocess.run(cmd, cwd=cwd) # noqa: S603
chain_names = []
for e in installed_exports:
@@ -296,10 +300,11 @@ def remove(
api_paths: Annotated[list[str], typer.Argument(help="The API paths to remove")],
*,
project_dir: Annotated[
Optional[Path], typer.Option(help="The project directory")
Optional[Path],
typer.Option(help="The project directory"),
] = None,
) -> None:
"""Removes the specified package from the current LangServe app."""
"""Remove the specified package from the current LangServe app."""
project_root = get_package_root(project_dir)
project_pyproject = project_root / "pyproject.toml"
@@ -320,7 +325,7 @@ def remove(
shutil.rmtree(package_dir)
remove_deps.append(api_path)
except Exception:
except Exception: # noqa: S110
pass
try:
@@ -334,16 +339,19 @@ def remove(
def serve(
*,
port: Annotated[
Optional[int], typer.Option(help="The port to run the server on")
Optional[int],
typer.Option(help="The port to run the server on"),
] = None,
host: Annotated[
Optional[str], typer.Option(help="The host to run the server on")
Optional[str],
typer.Option(help="The host to run the server on"),
] = None,
app: Annotated[
Optional[str], typer.Option(help="The app to run, e.g. `app.server:app`")
Optional[str],
typer.Option(help="The app to run, e.g. `app.server:app`"),
] = None,
) -> None:
"""Starts the LangServe app."""
"""Start the LangServe app."""
# add current dir as first entry of path
sys.path.append(str(Path.cwd()))
@@ -353,5 +361,8 @@ def serve(
import uvicorn
uvicorn.run(
app_str, host=host_str, port=port if port is not None else 8000, reload=True
app_str,
host=host_str,
port=port if port is not None else 8000,
reload=True,
)