mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-31 16:39:20 +00:00
cli[patch]: Ignore imports that change the name of the class (#21026)
Not currently handeled by migration script
This commit is contained in:
parent
ce89b34fc0
commit
aab78a37f3
@ -2123,4 +2123,4 @@
|
||||
"langchain.vectorstores.singlestoredb.SingleStoreDBRetriever",
|
||||
"langchain_core.vectorstores.VectorStoreRetriever"
|
||||
]
|
||||
]
|
||||
]
|
||||
|
@ -29,7 +29,17 @@ def _load_migrations_by_file(path: str):
|
||||
migrations_path = os.path.join(HERE, "migrations", path)
|
||||
with open(migrations_path, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
return data
|
||||
|
||||
# new migrations
|
||||
new_migrations = []
|
||||
for migration in data:
|
||||
old = migration[0].split(".")[-1]
|
||||
new = migration[1].split(".")[-1]
|
||||
|
||||
if old == new:
|
||||
new_migrations.append(migration)
|
||||
|
||||
return new_migrations
|
||||
|
||||
|
||||
T = TypeVar("T")
|
||||
|
31
libs/cli/tests/unit_tests/migrate/test_code_migrations.py
Normal file
31
libs/cli/tests/unit_tests/migrate/test_code_migrations.py
Normal file
@ -0,0 +1,31 @@
|
||||
"""Verify that the code migrations do not involve alias changes.
|
||||
|
||||
Migration script only updates imports not the rest of the code that uses the
|
||||
import.
|
||||
"""
|
||||
from langchain_cli.namespaces.migrate.codemods.replace_imports import (
|
||||
RULE_TO_PATHS,
|
||||
_load_migrations_from_fixtures,
|
||||
)
|
||||
|
||||
|
||||
def test_migration_files() -> None:
|
||||
"""Generate a codemod to replace imports."""
|
||||
errors = []
|
||||
|
||||
for paths in list(RULE_TO_PATHS.values()):
|
||||
for path in paths:
|
||||
migrations = _load_migrations_from_fixtures([path])
|
||||
|
||||
for migration in migrations:
|
||||
old = migration[0].split(".")[-1]
|
||||
new = migration[1].split(".")[-1]
|
||||
if old != new:
|
||||
errors.append((path, migration))
|
||||
|
||||
if errors:
|
||||
raise ValueError(
|
||||
f"Migration involves an alias change: {errors}. The "
|
||||
f"migration script does not currently support "
|
||||
f"corresponding code changes."
|
||||
)
|
Loading…
Reference in New Issue
Block a user