Skip to content

Commit

Permalink
use lock file
Browse files Browse the repository at this point in the history
  • Loading branch information
nui committed May 6, 2024
1 parent 5b16c5f commit 28d8f2a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
13 changes: 12 additions & 1 deletion etc/build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
import argparse
import hashlib
import json
import os
import re
import shutil
Expand Down Expand Up @@ -52,11 +53,21 @@ def read_plugin_tuple(repo):
yield m.groups()


def read_plugin_lock_db(repo):
lock_file = repo.joinpath('vim', 'plugins.lock.json')
return json.loads(open(lock_file, "rt").read())


def clone_vim_plugins(repo):
bundle_dir = repo.joinpath('vim', 'bundle')
db = read_plugin_lock_db(repo)
for (name, url) in read_plugin_tuple(repo):
print(f'Cloning {name}')
subprocess.run(['git', 'clone', '--quiet', url, name], cwd=bundle_dir)
subprocess.run(['git', 'clone', '--quiet', url, name], check=True, cwd=bundle_dir)
commit_id = db[name]
print(f'Resetting {name} to locked commit {commit_id}')
plugin_dir = bundle_dir.joinpath(name)
subprocess.run(['git', 'reset', '--hard', commit_id], check=True, cwd=plugin_dir)


# Generate files that need information from git
Expand Down
31 changes: 31 additions & 0 deletions vim/generate-plugin-lock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python3

import re
import subprocess
import json
from pathlib import PurePath

def read_plugin_tuple():
pattern = re.compile(r'^(\w\S+)\s+(\S+)')
plugin_file = open('plugins', 'rt')
for line in plugin_file.readlines():
m = pattern.match(line)
if m:
yield m.groups()

def main():
lock_db = {}
for name, url in read_plugin_tuple():
cwd=PurePath("bundle").joinpath(name)
process = subprocess.run(['git', 'rev-parse', 'HEAD'], check=True, cwd=cwd, capture_output=True)
output = process.stdout.decode().strip()
lock_db[name] = output
db=json.dumps(lock_db, sort_keys=True, indent=4)
with open('plugins.lock.json', 'wt') as f:
f.write(db)
print(db)


if __name__ == '__main__':
main()

0 comments on commit 28d8f2a

Please sign in to comment.