def __init__(self, run=None, database: str = ".", branch: str = 'master'): """ Initialize a new context for Dolt operations with Metaflow. run: this is either - a FlowSpec when initialized with a running Flow - a Flow when looking across for data read/written across runs of a Flow - a Run when looking for data read/written by a specific run doltdb_path: this is a path to a location on the filesystem with a Dolt database """ self.run = run self.database = database self.branch = branch self.meta_database = "." self.doltdb = Dolt(self.database) try: self.meta_doltdb = Dolt(os.getcwd()) except: self.meta_doltdb = Dolt.init(os.getcwd()) current_branch, _ = self.doltdb.branch() self.entry_branch = None if current_branch.name != branch: entry_branch = current_branch.name self.doltdb.checkout(branch, checkout_branch=False) self.table_reads = [] self.table_writes = []
def initRepo(self, path: str, create: bool, url: str = None): # Prepare Repo For Data if create: repo = Dolt.init(path) repo.remote(add=True, name='origin', url=url) self.repo: Dolt = repo self.repo: Dolt = Dolt(path)
def initRepo(path: str, create: bool, url: str = None) -> Dolt: # Prepare Repo For Data if create: repo = Dolt.init(path) repo.remote(add=True, name='origin', url=url) return repo return Dolt(path)
def create_repo_if_not_exists(path: str) -> Dolt: try: return Dolt(path) except AssertionError: return Dolt.init(path)
def init_empty_test_repo() -> Dolt: temp_dir = tempfile.mkdtemp() repo_path, repo_data_dir = get_repo_path_tmp_path(temp_dir) assert not os.path.exists(repo_data_dir) return Dolt.init(repo_path)