mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
repo: consolidate Repo.open logic
This commit is contained in:
+1
-1
@@ -245,7 +245,7 @@ def main(argv=None): # noqa: C901, PLR0912, PLR0915
|
|||||||
finally:
|
finally:
|
||||||
logger.setLevel(outer_log_level)
|
logger.setLevel(outer_log_level)
|
||||||
|
|
||||||
from dvc.external_repo import clean_repos
|
from dvc.repo.open_repo import clean_repos
|
||||||
|
|
||||||
# Remove cached repos in the end of the call, these are anonymous
|
# Remove cached repos in the end of the call, these are anonymous
|
||||||
# so won't be reused by any other subsequent run anyway.
|
# so won't be reused by any other subsequent run anyway.
|
||||||
|
|||||||
+2
-11
@@ -287,18 +287,9 @@ class Repo:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def open(url, *args, **kwargs): # noqa: A003
|
def open(url, *args, **kwargs): # noqa: A003
|
||||||
if url is None:
|
from .open_repo import open_repo
|
||||||
url = os.getcwd()
|
|
||||||
|
|
||||||
if os.path.exists(url):
|
return open_repo(url, *args, **kwargs)
|
||||||
try:
|
|
||||||
return Repo(url, *args, **kwargs)
|
|
||||||
except NotDvcRepoError:
|
|
||||||
pass # fallthrough to external_repo
|
|
||||||
|
|
||||||
from dvc.external_repo import external_repo
|
|
||||||
|
|
||||||
return external_repo(url, *args, **kwargs)
|
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def scm(self) -> Union["Git", "NoSCM"]:
|
def scm(self) -> Union["Git", "NoSCM"]:
|
||||||
|
|||||||
+1
-1
@@ -24,8 +24,8 @@ def get(url, path, out=None, rev=None, jobs=None, force=False):
|
|||||||
import shortuuid
|
import shortuuid
|
||||||
|
|
||||||
from dvc.dvcfile import is_valid_filename
|
from dvc.dvcfile import is_valid_filename
|
||||||
from dvc.external_repo import external_repo
|
|
||||||
from dvc.fs.callbacks import Callback
|
from dvc.fs.callbacks import Callback
|
||||||
|
from dvc.repo.open_repo import external_repo
|
||||||
|
|
||||||
out = resolve_output(path, out, force=force)
|
out = resolve_output(path, out, force=force)
|
||||||
|
|
||||||
|
|||||||
@@ -13,10 +13,9 @@ from dvc.scm import CloneError, map_scm_exception
|
|||||||
from dvc.utils import relpath
|
from dvc.utils import relpath
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from dvc.scm import Git
|
||||||
from dvc.types import StrPath
|
from dvc.types import StrPath
|
||||||
|
|
||||||
from .scm import Git
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -70,6 +69,19 @@ def external_repo(
|
|||||||
_remove(path)
|
_remove(path)
|
||||||
|
|
||||||
|
|
||||||
|
def open_repo(url, *args, **kwargs):
|
||||||
|
if url is None:
|
||||||
|
url = os.getcwd()
|
||||||
|
|
||||||
|
if os.path.exists(url):
|
||||||
|
try:
|
||||||
|
return Repo(url, *args, **kwargs)
|
||||||
|
except NotDvcRepoError:
|
||||||
|
pass # fallthrough to external_repo
|
||||||
|
|
||||||
|
return external_repo(url, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def erepo_factory(url, root_dir, cache_config):
|
def erepo_factory(url, root_dir, cache_config):
|
||||||
from dvc.fs import localfs
|
from dvc.fs import localfs
|
||||||
|
|
||||||
+1
-1
@@ -60,7 +60,7 @@ def enable_ui():
|
|||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def clean_repos():
|
def clean_repos():
|
||||||
from dvc.external_repo import clean_repos
|
from dvc.repo.open_repo import clean_repos
|
||||||
|
|
||||||
clean_repos()
|
clean_repos()
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from flaky.flaky_decorator import flaky
|
|||||||
import dvc_data
|
import dvc_data
|
||||||
from dvc.cli import main
|
from dvc.cli import main
|
||||||
from dvc.exceptions import CheckoutError
|
from dvc.exceptions import CheckoutError
|
||||||
from dvc.external_repo import clean_repos
|
from dvc.repo.open_repo import clean_repos
|
||||||
from dvc.stage.exceptions import StageNotFound
|
from dvc.stage.exceptions import StageNotFound
|
||||||
from dvc.testing.remote_tests import TestRemote # noqa, pylint: disable=unused-import
|
from dvc.testing.remote_tests import TestRemote # noqa, pylint: disable=unused-import
|
||||||
from dvc.utils.fs import remove
|
from dvc.utils.fs import remove
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
from unittest.mock import ANY
|
from unittest.mock import ANY
|
||||||
|
|
||||||
from dvc.external_repo import CLONES, external_repo
|
from dvc.repo.open_repo import CLONES, external_repo
|
||||||
from dvc.scm import Git
|
from dvc.scm import Git
|
||||||
from dvc.testing.tmp_dir import make_subrepo
|
from dvc.testing.tmp_dir import make_subrepo
|
||||||
from dvc.utils import relpath
|
from dvc.utils import relpath
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from unittest.mock import call
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from dvc.external_repo import external_repo
|
from dvc.repo.open_repo import external_repo
|
||||||
from dvc.testing.tmp_dir import make_subrepo
|
from dvc.testing.tmp_dir import make_subrepo
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user