gpt4 book ai didi

python - Gitlab CI 在 Python 脚本输出中换行

转载 作者:行者123 更新时间:2023-12-05 04:29:00 26 4
gpt4 key购买 nike

我想使用 python 脚本在 Gitlab CI 日志中显示一个表。我在本地检查脚本并正确显示表格,但是当我在 gitlab CI 中运行脚本时,它会中断该行,尽管如果您尝试回显任何长行,它会正确输出。

在gitlab ci中需要做些什么才能不破坏python脚本输出表的行?

如果重要的话,我会使用制表库制作表格。

enter image description here

Python 脚本:

#!/usr/bin/env python3

import ruamel.yaml
from tabulate import tabulate
from rich.console import Console

def main():
with open('cluster.yml', 'r') as cluster_yml:
cluster_yml_data = yaml.load(cluster_yml)
path_to_env_file = cluster_yml_data['include'][0]
with open(path_to_env_file, 'r') as env_yaml:
env_yaml_data = yaml.load(env_yaml)
for var, value in env_yaml_data['variables'].items():
env_yaml_data['variables'][var] = str(env_yaml_data['variables'][var]).replace(' ', '\n')
console.print(tabulate(env_yaml_data['variables'].items(), tablefmt='fancy_grid', headers=['Variable', 'Value']))

if __name__ == '__main__':
yaml = ruamel.yaml.YAML()
yaml.indent(mapping=2, sequence=4, offset=2)
yaml.preserve_quotes = True
console = Console(force_terminal=True)
main()

cluster.yml 文件:

include:
- 'cluster-init_variables.yml'

cluster-init_variables.yml 文件:

variables:
FOLDER_PREFIX: "bcs"
FOLDER_NAME: "sandbox"
FOLDER: "$FOLDER_PREFIX-$FOLDER_NAME"
INFRA_REPO: "git@github.com:aaaaaaa/bbbb-bbbbbbb/cccccc/dddddd/$FOLDER-repo.git"
SUBNET_ZONE_A: "1.1.1.1/24"
SUBNET_ZONE_B: "2.2.2.2/24"
SUBNET_ZONE_C: "3.3.3.3/24"
GROUP_ID: "12"
CLUSTER_NAME: "cluster"
NG_WORKER_MEMORY: 24
NG_WORKER_CORES: 8
NG_SCALE_MIN: 1
NG_SCALE_MAX: 3
NG_SCALE_INITIAL: 1
NG_WORKER_DISK_SIZE: 64

最佳答案

您可以将 width 参数传递给控制台调用并明确设置宽度。

width (int, optional) – The width of the terminal. Leave as default to auto-detect width.

关于python - Gitlab CI 在 Python 脚本输出中换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72451350/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com