MCPcopy
hub / github.com/treeverse/dvc / TmpDir

Class TmpDir

dvc/testing/tmp_dir.py:55–251  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53
54
55class TmpDir(pathlib.Path):
56 scheme = "local"
57
58 @property
59 def fs_path(self):
60 return os.fspath(self)
61
62 @property
63 def url(self):
64 return self.fs_path
65
66 @property
67 def config(self):
68 return {"url": self.url}
69
70 if sys.version_info < (3, 12):
71
72 def __new__(cls, *args, **kwargs):
73 if cls is TmpDir:
74 cls = WindowsTmpDir if os.name == "nt" else PosixTmpDir # noqa: PLW0642
75
76 # init parameter and `_init` method has been removed in Python 3.10.
77 kw = {"init": False} if sys.version_info < (3, 10) else {}
78 self = cls._from_parts(args, **kw) # type: ignore[attr-defined]
79 if not self._flavour.is_supported:
80 raise NotImplementedError(
81 f"cannot instantiate {cls.__name__!r} on your system"
82 )
83 if sys.version_info < (3, 10):
84 self._init()
85 return self
86
87 def init(self, *, scm=False, dvc=False, subdir=False):
88 from dvc.repo import Repo
89 from dvc.scm import Git
90
91 assert not scm or not hasattr(self, "scm")
92 assert not dvc or not hasattr(self, "dvc")
93
94 if scm:
95 Git.init(self.fs_path).close()
96 if dvc:
97 self.dvc = Repo.init(
98 self.fs_path,
99 no_scm=not scm and not hasattr(self, "scm"),
100 subdir=subdir,
101 )
102 if scm:
103 self.scm = self.dvc.scm if hasattr(self, "dvc") else Git(self.fs_path)
104 if dvc and hasattr(self, "scm"):
105 self.scm.commit("init dvc")
106
107 def close(self):
108 if hasattr(self, "scm"):
109 self.scm.close()
110 if hasattr(self, "dvc"):
111 self.dvc.close()
112

Callers 3

test_ignore_externalFunction · 0.90
makeFunction · 0.85

Calls

no outgoing calls

Tested by 2

test_ignore_externalFunction · 0.72