MCPcopy
hub / github.com/langchain-ai/langchain / main

Function main

libs/cli/langchain_cli/namespaces/migrate/main.py:35–145  ·  view source on GitHub ↗

Migrate langchain to the most recent version.

(
    path: Path = Argument(..., exists=True, dir_okay=True, allow_dash=False),
    disable: List[Rule] = Option(default=[], help="Disable a rule."),
    diff: bool = Option(False, help="Show diff instead of applying changes."),
    ignore: List[str] = Option(
        default=DEFAULT_IGNORES, help="Ignore a path glob pattern."
    ),
    log_file: Path = Option("log.txt", help="Log errors to this file."),
    include_ipynb: bool = Option(
        False, help="Include Jupyter Notebook files in the migration."
    ),
)

Source from the content-addressed store, hash-verified

33
34@app.callback()
35def main(
36 path: Path = Argument(..., exists=True, dir_okay=True, allow_dash=False),
37 disable: List[Rule] = Option(default=[], help="Disable a rule."),
38 diff: bool = Option(False, help="Show diff instead of applying changes."),
39 ignore: List[str] = Option(
40 default=DEFAULT_IGNORES, help="Ignore a path glob pattern."
41 ),
42 log_file: Path = Option("log.txt", help="Log errors to this file."),
43 include_ipynb: bool = Option(
44 False, help="Include Jupyter Notebook files in the migration."
45 ),
46):
47 """Migrate langchain to the most recent version."""
48 if not diff:
49 if not typer.confirm(
50 "✈️ This script will help you migrate to a recent version LangChain. "
51 "This migration script will attempt to replace old imports in the code "
52 "with new ones.\n\n"
53 "🔄 You will need to run the migration script TWICE to migrate (e.g., "
54 "to update llms import from langchain, the script will first move them to "
55 "corresponding imports from the community package, and on the second "
56 "run will migrate from the community package to the partner package "
57 "when possible). \n\n"
58 "🔍 You can pre-view the changes by running with the --diff flag. \n\n"
59 "🚫 You can disable specific import changes by using the --disable "
60 "flag. \n\n"
61 "📄 Update your pyproject.toml or requirements.txt file to "
62 "reflect any imports from new packages. For example, if you see new "
63 "imports from langchain_openai, langchain_anthropic or "
64 "langchain_text_splitters you "
65 "should them to your dependencies! \n\n"
66 '⚠️ This script is a "best-effort", and is likely to make some '
67 "mistakes.\n\n"
68 "🛡️ Backup your code prior to running the migration script -- it will "
69 "modify your files!\n\n"
70 "❓ Do you want to continue?"
71 ):
72 raise Exit()
73 console = Console(log_time=True)
74 console.log("Start langchain-cli migrate")
75 # NOTE: LIBCST_PARSER_TYPE=native is required according to https://github.com/Instagram/LibCST/issues/487.
76 os.environ["LIBCST_PARSER_TYPE"] = "native"
77
78 if os.path.isfile(path):
79 package = path.parent
80 all_files = [path]
81 else:
82 package = path
83 all_files = sorted(package.glob("**/*.py"))
84 if include_ipynb:
85 all_files.extend(sorted(package.glob("**/*.ipynb")))
86
87 filtered_files = [
88 file
89 for file in all_files
90 if not any(match_glob(file, pattern) for pattern in ignore)
91 ]
92 files = [str(file.relative_to(".")) for file in filtered_files]

Callers

nothing calls this directly

Calls 7

match_globFunction · 0.90
color_diffFunction · 0.85
add_taskMethod · 0.80
appendMethod · 0.80
logMethod · 0.45
extendMethod · 0.45
partialMethod · 0.45

Tested by

no test coverage detected