14
from __future__ import annotations
21
from pkg_resources import parse_version
24
def read_version_of_remote_package(name: str) -> str:
25
"""get version of remote package,
27
adapted from: https://stackoverflow.com/a/58649262/6894382
30
name (str): the name of package
33
str: the version of package
37
[sys.executable, "-m", "pip", "install", "{}==random".format(name)], capture_output=True, text=True
40
latest_version = latest_version[latest_version.find("(from versions:") + 15 :]
41
latest_version = latest_version[: latest_version.find(")")]
42
latest_version = latest_version.replace(" ", "").split(",")[-1]
46
def read_version_of_local_package(version_file_path: str) -> str:
47
"""get version of local package
50
version_file_path (str): the path of `VERSION` file
53
str: the version of local package
55
with open(version_file_path, "r", encoding="utf-8") as f:
56
version = f.read().strip()
60
if __name__ == "__main__":
61
parser = argparse.ArgumentParser()
62
parser.add_argument("--name", required=True)
64
args = parser.parse_args()
67
"ppdiffusers": "ppdiffusers/VERSION",
68
"paddle-pipelines": "pipelines/VERSION",
70
remote_version = read_version_of_remote_package(args.name)
72
if args.name == "paddlenlp":
73
local_version = str(subprocess.check_output(["python", "setup.py", "--version"], text=True))
74
elif args.name in version_file_map:
75
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
76
local_version_file = os.path.join(PROJECT_ROOT, version_file_map[args.name])
77
local_version = read_version_of_local_package(local_version_file)
79
raise ValueError(f"package<{args.name}> not supported")
81
should_deploy = str(parse_version(remote_version) < parse_version(local_version)).lower()
82
print(f"should_deploy={should_deploy}")