forked from codedownio/julia2nix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnix_util.py
30 lines (21 loc) · 869 Bytes
/
nix_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import json
import os
from pathlib import Path
import subprocess
script_dir = Path(os.path.dirname(os.path.realpath(__file__)))
nix_prefetch_git = script_dir.joinpath("templates").joinpath("fetchgit").joinpath("nix-prefetch-git")
def fetch_sha256(url, rev="HEAD", deepClone=False, leaveDotGit=False, fetchSubmodules=False):
extra_args = [] \
+ (["--deepClone"] if deepClone else []) \
+ (["--leave-dotGit"] if leaveDotGit else []) \
+ (["--fetch-submodules"] if fetchSubmodules else [])
p = subprocess.run([
str(nix_prefetch_git),
"--url", url,
"--rev", rev,
"--quiet"
] + extra_args, check=True, stdout=subprocess.PIPE)
stdout = p.stdout.decode()
if stdout.startswith("Nothing new to pack."):
stdout = stdout[(len("Nothing new to pack.")):]
return json.loads(stdout)["sha256"]