paddlenlp

Форк
0
/
should_deploy.py 
82 строки · 2.7 Кб
1
# Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14
from __future__ import annotations
15

16
import argparse
17
import os
18
import subprocess
19
import sys
20

21
from pkg_resources import parse_version
22

23

24
def read_version_of_remote_package(name: str) -> str:
25
    """get version of remote package,
26

27
    adapted from: https://stackoverflow.com/a/58649262/6894382
28

29
    Args:
30
        name (str): the name of package
31

32
    Returns:
33
        str: the version of package
34
    """
35
    latest_version = str(
36
        subprocess.run(
37
            [sys.executable, "-m", "pip", "install", "{}==random".format(name)], capture_output=True, text=True
38
        )
39
    )
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]
43
    return latest_version
44

45

46
def read_version_of_local_package(version_file_path: str) -> str:
47
    """get version of local package
48

49
    Args:
50
        version_file_path (str): the path of `VERSION` file
51

52
    Returns:
53
        str: the version of local package
54
    """
55
    with open(version_file_path, "r", encoding="utf-8") as f:
56
        version = f.read().strip()
57
    return version
58

59

60
if __name__ == "__main__":
61
    parser = argparse.ArgumentParser()
62
    parser.add_argument("--name", required=True)
63

64
    args = parser.parse_args()
65

66
    version_file_map = {
67
        "ppdiffusers": "ppdiffusers/VERSION",
68
        "paddle-pipelines": "pipelines/VERSION",
69
    }
70
    remote_version = read_version_of_remote_package(args.name)
71

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)
78
    else:
79
        raise ValueError(f"package<{args.name}> not supported")
80

81
    should_deploy = str(parse_version(remote_version) < parse_version(local_version)).lower()
82
    print(f"should_deploy={should_deploy}")
83

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.