From 0da75b9ebd1e5a485a295d6f519f2d7be1f89f0a Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Thu, 2 Nov 2023 23:45:38 -0700 Subject: [PATCH] Autopopulate module name in cli init (#12814) --- libs/cli/langchain_cli/namespaces/template.py | 5 +++++ .../package_template/package_template/__init__.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/cli/langchain_cli/namespaces/template.py b/libs/cli/langchain_cli/namespaces/template.py index d9dc9e76f5958..03ca7e7f04c02 100644 --- a/libs/cli/langchain_cli/namespaces/template.py +++ b/libs/cli/langchain_cli/namespaces/template.py @@ -67,6 +67,11 @@ def new( package_dir = destination_dir / module_name shutil.move(destination_dir / "package_template", package_dir) + # update init + init = package_dir / "__init__.py" + init_contents = init.read_text() + init.write_text(init_contents.replace("__module_name__", module_name)) + # replace readme readme = destination_dir / "README.md" readme_contents = readme.read_text() diff --git a/libs/cli/langchain_cli/package_template/package_template/__init__.py b/libs/cli/langchain_cli/package_template/package_template/__init__.py index b941ff9ff11b2..ee137d673a00d 100644 --- a/libs/cli/langchain_cli/package_template/package_template/__init__.py +++ b/libs/cli/langchain_cli/package_template/package_template/__init__.py @@ -1,3 +1,3 @@ -from chain import chain +from __module_name__.chain import chain __all__ = ["chain"]