sapling: teach gen-deps.py script to update Cargo.lock

Upstream Sapling does not maintain a Cargo.lock file, so Nixpkgs has its
own. Teach the gen-deps.py script to update Nixpkgs' Cargo.lock whenever
the Cargo.toml files change.

authored by Matthew "strager" Glazar and committed by Austin Seipp 97ebbdef ea6dad32

+34 -7
+34 -7
pkgs/applications/version-management/sapling/gen-deps.py
··· 1 #!/usr/bin/env nix-shell 2 - #!nix-shell -i python3 -p "python3.withPackages (ps: with ps; [ requests ])" 3 import json 4 import re 5 from hashlib import sha1 6 from struct import unpack 7 from subprocess import run 8 9 from requests import get 10 11 # Fetch the latest stable release metadata from GitHub 12 - latestTag = get("https://api.github.com/repos/facebook/sapling/releases/latest").json()[ 13 - "tag_name" 14 - ] 15 16 17 def nixPrefetchUrl(url): 18 return run( ··· 25 26 # Fetch the `setup.py` source and look for instances of assets being downloaded 27 # from files.pythonhosted.org. 28 - setupPy = get( 29 - f"https://github.com/facebook/sapling/raw/{latestTag}/eden/scm/setup.py" 30 - ).text 31 foundUrls = re.findall(r'(https://files\.pythonhosted\.org/packages/[^\s]+)"', setupPy) 32 33 dataDeps = {
··· 1 #!/usr/bin/env nix-shell 2 + #!nix-shell -i python3 -p cargo -p "python3.withPackages (ps: with ps; [ requests ])" 3 import json 4 + import pathlib 5 import re 6 + import tempfile 7 + import os 8 + import shutil 9 from hashlib import sha1 10 from struct import unpack 11 from subprocess import run 12 + import subprocess 13 14 from requests import get 15 16 # Fetch the latest stable release metadata from GitHub 17 + releaseMetadata = get("https://api.github.com/repos/facebook/sapling/releases/latest").json() 18 + latestTag = releaseMetadata["tag_name"] 19 + latestTarballURL = releaseMetadata["tarball_url"] 20 + 21 + [_tarballHash, sourceDirectory] = run( 22 + ["nix-prefetch-url", "--print-path", "--unpack", latestTarballURL], 23 + check=True, 24 + text=True, 25 + stdout=subprocess.PIPE, 26 + ).stdout.rstrip().splitlines() 27 + 28 + def updateCargoLock(): 29 + with tempfile.TemporaryDirectory() as tempDir: 30 + tempDir = pathlib.Path(tempDir) 31 32 + # NOTE(strager): We cannot use shutil.tree because it copies the 33 + # read-only permissions. 34 + for dirpath, dirnames, filenames in os.walk(sourceDirectory): 35 + relativeDirpath = os.path.relpath(dirpath, sourceDirectory) 36 + for filename in filenames: 37 + shutil.copy(os.path.join(dirpath, filename), tempDir / relativeDirpath / filename) 38 + for dirname in dirnames: 39 + os.mkdir(tempDir / relativeDirpath / dirname) 40 + 41 + run(["cargo", "fetch"], check=True, cwd=tempDir / "eden" / "scm") 42 + shutil.copy(tempDir / "eden" / "scm" / "Cargo.lock", "Cargo.lock") 43 + 44 + updateCargoLock() 45 46 def nixPrefetchUrl(url): 47 return run( ··· 54 55 # Fetch the `setup.py` source and look for instances of assets being downloaded 56 # from files.pythonhosted.org. 57 + setupPy = (pathlib.Path(sourceDirectory) / "eden/scm/setup.py").read_text() 58 foundUrls = re.findall(r'(https://files\.pythonhosted\.org/packages/[^\s]+)"', setupPy) 59 60 dataDeps = {