|
|
@ -9,7 +9,6 @@ from typing import List, Sequence
|
|
|
|
import typer
|
|
|
|
import typer
|
|
|
|
|
|
|
|
|
|
|
|
import langchain
|
|
|
|
import langchain
|
|
|
|
from langchain.cli.create_repo.pypi_name import is_name_taken, lint_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UnderscoreTemplate(string.Template):
|
|
|
|
class UnderscoreTemplate(string.Template):
|
|
|
@ -145,7 +144,7 @@ def _pip_install(project_directory_path: Path) -> None:
|
|
|
|
def _init_git(project_directory_path: Path) -> None:
|
|
|
|
def _init_git(project_directory_path: Path) -> None:
|
|
|
|
"""Initialize git repository."""
|
|
|
|
"""Initialize git repository."""
|
|
|
|
typer.echo(
|
|
|
|
typer.echo(
|
|
|
|
f"\n{typer.style('3.', bold=True, fg=typer.colors.GREEN)} Initializing git..."
|
|
|
|
f"\n{typer.style('Initializing git...', bold=True, fg=typer.colors.GREEN)}"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
subprocess.run(["git", "init"], cwd=project_directory_path)
|
|
|
|
subprocess.run(["git", "init"], cwd=project_directory_path)
|
|
|
|
|
|
|
|
|
|
|
@ -157,58 +156,12 @@ def _init_git(project_directory_path: Path) -> None:
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _select_project_name(suggested_project_name: str) -> str:
|
|
|
|
|
|
|
|
"""Help the user select a valid project name."""
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
|
|
|
project_name = typer.prompt(
|
|
|
|
|
|
|
|
"Please choose a project name: ", default=suggested_project_name
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
project_name_diagnostics = lint_name(project_name)
|
|
|
|
|
|
|
|
if project_name_diagnostics:
|
|
|
|
|
|
|
|
typer.echo(
|
|
|
|
|
|
|
|
f"{typer.style('Error:', fg=typer.colors.RED)}"
|
|
|
|
|
|
|
|
f" The project name"
|
|
|
|
|
|
|
|
f" {typer.style(project_name, fg=typer.colors.BRIGHT_CYAN)}"
|
|
|
|
|
|
|
|
f" is not valid:",
|
|
|
|
|
|
|
|
err=True,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for diagnostic in project_name_diagnostics:
|
|
|
|
|
|
|
|
typer.echo(f" - {diagnostic}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if typer.confirm(
|
|
|
|
|
|
|
|
"Would you like to choose another name? "
|
|
|
|
|
|
|
|
"Choose NO to proceed with existing name.",
|
|
|
|
|
|
|
|
default=True,
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if is_name_taken(project_name):
|
|
|
|
|
|
|
|
typer.echo(
|
|
|
|
|
|
|
|
f"{typer.style('Error:', fg=typer.colors.RED)}"
|
|
|
|
|
|
|
|
f" The project name"
|
|
|
|
|
|
|
|
f" {typer.style(project_name, fg=typer.colors.BRIGHT_CYAN)}"
|
|
|
|
|
|
|
|
f" is already taken on pypi",
|
|
|
|
|
|
|
|
err=True,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if typer.confirm(
|
|
|
|
|
|
|
|
"Would you like to choose another name? "
|
|
|
|
|
|
|
|
"Choose NO to proceed with existing name.",
|
|
|
|
|
|
|
|
default=True,
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# If we got here then the project name is valid and not taken
|
|
|
|
|
|
|
|
return project_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# PUBLIC API
|
|
|
|
# PUBLIC API
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create(
|
|
|
|
def create(
|
|
|
|
project_directory: pathlib.Path,
|
|
|
|
project_directory: pathlib.Path,
|
|
|
|
|
|
|
|
project_name: str,
|
|
|
|
author_name: str,
|
|
|
|
author_name: str,
|
|
|
|
author_email: str,
|
|
|
|
author_email: str,
|
|
|
|
use_poetry: bool,
|
|
|
|
use_poetry: bool,
|
|
|
@ -217,27 +170,29 @@ def create(
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
project_directory (str): The directory to create the project in.
|
|
|
|
project_directory (str): The directory to create the project in.
|
|
|
|
|
|
|
|
project_name: The name of the project.
|
|
|
|
author_name (str): The name of the author.
|
|
|
|
author_name (str): The name of the author.
|
|
|
|
author_email (str): The email of the author.
|
|
|
|
author_email (str): The email of the author.
|
|
|
|
use_poetry (bool): Whether to use Poetry to manage the project.
|
|
|
|
use_poetry (bool): Whether to use Poetry to manage the project.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
project_directory_path = Path(project_directory)
|
|
|
|
project_directory_path = Path(project_directory)
|
|
|
|
project_name_suggestion = project_directory_path.name.replace("-", "_")
|
|
|
|
|
|
|
|
project_name = _select_project_name(project_name_suggestion)
|
|
|
|
|
|
|
|
project_name_identifier = project_name
|
|
|
|
project_name_identifier = project_name
|
|
|
|
|
|
|
|
|
|
|
|
resolved_path = project_directory_path.resolve()
|
|
|
|
resolved_path = project_directory_path.resolve()
|
|
|
|
|
|
|
|
|
|
|
|
if not typer.confirm(
|
|
|
|
if not typer.confirm(
|
|
|
|
f"\n{typer.style('>', bold=True, fg=typer.colors.GREEN)} "
|
|
|
|
f"\n"
|
|
|
|
f"Creating new LangChain project "
|
|
|
|
f"Creating a new LangChain project 🦜️🔗\n"
|
|
|
|
f"{typer.style(project_name, fg=typer.colors.BRIGHT_CYAN)}"
|
|
|
|
f"Name: {typer.style(project_name, fg=typer.colors.BRIGHT_CYAN)}\n"
|
|
|
|
f" in"
|
|
|
|
f"Path: {typer.style(resolved_path, fg=typer.colors.BRIGHT_CYAN)}\n"
|
|
|
|
f" {typer.style(resolved_path, fg=typer.colors.BRIGHT_CYAN)}",
|
|
|
|
f"Project name: {typer.style(project_name, fg=typer.colors.BRIGHT_CYAN)}\n"
|
|
|
|
|
|
|
|
f"Author name: {typer.style(author_name, fg=typer.colors.BRIGHT_CYAN)}\n"
|
|
|
|
|
|
|
|
f"Author email: {typer.style(author_email, fg=typer.colors.BRIGHT_CYAN)}\n"
|
|
|
|
|
|
|
|
f"Use Poetry: {typer.style(str(use_poetry), fg=typer.colors.BRIGHT_CYAN)}\n"
|
|
|
|
|
|
|
|
"Continue?",
|
|
|
|
default=True,
|
|
|
|
default=True,
|
|
|
|
):
|
|
|
|
):
|
|
|
|
typer.echo("OK! Canceling project creation.")
|
|
|
|
typer.echo("Cancelled project creation. See you later! 👋")
|
|
|
|
raise typer.Exit(code=0)
|
|
|
|
raise typer.Exit(code=0)
|
|
|
|
|
|
|
|
|
|
|
|
_create_project_dir(
|
|
|
|
_create_project_dir(
|
|
|
@ -258,7 +213,7 @@ def create(
|
|
|
|
_init_git(project_directory_path)
|
|
|
|
_init_git(project_directory_path)
|
|
|
|
|
|
|
|
|
|
|
|
typer.echo(
|
|
|
|
typer.echo(
|
|
|
|
f"\n{typer.style('Done!', bold=True, fg=typer.colors.GREEN)}"
|
|
|
|
f"\n{typer.style('Done!🙌', bold=True, fg=typer.colors.GREEN)}"
|
|
|
|
f" Your new LangChain project"
|
|
|
|
f" Your new LangChain project"
|
|
|
|
f" {typer.style(project_name, fg=typer.colors.BRIGHT_CYAN)}"
|
|
|
|
f" {typer.style(project_name, fg=typer.colors.BRIGHT_CYAN)}"
|
|
|
|
f" has been created in"
|
|
|
|
f" has been created in"
|
|
|
|