Skip to content

Commit

Permalink
♻️ Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
falexwolf committed Mar 12, 2024
1 parent 524695f commit 6881fcd
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions lamindb/core/_run_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,26 @@ def get_filepath_within_git_repo(
return filepath


def get_transform_reference_from_git_repo(path: Path):
blob_hash = hash_code(path).hexdigest()
cd_repo = None
result = get_git_commit_hash(blob_hash, cd_repo=None)
commit_hash = result.stdout.decode()
if commit_hash == "" or result.returncode == 1:
cd_repo = dir_from_repo_url(settings.sync_git_repo)
clone_git_repo(settings.sync_git_repo)
result = get_git_commit_hash(blob_hash, cd_repo=cd_repo)
commit_hash = result.stdout.decode()
if commit_hash == "" or result.returncode == 1:
raise RuntimeError(
f"Did not find file in git repo\n{result.stderr.decode()}"
)
gitpath = get_filepath_within_git_repo(commit_hash, blob_hash, cd_repo)
reference = f"{settings.sync_git_repo}/blob/{commit_hash}/{gitpath}"
reference_type = "url"
return reference, reference_type


class run_context:
"""Global run context."""

Expand Down Expand Up @@ -421,22 +441,7 @@ def _track_script(
reference = None
reference_type = None
if settings.sync_git_repo is not None:
blob_hash = hash_code(path).hexdigest()
cd_repo = None
result = get_git_commit_hash(blob_hash, cd_repo=None)
commit_hash = result.stdout.decode()
if commit_hash == "" or result.returncode == 1:
cd_repo = dir_from_repo_url(settings.sync_git_repo)
clone_git_repo(settings.sync_git_repo)
result = get_git_commit_hash(blob_hash, cd_repo=cd_repo)
commit_hash = result.stdout.decode()
if commit_hash == "" or result.returncode == 1:
raise RuntimeError(
f"Did not find file in git repo\n{result.stderr.decode()}"
)
gitpath = get_filepath_within_git_repo(commit_hash, blob_hash, cd_repo)
reference = f"{settings.sync_git_repo}/blob/{commit_hash}/{gitpath}"
reference_type = "url"
reference, reference_type = get_transform_reference_from_git_repo(path)
return name, short_name, reference, reference_type

@classmethod
Expand Down

0 comments on commit 6881fcd

Please sign in to comment.