无法看到詹金斯的Cython输出

时间:2019-04-16 12:41:57

标签: python jenkins cython

在jenkins控制台中看不到Cython输出。

我尝试使用以下方法刷新输出:

sys.stdout.flush()

我也尝试使用:

sys.stdout = sys.stderr

这是我调用Cython的代码的一部分:

# cythonize the files
setup(
    name=directory_name,
    ext_modules=cythonize(extension_list, build_dir="build",
                          compiler_directives=dict(always_allow_keywords=True, language_level=3)),
    cmdclass={'build_ext': Cython.Build.build_ext},
    packages=[directory_name])

directory_name是目标目录。

extension_list是目录中所有目标python文件的列表。

我递归地迭代我的项目目录,搜索所有要进行cythonize的python文件。

Jenkins命令:

python cython_setup.py --target_directory = "path/to/directory"

此行将显示在jenkins控制台中,但Cython输出将不会:

print('hello!') 

有人可以帮助我解决这个问题吗?

整个脚本代码:

"""
create_cython_setup.py script

This script will iterate recursively all files and folders in a target directory.
For any file with a .py extension the script will add the file to a setup.py file used for Cython.
This script will ignore __init__.py files and other files,
listed in a cython_ignore.txt file if found in the directory.

"""

from setuptools import setup
from setuptools.extension import Extension
from Cython.Build import cythonize
from Cython.Distutils import build_ext
from contextlib import redirect_stdout
import Cython
import argparse
import os, sys, io
import pathlib
import ntpath
import argparse

sys.stdout = sys.stderr
#unbuffered output from here on

def cythonize_directory(dir):
    """
    cythonize each .py file in the given target directory (ignore __init__.py)
    """

    # list all .py files in the operated directory
    py_files = list(pathlib.Path(dir).glob('*.py'))

    extension_list = list()

    for py_file in py_files:
        basename_file = ntpath.basename(py_file)
        file_name_no_extension = os.path.splitext(basename_file)[0]

        if not basename_file == "__init__.py":
            print(basename_file)
            extension_list.append(Extension(file_name_no_extension, [str(py_file)]))

    directory_name = ntpath.basename(dir)
    print('directory name = ', directory_name)

    # cythonize the files
    setup(
        name=directory_name,
        ext_modules=cythonize(extension_list, build_dir="build",
                              compiler_directives=dict(always_allow_keywords=True, language_level=3)),
        cmdclass={'build_ext': Cython.Build.build_ext},
        packages=[directory_name])



def cythonize_directory_recursive(dir):
    for root, subdirs, files in os.walk(dir):
        # cythonize all sub directories as well
        if subdirs:
            for subdir in subdirs:
                if not subdir == "build" and not subdir == "__pycache__" and not subdir == ".cache":
                    path_to_subdir = os.path.join(root, subdir)
                    print(path_to_subdir)
                    cythonize_directory(path_to_subdir)

    # cythonize the directory
    cythonize_directory(dir)


def main(args):
    dir = args.target_directory
    sys.argv = [sys.argv[0], 'build_ext']
    # dir = os.getcwd()
    cythonize_directory_recursive(dir)


if __name__ == "__main__":
    try:
        parser = argparse.ArgumentParser(description='Script Arguments')
        parser.add_argument('--target_directory', help='target directory to run the script')
        args = parser.parse_args()
        main(args)
        sys.exit(0)
    except Exception as e:
        print(e)
        sys.exit(1)
    finally:
        sys.stdout.flush()

0 个答案:

没有答案