vimPlugins: automatically commit redirect updates
- When redirections are detected, rather than printing instructions, update.py now creates two commits -- one with the plugin updates and another with redirected plugin names updated to their new repos. - Added a --allow-dirty flag so that one can run ./update.py --commit with a dirty nixpkgs repository, which is necessary for development. I wouldn't mind removing this before merging if it's not in our flag budget but it's necessary scaffolding for now.
This commit is contained in:
parent
df0db17740
commit
042c3dc356
|
@ -416,12 +416,7 @@ in lib.fix' (lib.extends overrides packages)
|
||||||
print(f"updated {outfile}")
|
print(f"updated {outfile}")
|
||||||
|
|
||||||
|
|
||||||
def commit_changes(repo: git.Repo, *files: Path):
|
def rewrite_input(input_file: Path, redirects: dict):
|
||||||
repo.index.add([str(f.resolve()) for f in files])
|
|
||||||
repo.index.commit("vimPlugins: Update")
|
|
||||||
|
|
||||||
|
|
||||||
def rewrite_input(input_file: Path, output_file: Path, redirects: dict):
|
|
||||||
with open(input_file, "r") as f:
|
with open(input_file, "r") as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
|
|
||||||
|
@ -442,19 +437,6 @@ def rewrite_input(input_file: Path, output_file: Path, redirects: dict):
|
||||||
with open(DEPRECATED, "w") as f:
|
with open(DEPRECATED, "w") as f:
|
||||||
json.dump(deprecations, f, indent=4, sort_keys=True)
|
json.dump(deprecations, f, indent=4, sort_keys=True)
|
||||||
|
|
||||||
print(
|
|
||||||
f"""\
|
|
||||||
Redirects have been detected and {input_file} has been updated. Please take the
|
|
||||||
following steps:
|
|
||||||
1. Run this script again so these changes will be reflected in the
|
|
||||||
generated expressions:
|
|
||||||
./update.py
|
|
||||||
2. Commit {input_file} along with deprecations and generated expressions:
|
|
||||||
git add {output_file} {input_file} {DEPRECATED}
|
|
||||||
git commit -m "vimPlugins: Update redirects"
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
lines = sorted(lines, key=str.casefold)
|
lines = sorted(lines, key=str.casefold)
|
||||||
|
|
||||||
with open(input_file, "w") as f:
|
with open(input_file, "w") as f:
|
||||||
|
@ -496,25 +478,49 @@ def parse_args():
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Automatically commit updates",
|
help="Automatically commit updates",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--allow-dirty",
|
||||||
|
dest="allow_dirty",
|
||||||
|
action="store_true",
|
||||||
|
help=(
|
||||||
|
"Allow commit to continue even if state is unexpectedly dirty. "
|
||||||
|
"This is only helpful when developing vimPlugins infrastructure."
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def get_nixpkgs_repo() -> git.Repo:
|
class NixpkgsRepo:
|
||||||
repo = git.Repo(NIXPKGS_PATH)
|
def __init__(self, allow_dirty: bool):
|
||||||
if repo.is_dirty():
|
self.allow_dirty: bool = allow_dirty
|
||||||
raise Exception("Please stash your changes before updating.")
|
self.repo: git.Repo = git.Repo(NIXPKGS_PATH)
|
||||||
return repo
|
|
||||||
|
if self.is_unexpectedly_dirty():
|
||||||
|
raise Exception("Please stash changes before updating.")
|
||||||
|
|
||||||
|
def commit(self, message: str, files: List[Path]) -> None:
|
||||||
|
file_paths = [str(f.resolve()) for f in files]
|
||||||
|
files_changed = False
|
||||||
|
for f in self.repo.index.diff(None):
|
||||||
|
if str(f) in file_paths:
|
||||||
|
files_changed = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if files_changed:
|
||||||
|
print(f'committing to nixpkgs "vimPlugins: {message}"')
|
||||||
|
self.repo.index.add(file_paths)
|
||||||
|
self.repo.index.commit(f"vimPlugins: {message}")
|
||||||
|
assert self.is_unexpectedly_dirty() is False
|
||||||
|
else:
|
||||||
|
print("no changes in working tree to commit")
|
||||||
|
|
||||||
|
def is_unexpectedly_dirty(self) -> bool:
|
||||||
|
return self.repo.is_dirty() and not self.allow_dirty
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def update_plugins(input_file: str, outfile: str, cache: Cache) -> Dict:
|
||||||
args = parse_args()
|
plugin_names = load_plugin_spec(input_file)
|
||||||
if args.commit:
|
|
||||||
nixpkgs_repo = get_nixpkgs_repo()
|
|
||||||
plugin_names = load_plugin_spec(args.input_file)
|
|
||||||
current_plugins = get_current_plugins()
|
|
||||||
cache = Cache(current_plugins)
|
|
||||||
|
|
||||||
prefetch_with_cache = functools.partial(prefetch, cache=cache)
|
prefetch_with_cache = functools.partial(prefetch, cache=cache)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -525,12 +531,30 @@ def main() -> None:
|
||||||
|
|
||||||
plugins, redirects = check_results(results)
|
plugins, redirects = check_results(results)
|
||||||
|
|
||||||
generate_nix(plugins, args.outfile)
|
generate_nix(plugins, outfile)
|
||||||
|
|
||||||
rewrite_input(args.input_file, args.outfile, redirects)
|
return redirects
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
args = parse_args()
|
||||||
|
if args.commit:
|
||||||
|
nixpkgs_repo = NixpkgsRepo(args.allow_dirty)
|
||||||
|
current_plugins = get_current_plugins()
|
||||||
|
cache = Cache(current_plugins)
|
||||||
|
redirects = {}
|
||||||
|
|
||||||
|
redirects = update_plugins(args.input_file, args.outfile, cache)
|
||||||
|
|
||||||
|
rewrite_input(args.input_file, redirects)
|
||||||
|
|
||||||
if args.commit:
|
if args.commit:
|
||||||
commit_changes(nixpkgs_repo, args.outfile)
|
nixpkgs_repo.commit("Update", [args.outfile])
|
||||||
|
if redirects:
|
||||||
|
update_plugins(args.input_file, args.outfile, cache)
|
||||||
|
nixpkgs_repo.commit(
|
||||||
|
"Update redirects", [args.outfile, args.input_file, DEPRECATED]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue