Skip to content

Commit 468d3c3

Browse files
authored
Merge branch 'master' into ruff-core-preview-2
2 parents 348756d + 4024d47 commit 468d3c3

File tree

102 files changed

+2708
-2237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+2708
-2237
lines changed

.github/workflows/api_doc_build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
done
7373
7474
- name: '🐍 Setup Python ${{ env.PYTHON_VERSION }}'
75-
uses: actions/setup-python@v5
75+
uses: actions/setup-python@v6
7676
id: setup-python
7777
with:
7878
python-version: ${{ env.PYTHON_VERSION }}

.github/workflows/check_diffs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: '📋 Checkout Code'
3636
uses: actions/checkout@v5
3737
- name: '🐍 Setup Python 3.11'
38-
uses: actions/setup-python@v5
38+
uses: actions/setup-python@v6
3939
with:
4040
python-version: '3.11'
4141
- name: '📂 Get Changed Files'

.github/workflows/check_new_docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
runs-on: ubuntu-latest
2424
steps:
2525
- uses: actions/checkout@v5
26-
- uses: actions/setup-python@v5
26+
- uses: actions/setup-python@v6
2727
with:
2828
python-version: '3.10'
2929
- id: files

.github/workflows/codspeed.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
with:
4545
python-version: "3.12"
4646

47-
- uses: actions/setup-python@v5
47+
- uses: actions/setup-python@v6
4848
with:
4949
python-version: "3.12"
5050

libs/cli/langchain_cli/dev_scripts.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,19 @@ def create_demo_server(
1414
config_keys: Sequence[str] = (),
1515
playground_type: Literal["default", "chat"] = "default",
1616
) -> FastAPI:
17-
"""Create a demo server for the current template."""
17+
"""Create a demo server for the current template.
18+
19+
Args:
20+
config_keys: Optional sequence of config keys to expose in the playground.
21+
playground_type: The type of playground to use. Can be `'default'` or `'chat'`.
22+
23+
Returns:
24+
The demo server.
25+
26+
Raises:
27+
KeyError: If the `pyproject.toml` file is missing required fields.
28+
ImportError: If the module defined in `pyproject.toml` cannot be imported.
29+
"""
1830
app = FastAPI()
1931
package_root = get_package_root()
2032
pyproject = package_root / "pyproject.toml"
@@ -41,10 +53,18 @@ def create_demo_server(
4153

4254

4355
def create_demo_server_configurable() -> FastAPI:
44-
"""Create a configurable demo server."""
56+
"""Create a configurable demo server.
57+
58+
Returns:
59+
The configurable demo server.
60+
"""
4561
return create_demo_server(config_keys=["configurable"])
4662

4763

4864
def create_demo_server_chat() -> FastAPI:
49-
"""Create a chat demo server."""
65+
"""Create a chat demo server.
66+
67+
Returns:
68+
The chat demo server.
69+
"""
5070
return create_demo_server(playground_type="chat")

libs/cli/langchain_cli/namespaces/migrate/generate/generic.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@ def generate_raw_migrations(
1111
to_package: str,
1212
filter_by_all: bool = False, # noqa: FBT001, FBT002
1313
) -> list[tuple[str, str]]:
14-
"""Scan the `langchain` package and generate migrations for all modules."""
14+
"""Scan the `langchain` package and generate migrations for all modules.
15+
16+
Args:
17+
from_package: The package to migrate from.
18+
to_package: The package to migrate to.
19+
filter_by_all: Whether to only consider items in `__all__`.
20+
21+
Returns:
22+
A list of tuples containing the original import path and the new import path.
23+
"""
1524
package = importlib.import_module(from_package)
1625

1726
items = []
@@ -84,6 +93,13 @@ def generate_top_level_imports(pkg: str) -> list[tuple[str, str]]:
8493
and the second tuple will contain the path
8594
to importing it from the top level namespaces
8695
(e.g., ``langchain_community.chat_models.XYZ``)
96+
97+
Args:
98+
pkg: The package to scan.
99+
100+
Returns:
101+
A list of tuples containing the fully qualified path and the top-level
102+
import path.
87103
"""
88104
package = importlib.import_module(pkg)
89105

@@ -130,7 +146,17 @@ def generate_simplified_migrations(
130146
to_package: str,
131147
filter_by_all: bool = True, # noqa: FBT001, FBT002
132148
) -> list[tuple[str, str]]:
133-
"""Get all the raw migrations, then simplify them if possible."""
149+
"""Get all the raw migrations, then simplify them if possible.
150+
151+
Args:
152+
from_package: The package to migrate from.
153+
to_package: The package to migrate to.
154+
filter_by_all: Whether to only consider items in `__all__`.
155+
156+
Returns:
157+
A list of tuples containing the original import path and the simplified
158+
import path.
159+
"""
134160
raw_migrations = generate_raw_migrations(
135161
from_package,
136162
to_package,

libs/cli/langchain_cli/namespaces/migrate/generate/grit.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@
22

33

44
def split_package(package: str) -> tuple[str, str]:
5-
"""Split a package name into the containing package and the final name."""
5+
"""Split a package name into the containing package and the final name.
6+
7+
Args:
8+
package: The full package name.
9+
10+
Returns:
11+
A tuple of `(containing_package, final_name)`.
12+
"""
613
parts = package.split(".")
714
return ".".join(parts[:-1]), parts[-1]
815

916

1017
def dump_migrations_as_grit(name: str, migration_pairs: list[tuple[str, str]]) -> str:
11-
"""Dump the migration pairs as a Grit file."""
18+
"""Dump the migration pairs as a Grit file.
19+
20+
Args:
21+
name: The name of the migration.
22+
migration_pairs: A list of tuples `(from_module, to_module)`.
23+
24+
Returns:
25+
The Grit file as a string.
26+
"""
1227
remapped = ",\n".join(
1328
[
1429
f"""

libs/cli/langchain_cli/namespaces/migrate/generate/utils.py

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,15 @@ def visit_ClassDef(self, node: ast.ClassDef) -> None:
5959

6060

6161
def is_subclass(class_obj: type, classes_: list[type]) -> bool:
62-
"""Check if the given class object is a subclass of any class in list classes."""
62+
"""Check if the given class object is a subclass of any class in list classes.
63+
64+
Args:
65+
class_obj: The class to check.
66+
classes_: A list of classes to check against.
67+
68+
Returns:
69+
True if `class_obj` is a subclass of any class in `classes_`, False otherwise.
70+
"""
6371
return any(
6472
issubclass(class_obj, kls)
6573
for kls in classes_
@@ -68,7 +76,15 @@ def is_subclass(class_obj: type, classes_: list[type]) -> bool:
6876

6977

7078
def find_subclasses_in_module(module: ModuleType, classes_: list[type]) -> list[str]:
71-
"""Find all classes in the module that inherit from one of the classes."""
79+
"""Find all classes in the module that inherit from one of the classes.
80+
81+
Args:
82+
module: The module to inspect.
83+
classes_: A list of classes to check against.
84+
85+
Returns:
86+
A list of class names that are subclasses of any class in `classes_`.
87+
"""
7288
subclasses = []
7389
# Iterate over all attributes of the module that are classes
7490
for _name, obj in inspect.getmembers(module, inspect.isclass):
@@ -91,7 +107,15 @@ def identify_all_imports_in_file(
91107
*,
92108
from_package: Optional[str] = None,
93109
) -> list[tuple[str, str]]:
94-
"""Let's also identify all the imports in the given file."""
110+
"""Identify all the imports in the given file.
111+
112+
Args:
113+
file: The file to analyze.
114+
from_package: If provided, only return imports from this package.
115+
116+
Returns:
117+
A list of tuples `(module, name)` representing the imports found in the file.
118+
"""
95119
code = Path(file).read_text(encoding="utf-8")
96120
return find_imports_from_package(code, from_package=from_package)
97121

@@ -106,6 +130,9 @@ def identify_pkg_source(pkg_root: str) -> pathlib.Path:
106130
Returns:
107131
Returns the path to the source code for the package.
108132
133+
Raises:
134+
ValueError: If there is not exactly one directory starting with `'langchain_'`
135+
in the package root.
109136
"""
110137
dirs = [d for d in Path(pkg_root).iterdir() if d.is_dir()]
111138
matching_dirs = [d for d in dirs if d.name.startswith("langchain_")]
@@ -116,7 +143,15 @@ def identify_pkg_source(pkg_root: str) -> pathlib.Path:
116143

117144

118145
def list_classes_by_package(pkg_root: str) -> list[tuple[str, str]]:
119-
"""List all classes in a package."""
146+
"""List all classes in a package.
147+
148+
Args:
149+
pkg_root: the root of the package.
150+
151+
Returns:
152+
A list of tuples `(module, class_name)` representing all classes found in the
153+
package, excluding test files.
154+
"""
120155
module_classes = []
121156
pkg_source = identify_pkg_source(pkg_root)
122157
files = list(pkg_source.rglob("*.py"))
@@ -130,7 +165,15 @@ def list_classes_by_package(pkg_root: str) -> list[tuple[str, str]]:
130165

131166

132167
def list_init_imports_by_package(pkg_root: str) -> list[tuple[str, str]]:
133-
"""List all the things that are being imported in a package by module."""
168+
"""List all the things that are being imported in a package by module.
169+
170+
Args:
171+
pkg_root: the root of the package.
172+
173+
Returns:
174+
A list of tuples `(module, name)` representing the imports found in
175+
`__init__.py` files.
176+
"""
134177
imports = []
135178
pkg_source = identify_pkg_source(pkg_root)
136179
# Scan all the files in the package
@@ -150,7 +193,15 @@ def find_imports_from_package(
150193
*,
151194
from_package: Optional[str] = None,
152195
) -> list[tuple[str, str]]:
153-
"""Find imports in code."""
196+
"""Find imports in code.
197+
198+
Args:
199+
code: The code to analyze.
200+
from_package: If provided, only return imports from this package.
201+
202+
Returns:
203+
A list of tuples `(module, name)` representing the imports found.
204+
"""
154205
# Parse the code into an AST
155206
tree = ast.parse(code)
156207
# Create an instance of the visitor

libs/cli/langchain_cli/utils/events.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ class EventDict(TypedDict):
2222

2323

2424
def create_events(events: list[EventDict]) -> Optional[dict[str, Any]]:
25-
"""Create events."""
25+
"""Create events.
26+
27+
Args:
28+
events: A list of event dictionaries.
29+
30+
Returns:
31+
The response from the event tracking service, or None if there was an error.
32+
"""
2633
try:
2734
data = {
2835
"events": [

libs/cli/langchain_cli/utils/find_replace.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44

55

66
def find_and_replace(source: str, replacements: dict[str, str]) -> str:
7-
"""Find and replace text in a string."""
7+
"""Find and replace text in a string.
8+
9+
Args:
10+
source: The source string.
11+
replacements: A dictionary of `{find: replace}` pairs.
12+
13+
Returns:
14+
The modified string.
15+
"""
816
rtn = source
917

1018
# replace keys in deterministic alphabetical order

0 commit comments

Comments
 (0)