浏览代码

add options to set version on files (#2954)

* add options to set version on files

* fix precommit
/develop-newnormalization
GitHub 5 年前
当前提交
e6cace92
共有 2 个文件被更改,包括 23 次插入4 次删除
  1. 2
      .pre-commit-config.yaml
  2. 25
      utils/validate_versions.py

2
.pre-commit-config.yaml


name: validate library versions
language: script
entry: utils/validate_versions.py
files: ".*/setup.py"
files: ".*/__init__.py"

25
utils/validate_versions.py


import os
import sys
from typing import Dict
import argparse
VERSION_LINE_START = "__version__ = "

return True
def set_version(new_version: str) -> None:
new_contents = f'{VERSION_LINE_START}"{new_version}"\n'
for directory in DIRECTORIES:
path = os.path.join(directory, "__init__.py")
print(f"Setting {path} to version {new_version}")
with open(path, "w") as f:
f.write(new_contents)
ok = check_versions()
return_code = 0 if ok else 1
sys.exit(return_code)
parser = argparse.ArgumentParser()
parser.add_argument("--new-version", default=None)
# unused, but allows precommit to pass filenames
parser.add_argument("files", nargs="*")
args = parser.parse_args()
if args.new_version:
print(f"Updating to verison {args.new_version}")
set_version(args.new_version)
else:
ok = check_versions()
return_code = 0 if ok else 1
sys.exit(return_code)
正在加载...
取消
保存