Skip to content

Commit 31495ef

Browse files
committed
Hello from the other side
1 parent 270f3b9 commit 31495ef

File tree

9 files changed

+32
-156
lines changed

9 files changed

+32
-156
lines changed

scmrepo/__init__.py

Lines changed: 0 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +0,0 @@
1-
"""Manages source control systems (e.g. Git)."""
2-
from contextlib import contextmanager
3-
from typing import TYPE_CHECKING, Iterator
4-
5-
from dvc.exceptions import DvcException
6-
from dvc.progress import Tqdm
7-
from dvc.scm.base import Base # noqa: F401
8-
from dvc.scm.git import Git
9-
from dvc.scm.noscm import NoSCM
10-
11-
if TYPE_CHECKING:
12-
from dvc.scm.progress import GitProgressEvent
13-
14-
15-
class SCMError(DvcException):
16-
"""Base class for source control management errors."""
17-
18-
19-
class CloneError(SCMError):
20-
pass
21-
22-
23-
class RevError(SCMError):
24-
pass
25-
26-
27-
class NoSCMError(SCMError):
28-
def __init__(self):
29-
msg = (
30-
"Only supported for Git repositories. If you're "
31-
"seeing this error in a Git repo, try updating the DVC "
32-
"configuration with `dvc config core.no_scm false`."
33-
)
34-
super().__init__(msg)
35-
36-
37-
class InvalidRemoteSCMRepo(SCMError):
38-
pass
39-
40-
41-
class GitAuthError(SCMError):
42-
def __init__(self, reason: str) -> None:
43-
doc = "See https://dvc.org/doc//user-guide/troubleshooting#git-auth"
44-
super().__init__(f"{reason}\n{doc}")
45-
46-
47-
@contextmanager
48-
def map_scm_exception(with_cause: bool = False) -> Iterator[None]:
49-
from dvc.scm.exceptions import SCMError as InternalSCMError
50-
51-
try:
52-
yield
53-
except InternalSCMError as exc:
54-
into = SCMError(str(exc))
55-
if with_cause:
56-
raise into from exc
57-
raise into
58-
59-
60-
def SCM(
61-
root_dir, search_parent_directories=True, no_scm=False
62-
): # pylint: disable=invalid-name
63-
"""Returns SCM instance that corresponds to a repo at the specified
64-
path.
65-
66-
Args:
67-
root_dir (str): path to a root directory of the repo.
68-
search_parent_directories (bool): whether to look for repo root in
69-
parent directories.
70-
no_scm (bool): return NoSCM if True.
71-
72-
Returns:
73-
dvc.scm.base.Base: SCM instance.
74-
"""
75-
with map_scm_exception():
76-
if no_scm:
77-
return NoSCM(root_dir, _raise_not_implemented_as=NoSCMError)
78-
return Git(
79-
root_dir, search_parent_directories=search_parent_directories
80-
)
81-
82-
83-
class TqdmGit(Tqdm):
84-
def __init__(self, *args, **kwargs):
85-
kwargs.setdefault("unit", "obj")
86-
super().__init__(*args, **kwargs)
87-
88-
def update_git(self, event: "GitProgressEvent") -> None:
89-
phase, completed, total, message, *_ = event
90-
if phase:
91-
message = (phase + " | " + message) if message else phase
92-
if message:
93-
self.postfix["info"] = f" {message} | "
94-
if completed:
95-
self.update_to(completed, total)
96-
97-
98-
def clone(url: str, to_path: str, **kwargs):
99-
from dvc.scm.exceptions import CloneError as InternalCloneError
100-
101-
with TqdmGit(desc="Cloning") as pbar:
102-
try:
103-
return Git.clone(url, to_path, progress=pbar.update_git, **kwargs)
104-
except InternalCloneError as exc:
105-
raise CloneError(str(exc))
106-
107-
108-
def resolve_rev(scm: "Git", rev: str) -> str:
109-
from dvc.scm.exceptions import RevError as InternalRevError
110-
111-
try:
112-
return scm.resolve_rev(rev)
113-
except InternalRevError as exc:
114-
# `scm` will only resolve git branch and tag names,
115-
# if rev is not a sha it may be an abbreviated experiment name
116-
if not scm.is_sha(rev) and not rev.startswith("refs/"):
117-
from dvc.repo.experiments.utils import exp_refs_by_name
118-
119-
ref_infos = list(exp_refs_by_name(scm, rev))
120-
if len(ref_infos) == 1:
121-
return scm.get_ref(str(ref_infos[0]))
122-
if len(ref_infos) > 1:
123-
raise RevError(f"ambiguous Git revision '{rev}'")
124-
raise RevError(str(exc))

scmrepo/fs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
if TYPE_CHECKING:
1616
from io import BytesIO
1717

18-
from dvc.scm.git import Git
19-
from dvc.scm.git.objects import GitTrie
18+
from scmrepo.git import Git
19+
from scmrepo.git.objects import GitTrie
2020

2121

2222
def bytesio_len(obj: "BytesIO") -> Optional[int]:
@@ -43,8 +43,8 @@ def __init__(
4343
rev_resolver: Callable[["Git", str], str] = None,
4444
**kwargs,
4545
):
46-
from dvc.scm.git import Git
47-
from dvc.scm.git.objects import GitTrie
46+
from scmrepo.git import Git
47+
from scmrepo.git.objects import GitTrie
4848

4949
super().__init__(**kwargs)
5050
if not trie:
@@ -62,7 +62,7 @@ def __init__(
6262
self.rev = self.trie.rev
6363

6464
def _get_key(self, path: str) -> Tuple[str, ...]:
65-
from dvc.scm.utils import relpath
65+
from scmrepo.utils import relpath
6666

6767
if os.path.isabs(path):
6868
path = relpath(path, self.root_dir)

scmrepo/git/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
from funcy import cached_property, first
1212
from pathspec.patterns import GitWildMatchPattern
1313

14-
from dvc.scm.base import Base
15-
from dvc.scm.exceptions import (
14+
from scmrepo.base import Base
15+
from scmrepo.exceptions import (
1616
FileNotInRepoError,
1717
GitHookAlreadyExists,
1818
RevError,
1919
)
20-
from dvc.scm.utils import relpath
20+
from scmrepo.utils import relpath
2121

2222
from .backend.base import BaseGitBackend, NoGitBackendError
2323
from .backend.dulwich import DulwichBackend
@@ -256,7 +256,7 @@ def _backend_func(self, name, *args, **kwargs):
256256
raise NoGitBackendError(name)
257257

258258
def get_fs(self, rev: str):
259-
from dvc.fs.git import GitFileSystem
259+
from scmrepo.fs import GitFileSystem
260260

261261
return GitFileSystem(scm=self, rev=rev)
262262

scmrepo/git/backend/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
Union,
1111
)
1212

13-
from dvc.scm.exceptions import SCMError
13+
from scmrepo.exceptions import SCMError
1414

1515
from ..objects import GitObject
1616

1717
if TYPE_CHECKING:
18-
from dvc.scm.progress import GitProgressEvent
18+
from scmrepo.progress import GitProgressEvent
1919

2020
from ..objects import GitCommit
2121

scmrepo/git/backend/dulwich/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818

1919
from funcy import cached_property
2020

21-
from dvc.scm.exceptions import AuthError, InvalidRemote, SCMError
22-
from dvc.scm.utils import relpath
21+
from scmrepo.exceptions import AuthError, InvalidRemote, SCMError
22+
from scmrepo.utils import relpath
2323

2424
from ...objects import GitObject
2525
from ..base import BaseGitBackend
2626

2727
if TYPE_CHECKING:
28-
from dvc.scm.progress import GitProgressEvent
28+
from scmrepo.progress import GitProgressEvent
2929

3030
from ...objects import GitCommit
3131

@@ -442,7 +442,7 @@ def update_refs(refs):
442442
return new_refs
443443

444444
try:
445-
from dvc.scm.progress import GitProgressReporter
445+
from scmrepo.progress import GitProgressReporter
446446

447447
client.send_pack(
448448
path,
@@ -515,7 +515,7 @@ def determine_wants(remote_refs):
515515
f"'{url}' is not a valid Git remote or URL"
516516
) from exc
517517

518-
from dvc.scm.progress import GitProgressReporter
518+
from scmrepo.progress import GitProgressReporter
519519

520520
fetch_result = client.fetch(
521521
path,
@@ -552,7 +552,7 @@ def _stash_push(
552552
) -> Tuple[Optional[str], bool]:
553553
from dulwich.repo import InvalidUserIdentity
554554

555-
from dvc.scm.git import Stash
555+
from scmrepo.git import Stash
556556

557557
if include_untracked or ref == Stash.DEFAULT_STASH:
558558
# dulwich stash.push does not support include_untracked and does
@@ -573,7 +573,7 @@ def _stash_apply(self, rev: str):
573573
raise NotImplementedError
574574

575575
def _stash_drop(self, ref: str, index: int):
576-
from dvc.scm.git import Stash
576+
from scmrepo.git import Stash
577577

578578
if ref == Stash.DEFAULT_STASH:
579579
raise NotImplementedError

scmrepo/git/backend/dulwich/asyncssh_vendor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from dulwich.client import SSHVendor
55

6-
from dvc.scm.asyn import BaseAsyncObject, sync_wrapper
6+
from scmrepo.asyn import BaseAsyncObject, sync_wrapper
77

88

99
class _StderrWrapper:

scmrepo/git/backend/gitpython.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@
1818

1919
from funcy import ignore
2020

21-
from dvc.scm.exceptions import (
21+
from scmrepo.exceptions import (
2222
CloneError,
2323
MergeConflictError,
2424
RevError,
2525
SCMError,
2626
UnsupportedIndexFormat,
2727
)
28-
from dvc.scm.utils import relpath
28+
from scmrepo.utils import relpath
2929

3030
from ..objects import GitCommit, GitObject
3131
from .base import BaseGitBackend
3232

3333
if TYPE_CHECKING:
34-
from dvc.scm.progress import GitProgressEvent
34+
from scmrepo.progress import GitProgressEvent
3535

3636

3737
logger = logging.getLogger(__name__)
@@ -169,7 +169,7 @@ def clone(
169169
# scheme is used
170170
url = f"file://{url}"
171171

172-
from dvc.scm.progress import GitProgressReporter
172+
from scmrepo.progress import GitProgressReporter
173173

174174
clone_from = partial(
175175
Repo.clone_from,
@@ -487,7 +487,7 @@ def _stash_push(
487487
message: Optional[str] = None,
488488
include_untracked: Optional[bool] = False,
489489
) -> Tuple[Optional[str], bool]:
490-
from dvc.scm.git import Stash
490+
from scmrepo.git import Stash
491491

492492
args = ["push"]
493493
if message:
@@ -523,7 +523,7 @@ def _stash_apply(self, rev: str):
523523
def _stash_drop(self, ref: str, index: int):
524524
from git.exc import GitCommandError
525525

526-
from dvc.scm.git import Stash
526+
from scmrepo.git import Stash
527527

528528
if ref == Stash.DEFAULT_STASH:
529529
self.git.stash("drop", index)

scmrepo/git/backend/pygit2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
from funcy import cached_property
1919

20-
from dvc.scm.exceptions import MergeConflictError, RevError, SCMError
21-
from dvc.scm.utils import relpath
20+
from scmrepo.exceptions import MergeConflictError, RevError, SCMError
21+
from scmrepo.utils import relpath
2222

2323
from ..objects import GitCommit, GitObject
2424
from .base import BaseGitBackend
@@ -27,7 +27,7 @@
2727

2828

2929
if TYPE_CHECKING:
30-
from dvc.scm.progress import GitProgressEvent
30+
from scmrepo.progress import GitProgressEvent
3131

3232
# NOTE: constant from libgit2 git2/checkout.h
3333
# This can be removed after next pygit2 release:
@@ -399,7 +399,7 @@ def _stash_push(
399399
message: Optional[str] = None,
400400
include_untracked: Optional[bool] = False,
401401
) -> Tuple[Optional[str], bool]:
402-
from dvc.scm.git import Stash
402+
from scmrepo.git import Stash
403403

404404
oid = self.repo.stash(
405405
self.default_signature,
@@ -416,7 +416,7 @@ def _stash_push(
416416
def _stash_apply(self, rev: str):
417417
from pygit2 import GitError
418418

419-
from dvc.scm.git import Stash
419+
from scmrepo.git import Stash
420420

421421
def _apply(index):
422422
try:
@@ -446,7 +446,7 @@ def _apply(index):
446446
self.repo.stash_drop()
447447

448448
def _stash_drop(self, ref: str, index: int):
449-
from dvc.scm.git import Stash
449+
from scmrepo.git import Stash
450450

451451
if ref != Stash.DEFAULT_STASH:
452452
raise NotImplementedError

scmrepo/git/stash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
from typing import Optional
55

6-
from dvc.scm.exceptions import SCMError
6+
from scmrepo.exceptions import SCMError
77

88
logger = logging.getLogger(__name__)
99

0 commit comments

Comments
 (0)