mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-02 03:26:17 +00:00
cli improvements (#12465)
Features - add multiple repos by their branch/repo - generate `pip install` commands and `add_route()` code  Optimizations: - group installs by repo/branch to avoid duplicate cloning
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
from typing import Dict, Optional
|
||||
|
||||
import pytest
|
||||
|
||||
from langchain_cli.constants import (
|
||||
@@ -8,44 +10,74 @@ from langchain_cli.constants import (
|
||||
from langchain_cli.utils.git import DependencySource, parse_dependency_string
|
||||
|
||||
|
||||
def _assert_dependency_equals(
|
||||
dep: DependencySource,
|
||||
*,
|
||||
git: Optional[str] = None,
|
||||
ref: Optional[str] = None,
|
||||
subdirectory: Optional[str] = None,
|
||||
event_metadata: Optional[Dict] = None,
|
||||
) -> None:
|
||||
assert dep["git"] == git
|
||||
assert dep["ref"] == ref
|
||||
assert dep["subdirectory"] == subdirectory
|
||||
if event_metadata is not None:
|
||||
assert dep["event_metadata"] == event_metadata
|
||||
|
||||
|
||||
def test_dependency_string() -> None:
|
||||
assert parse_dependency_string(
|
||||
"git+ssh://git@github.com/efriis/myrepo.git"
|
||||
) == DependencySource(
|
||||
_assert_dependency_equals(
|
||||
parse_dependency_string(
|
||||
"git+ssh://git@github.com/efriis/myrepo.git", None, None, None
|
||||
),
|
||||
git="ssh://git@github.com/efriis/myrepo.git",
|
||||
ref=None,
|
||||
subdirectory=None,
|
||||
)
|
||||
|
||||
assert parse_dependency_string(
|
||||
"git+https://github.com/efriis/myrepo.git#subdirectory=src"
|
||||
) == DependencySource(
|
||||
_assert_dependency_equals(
|
||||
parse_dependency_string(
|
||||
"git+https://github.com/efriis/myrepo.git#subdirectory=src",
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
git="https://github.com/efriis/myrepo.git",
|
||||
subdirectory="src",
|
||||
ref=None,
|
||||
)
|
||||
|
||||
assert parse_dependency_string(
|
||||
"git+ssh://git@github.com:efriis/myrepo.git#develop"
|
||||
) == DependencySource(
|
||||
git="ssh://git@github.com:efriis/myrepo.git", ref="develop", subdirectory=None
|
||||
_assert_dependency_equals(
|
||||
parse_dependency_string(
|
||||
"git+ssh://git@github.com:efriis/myrepo.git#develop", None, None, None
|
||||
),
|
||||
git="ssh://git@github.com:efriis/myrepo.git",
|
||||
ref="develop",
|
||||
subdirectory=None,
|
||||
)
|
||||
|
||||
# also support a slash in ssh
|
||||
assert parse_dependency_string(
|
||||
"git+ssh://git@github.com/efriis/myrepo.git#develop"
|
||||
) == DependencySource(
|
||||
git="ssh://git@github.com/efriis/myrepo.git", ref="develop", subdirectory=None
|
||||
_assert_dependency_equals(
|
||||
parse_dependency_string(
|
||||
"git+ssh://git@github.com/efriis/myrepo.git#develop", None, None, None
|
||||
),
|
||||
git="ssh://git@github.com/efriis/myrepo.git",
|
||||
ref="develop",
|
||||
subdirectory=None,
|
||||
)
|
||||
|
||||
# looks like poetry supports both an @ and a #
|
||||
assert parse_dependency_string(
|
||||
"git+ssh://git@github.com:efriis/myrepo.git@develop"
|
||||
) == DependencySource(
|
||||
git="ssh://git@github.com:efriis/myrepo.git", ref="develop", subdirectory=None
|
||||
_assert_dependency_equals(
|
||||
parse_dependency_string(
|
||||
"git+ssh://git@github.com:efriis/myrepo.git@develop", None, None, None
|
||||
),
|
||||
git="ssh://git@github.com:efriis/myrepo.git",
|
||||
ref="develop",
|
||||
subdirectory=None,
|
||||
)
|
||||
|
||||
assert parse_dependency_string("simple-pirate") == DependencySource(
|
||||
_assert_dependency_equals(
|
||||
parse_dependency_string("simple-pirate", None, None, None),
|
||||
git=DEFAULT_GIT_REPO,
|
||||
subdirectory=f"{DEFAULT_GIT_SUBDIRECTORY}/simple-pirate",
|
||||
ref=DEFAULT_GIT_REF,
|
||||
@@ -53,9 +85,13 @@ def test_dependency_string() -> None:
|
||||
|
||||
|
||||
def test_dependency_string_both() -> None:
|
||||
assert parse_dependency_string(
|
||||
"git+https://github.com/efriis/myrepo.git@branch#subdirectory=src"
|
||||
) == DependencySource(
|
||||
_assert_dependency_equals(
|
||||
parse_dependency_string(
|
||||
"git+https://github.com/efriis/myrepo.git@branch#subdirectory=src",
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
git="https://github.com/efriis/myrepo.git",
|
||||
subdirectory="src",
|
||||
ref="branch",
|
||||
@@ -66,7 +102,10 @@ def test_dependency_string_invalids() -> None:
|
||||
# expect error for wrong order
|
||||
with pytest.raises(ValueError):
|
||||
parse_dependency_string(
|
||||
"git+https://github.com/efriis/myrepo.git#subdirectory=src@branch"
|
||||
"git+https://github.com/efriis/myrepo.git#subdirectory=src@branch",
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
# expect error for @subdirectory
|
||||
|
||||
@@ -77,16 +116,21 @@ def test_dependency_string_edge_case() -> None:
|
||||
# this could be a ssh dep with user=a, and default ref
|
||||
# or a ssh dep at a with ref=b.
|
||||
# in this case, assume the first case (be greedy with the '@')
|
||||
assert parse_dependency_string("git+ssh://a@b") == DependencySource(
|
||||
_assert_dependency_equals(
|
||||
parse_dependency_string("git+ssh://a@b", None, None, None),
|
||||
git="ssh://a@b",
|
||||
subdirectory=None,
|
||||
ref=None,
|
||||
)
|
||||
|
||||
# weird one that is actually valid
|
||||
assert parse_dependency_string(
|
||||
"git+https://github.com/efriis/myrepo.git@subdirectory=src"
|
||||
) == DependencySource(
|
||||
_assert_dependency_equals(
|
||||
parse_dependency_string(
|
||||
"git+https://github.com/efriis/myrepo.git@subdirectory=src",
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
),
|
||||
git="https://github.com/efriis/myrepo.git",
|
||||
subdirectory=None,
|
||||
ref="subdirectory=src",
|
||||
|
Reference in New Issue
Block a user