Skip to content

Commit c57efe1

Browse files
add git-lfs package (#8)
1 parent f67ffb5 commit c57efe1

File tree

5 files changed

+154
-0
lines changed

5 files changed

+154
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ capnproto/capnproto/install/
1919

2020
# built ffmpeg
2121
ffmpeg/ffmpeg/install/
22+
23+
# downloaded git-lfs
24+
git-lfs/git_lfs/bin/

git-lfs/build.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
5+
cd "$DIR"
6+
7+
VERSION="3.6.1"
8+
INSTALL_DIR="$DIR/git_lfs/bin"
9+
10+
# Idempotent: skip if already present
11+
if [ -x "$INSTALL_DIR/git-lfs" ]; then
12+
echo "git-lfs already present, skipping download."
13+
exit 0
14+
fi
15+
16+
OS="$(uname -s)"
17+
ARCH="$(uname -m)"
18+
19+
case "${OS}-${ARCH}" in
20+
Linux-x86_64) PLATFORM="linux-amd64" ; EXT="tar.gz" ;;
21+
Linux-aarch64) PLATFORM="linux-arm64" ; EXT="tar.gz" ;;
22+
Darwin-arm64) PLATFORM="darwin-arm64" ; EXT="zip" ;;
23+
*)
24+
echo "Unsupported platform: ${OS}-${ARCH}" >&2
25+
exit 1
26+
;;
27+
esac
28+
29+
FILENAME="git-lfs-${PLATFORM}-v${VERSION}.${EXT}"
30+
URL="https://github.com/git-lfs/git-lfs/releases/download/v${VERSION}/${FILENAME}"
31+
32+
echo "Downloading $FILENAME ..."
33+
curl -fSL -o "$FILENAME" "$URL"
34+
35+
echo "Extracting ..."
36+
mkdir -p "$INSTALL_DIR"
37+
if [ "$EXT" = "zip" ]; then
38+
python3 -c "
39+
import zipfile, sys
40+
with zipfile.ZipFile('$FILENAME') as zf:
41+
for info in zf.infolist():
42+
if info.filename.endswith('/git-lfs'):
43+
with open('$INSTALL_DIR/git-lfs', 'wb') as f:
44+
f.write(zf.read(info))
45+
break
46+
"
47+
else
48+
tar --strip-components=1 -xzf "$FILENAME" -C "$INSTALL_DIR" --wildcards '*/git-lfs'
49+
fi
50+
51+
chmod +x "$INSTALL_DIR/git-lfs"
52+
strip "$INSTALL_DIR/git-lfs" 2>/dev/null || true
53+
54+
rm -f "$FILENAME"
55+
56+
echo "Installed git-lfs to $INSTALL_DIR"
57+
du -sh "$INSTALL_DIR"

git-lfs/git_lfs/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
import sys
3+
4+
BIN_DIR = os.path.join(os.path.dirname(__file__), "bin")
5+
6+
7+
def _run():
8+
binary = os.path.join(BIN_DIR, "git-lfs")
9+
os.execvp(binary, [binary] + sys.argv[1:])
10+
11+
12+
def smoketest():
13+
import subprocess
14+
binary = os.path.join(BIN_DIR, "git-lfs")
15+
subprocess.run([binary, "--version"], check=True)

git-lfs/pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[build-system]
2+
requires = ["setuptools>=64", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "git-lfs"
7+
version = "3.6.1"
8+
description = "Git Large File Storage extension"
9+
requires-python = ">=3.8"
10+
11+
[project.scripts]
12+
git-lfs = "git_lfs:_run"
13+
14+
[tool.setuptools.packages.find]
15+
include = ["git_lfs*"]
16+
17+
[tool.setuptools.package-data]
18+
git_lfs = ["bin/**/*"]

git-lfs/setup.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import os
2+
import platform
3+
import subprocess
4+
5+
from setuptools.command.build_py import build_py
6+
7+
try:
8+
from wheel.bdist_wheel import bdist_wheel
9+
except ImportError:
10+
bdist_wheel = None
11+
12+
13+
class BuildGitLfs(build_py):
14+
"""Run build.sh to download git-lfs before collecting package data."""
15+
16+
def run(self):
17+
pkg_dir = os.path.dirname(os.path.abspath(__file__))
18+
marker = os.path.join(pkg_dir, "git_lfs", "bin", "git-lfs")
19+
20+
if not os.path.exists(marker):
21+
build_script = os.path.join(pkg_dir, "build.sh")
22+
subprocess.check_call(["bash", build_script], cwd=pkg_dir)
23+
24+
super().run()
25+
26+
27+
cmdclass = {"build_py": BuildGitLfs}
28+
29+
if bdist_wheel is not None:
30+
31+
class PlatformWheel(bdist_wheel):
32+
"""Produce a platform-specific, Python-version-agnostic wheel."""
33+
34+
def finalize_options(self):
35+
super().finalize_options()
36+
self.root_is_pure = False
37+
38+
def get_tag(self):
39+
system = platform.system()
40+
machine = platform.machine()
41+
42+
if system == "Linux":
43+
plat = f"linux_{machine}"
44+
elif system == "Darwin":
45+
plat = "macosx_11_0_arm64"
46+
else:
47+
plat = f"{system.lower()}_{machine}"
48+
49+
return "py3", "none", plat
50+
51+
cmdclass["bdist_wheel"] = PlatformWheel
52+
53+
54+
def setup():
55+
from setuptools import setup as _setup
56+
57+
_setup(cmdclass=cmdclass)
58+
59+
60+
if __name__ == "__main__":
61+
setup()

0 commit comments

Comments
 (0)