我想使用python脚本在Gitlab CI日志(log)中显示一个表.我在本地判断脚本,它会正确地显示表,但当我在gitlab CI中运行脚本时,它会中断行,尽管如果try echo 任何长行,它会正确地输出它.

在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()

簇yml文件:

include:
  - 'cluster-init_variables.yml'

cluster-init\u变量.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相关问答推荐

Matplotlib轮廓线值似乎不对劲

如何将Matplotlib的fig.add_axes本地坐标与我的坐标关联起来?

Python中的函数中是否有充分的理由接受float而不接受int?

Pystata:从Python并行运行stata实例

try 在树叶 map 上应用覆盖磁贴

使用索引列表列表对列进行切片并获取行方向的向量长度

Python—从np.array中 Select 复杂的列子集

如何让这个星型模式在Python中只使用一个for循环?

在vscode上使用Python虚拟环境时((env))

海上重叠直方图

NumPy中条件嵌套for循环的向量化

driver. find_element无法通过class_name找到元素'""

如何启动下载并在不击中磁盘的情况下呈现响应?

如何排除prefecture_related中查询集为空的实例?

pysnmp—lextudio使用next()和getCmd()生成器导致TypeError:tuple对象不是迭代器''

高效生成累积式三角矩阵

Django.core.exceptions.SynchronousOnlyOperation您不能从异步上下文中调用它-请使用线程或SYNC_TO_ASYNC

利用SCIPY沿第一轴对数组进行内插

设置索引值每隔17行左右更改的索引

正在try 让Python读取特定的CSV文件