Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
feihoo87 committed Jan 8, 2024
1 parent 7a63555 commit dde3f6d
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions waveforms/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,35 @@ def find_spec(self, fullname, path=None, target=None):


class GitModuleLoader(importlib.abc.FileLoader, importlib.abc.SourceLoader):
def __init__(self, repo_path, name, fullname):
def __init__(self, repo_path, revision, fullname):
self.repo_path = repo_path
self.hexsha = git.Repo(self.repo_path).commit(name).hexsha
self.hexsha = git.Repo(self.repo_path).commit(revision).hexsha

self.blob, self.filepath, self._is_package = self._find_blob(
repo_path, name, '/'.join(fullname.split('.')))
repo_path, revision, '/'.join(fullname.split('.')))

def get_blob(self, revision, filepath):
try:
# find a module
blob = git.Repo(self.repo_path).commit(revision).tree[filepath + '.py']
return blob, filepath + '.py'
except KeyError:
try:
blob = git.Repo(self.repo_path).commit(revision).tree[filepath + '.pyc']
return blob, filepath + '.pyc'
except KeyError:
return None, None

def _find_blob(self, repo_path, name, filepath):
def _find_blob(self, repo_path, revision, filepath):
try:
# find a module
blob = git.Repo(repo_path).commit(name).tree[filepath + '.py']
blob = git.Repo(repo_path).commit(revision).tree[filepath + '.py']
return blob, filepath + '.py', False
except KeyError:
pass
try:
# find a package
blob = git.Repo(repo_path).commit(name).tree[filepath +
blob = git.Repo(repo_path).commit(revision).tree[filepath +
'/__init__.py']
return blob, filepath + '/__init__.py', True
except KeyError:
Expand Down

0 comments on commit dde3f6d

Please sign in to comment.