Skip to content

Commit

Permalink
Merge pull request #4 from ssciwr/always-execute-hooks
Browse files Browse the repository at this point in the history
Ensure that hooks run even when git-lfs was present on the system
  • Loading branch information
dokempf authored Mar 16, 2022
2 parents 360c488 + 0101c07 commit 37df989
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = "Dominic Kempf"

# The full version, including alpha/beta/rc tags
release = "1.0.0"
release = "1.1.0"

# -- General configuration ---------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="sphinx_lfs_content",
version="1.0.1",
version="1.1.0",
author="Dominic Kempf",
author_email="dominic.kempf@iwr.uni-heidelberg.de",
description="Ensure existence of LFS content in your LFS builds",
Expand Down
60 changes: 29 additions & 31 deletions sphinx_lfs_content/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,34 @@


def lfs_setup(_, config):
# If we already have git-lfs, we do nothing
if shutil.which("git-lfs"):
return

# Download the latest git-lfs tarball and check its checksum
git_lfs_content = requests.get(GIT_LFS_FILE).content
checksum = hashlib.sha256(git_lfs_content).hexdigest()
if checksum != GIT_LFS_CHECKSUM:
raise ValueError("CheckSum of git-lfs tarball was incorrect!")

# Create a temporary directory to install git-lfs into
with tempfile.TemporaryDirectory() as tmp_dir:
# Write it to file (can this be short cut and merged with unpacking?)
with open(os.path.join(tmp_dir, "git-lfs.tar.gz"), "wb") as tar:
tar.write(git_lfs_content)

# Unpack the tarball
with tarfile.open(os.path.join(tmp_dir, "git-lfs.tar.gz"), "r:gz") as tar:
tar.extractall(path=tmp_dir)

# Setup a modified environment that has the temporary directory in PATH
# This works around a bug in git-lfs where git-lfs is called recursively,
# but the inner calls rely on git-lfs being in PATH.
env = os.environ
env["PATH"] = os.environ["PATH"] + os.path.pathsep + tmp_dir

# Fetch the LFS content of the repository
subprocess.check_call("git-lfs install".split(), env=env)
subprocess.check_call("git-lfs fetch".split(), env=env)
subprocess.check_call("git-lfs checkout".split(), env=env)
# If we already have git-lfs, we do not need to set it up
if shutil.which("git-lfs") is None:
# Download the latest git-lfs tarball and check its checksum
git_lfs_content = requests.get(GIT_LFS_FILE).content
checksum = hashlib.sha256(git_lfs_content).hexdigest()
if checksum != GIT_LFS_CHECKSUM:
raise ValueError("CheckSum of git-lfs tarball was incorrect!")

# Create a temporary directory to install git-lfs into
with tempfile.TemporaryDirectory() as tmp_dir:
# Write it to file (can this be short cut and merged with unpacking?)
with open(os.path.join(tmp_dir, "git-lfs.tar.gz"), "wb") as tar:
tar.write(git_lfs_content)

# Unpack the tarball
with tarfile.open(os.path.join(tmp_dir, "git-lfs.tar.gz"), "r:gz") as tar:
tar.extractall(path=tmp_dir)

# Setup a modified environment that has the temporary directory in PATH
# This works around a bug in git-lfs where git-lfs is called recursively,
# but the inner calls rely on git-lfs being in PATH.
env = os.environ
env["PATH"] = os.environ["PATH"] + os.path.pathsep + tmp_dir

# Fetch the LFS content of the repository
subprocess.check_call("git-lfs install".split(), env=env)
subprocess.check_call("git-lfs fetch".split(), env=env)
subprocess.check_call("git-lfs checkout".split(), env=env)

# Execute all of the given post commands
for cmd in config.lfs_content_post_commands:
Expand All @@ -53,4 +51,4 @@ def setup(app):
app.add_config_value("lfs_content_post_commands", [], rebuild="")
app.connect("config-inited", lfs_setup)

return {"version": "1.0.1", "parallel_read_safe": True}
return {"version": "1.1.0", "parallel_read_safe": True}

0 comments on commit 37df989

Please sign in to comment.