提交 6700dcdf authored 作者: Brandon T. Willard's avatar Brandon T. Willard 提交者: Brandon T. Willard

Create custom CompileError that prints compilation output correctly

上级 1ee6f62c
...@@ -28,7 +28,7 @@ import aesara ...@@ -28,7 +28,7 @@ import aesara
# we will abuse the lockfile mechanism when reading and writing the registry # we will abuse the lockfile mechanism when reading and writing the registry
from aesara.compile.compilelock import lock_ctx from aesara.compile.compilelock import lock_ctx
from aesara.configdefaults import config, gcc_version_str from aesara.configdefaults import config, gcc_version_str
from aesara.link.c.exceptions import MissingGXX from aesara.link.c.exceptions import CompileError, MissingGXX
from aesara.utils import ( from aesara.utils import (
LOCAL_BITWIDTH, LOCAL_BITWIDTH,
flatten, flatten,
...@@ -2543,9 +2543,9 @@ class GCC_compiler(Compiler): ...@@ -2543,9 +2543,9 @@ class GCC_compiler(Compiler):
# We replace '\n' by '. ' in the error message because when Python # We replace '\n' by '. ' in the error message because when Python
# prints the exception, having '\n' in the text makes it more # prints the exception, having '\n' in the text makes it more
# difficult to read. # difficult to read.
compile_stderr = compile_stderr.replace("\n", ". ") # compile_stderr = compile_stderr.replace("\n", ". ")
raise Exception( raise CompileError(
f"Compilation failed (return status={status}): {compile_stderr}" f"Compilation failed (return status={status}):\n{' '.join(cmd)}\n{compile_stderr}"
) )
elif config.cmodule__compilation_warning and compile_stderr: elif config.cmodule__compilation_warning and compile_stderr:
# Print errors just below the command line. # Print errors just below the command line.
......
from distutils.errors import CompileError as BaseCompileError
class MissingGXX(Exception): class MissingGXX(Exception):
""" """
This error is raised when we try to generate c code, This error is raised when we try to generate c code,
but g++ is not available. but g++ is not available.
""" """
class CompileError(BaseCompileError):
"""This custom `Exception` prints compilation errors with their original
formatting.
"""
def __str__(self):
return self.args[0]
...@@ -4,18 +4,21 @@ We don't have real tests for the cache, but it would be great to make them! ...@@ -4,18 +4,21 @@ We don't have real tests for the cache, but it would be great to make them!
But this one tests a current behavior that isn't good: the c_code isn't But this one tests a current behavior that isn't good: the c_code isn't
deterministic based on the input type and the op. deterministic based on the input type and the op.
""" """
import logging import logging
import tempfile
from unittest.mock import patch from unittest.mock import patch
import numpy as np import numpy as np
import pytest
import aesara import aesara
from aesara.compile.ops import DeepCopyOp
from aesara.link.c.cmodule import GCC_compiler, default_blas_ldflags from aesara.link.c.cmodule import GCC_compiler, default_blas_ldflags
from aesara.link.c.exceptions import CompileError
from aesara.tensor.type import dvectors from aesara.tensor.type import dvectors
class MyOp(aesara.compile.ops.DeepCopyOp): class MyOp(DeepCopyOp):
nb_called = 0 nb_called = 0
def c_code_cache_version(self): def c_code_cache_version(self):
...@@ -37,6 +40,11 @@ class MyOp(aesara.compile.ops.DeepCopyOp): ...@@ -37,6 +40,11 @@ class MyOp(aesara.compile.ops.DeepCopyOp):
) )
def test_compiler_error():
with pytest.raises(CompileError), tempfile.TemporaryDirectory() as dir_name:
GCC_compiler.compile_str("module_name", "blah", location=dir_name)
def test_inter_process_cache(): def test_inter_process_cache():
# When an op with c_code, but no version. If we have 2 apply node # When an op with c_code, but no version. If we have 2 apply node
# in the graph with different inputs variable(so they don't get # in the graph with different inputs variable(so they don't get
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论