airflow pre_commit_update_versions 源码
airflow pre_commit_update_versions 代码
文件路径:/scripts/ci/pre_commit/pre_commit_update_versions.py
#!/usr/bin/env python
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from __future__ import annotations
import glob
import os
import re
import sys
from os.path import abspath, dirname, join
AIRFLOW_SOURCES_DIR = abspath(join(dirname(__file__), os.pardir, os.pardir, os.pardir))
sys.path.insert(0, AIRFLOW_SOURCES_DIR)
# flake8: noqa: F401
from setup import version # isort:skip
def update_version(pattern: re.Pattern, v: str, file_path: str):
print(f"Checking {pattern} in {file_path}")
with open(file_path, "r+") as f:
file_content = f.read()
if not pattern.search(file_content):
raise Exception(f"Pattern {pattern!r} doesn't found in {file_path!r} file")
new_content = pattern.sub(fr'\g<1>{v}\g<2>', file_content)
if file_content == new_content:
return
print(" Updated.")
f.seek(0)
f.truncate()
f.write(new_content)
REPLACEMENTS = {
r'^(FROM apache\/airflow:).*($)': "docs/docker-stack/docker-examples/extending/*/Dockerfile",
r'(apache\/airflow:)[^-]*(\-)': "docs/docker-stack/entrypoint.rst",
r'(`apache/airflow:(?:slim-)?)[0-9].*?((?:-pythonX.Y)?`)': "docs/docker-stack/README.md",
r'(\(Assuming Airflow version `).*(`\))': "docs/docker-stack/README.md",
}
print(f"Current version: {version}")
if __name__ == '__main__':
for regexp, p in REPLACEMENTS.items():
text_pattern = re.compile(regexp, flags=re.MULTILINE)
files = glob.glob(join(AIRFLOW_SOURCES_DIR, p), recursive=True)
if not files:
print(f"ERROR! No files matched on {p}")
for file in glob.glob(join(AIRFLOW_SOURCES_DIR, p), recursive=True):
update_version(text_pattern, version, file)
相关信息
相关文章
airflow common_precommit_utils 源码
airflow pre_commit_base_operator_partial_arguments 源码
airflow pre_commit_boring_cyborg 源码
airflow pre_commit_breeze_cmd_line 源码
airflow pre_commit_build_providers_dependencies 源码
airflow pre_commit_changelog_duplicates 源码
airflow pre_commit_chart_schema 源码
airflow pre_commit_check_2_2_compatibility 源码
0
赞
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦