streamlit

Форк
0
/
update_name.py 
68 строк · 2.3 Кб
1
#!/usr/bin/env python
2

3
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2024)
4
#
5
# Licensed under the Apache License, Version 2.0 (the "License");
6
# you may not use this file except in compliance with the License.
7
# You may obtain a copy of the License at
8
#
9
#     http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS,
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
16

17
"""Update project name across the entire repo.
18

19
The streamlit-nightly CI job uses this to set the project name to "streamlit-nightly".
20
"""
21

22
import fileinput
23
import os
24
import re
25
import sys
26
from typing import Dict
27

28
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
29

30
# A dict of [filename:regex]. For each filename, we modify all lines
31
# matched by the regex.
32
#
33
# Regexes should start with a "<pre_match>" named group and end with a
34
# "<post_match>" named group. Text between these pre- and post-match
35
# groups will be replaced with the specified project_name text.
36
FILES_AND_REGEXES = {
37
    "lib/setup.py": r"(?P<pre_match>.*name=\").*(?P<post_match>\")",
38
    "lib/streamlit/version.py": r"(?P<pre_match>.*_version\(\").*(?P<post_match>\"\)$)",
39
}
40

41

42
def update_files(project_name: str, files: Dict[str, str]) -> None:
43
    """Update files with new project name."""
44
    for filename, regex in files.items():
45
        filename = os.path.join(BASE_DIR, filename)
46
        matched = False
47
        pattern = re.compile(regex)
48
        for line in fileinput.input(filename, inplace=True):
49
            line = line.rstrip()
50
            if pattern.match(line):
51
                line = re.sub(
52
                    regex, rf"\g<pre_match>{project_name}\g<post_match>", line
53
                )
54
                matched = True
55
            print(line)
56
        if not matched:
57
            raise Exception(f'In file "{filename}", did not find regex "{regex}"')
58

59

60
def main() -> None:
61
    if len(sys.argv) != 2:
62
        raise Exception(f'Specify project name, e.g: "{sys.argv[0]} streamlit-nightly"')
63
    project_name = sys.argv[1]
64
    update_files(project_name, FILES_AND_REGEXES)
65

66

67
if __name__ == "__main__":
68
    main()
69

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

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

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

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