Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer rely on distutils for CompileError #2205

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Changelog = "https://pythran.readthedocs.io/en/latest/Changelog.html"

[project.optional-dependencies]
doc = ["numpy", "nbsphinx", "scipy", "guzzle_sphinx_theme"]
test = ["ipython", "nbval", "cython", "wheel"]
test = ["ipython", "nbval", "cython", "wheel", "packaging"]

[project.scripts]
pythran = "pythran.run:run"
Expand Down
2 changes: 1 addition & 1 deletion pythran/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* compile_pythranfile: python (file) to so/cpp, returns output filename
* import_pythrancode: python (str) to module, returns loaded module
* import_pythranfile: python (file) to module, returns loaded module
* test_compile: passthrough compile test, raises CompileError Exception.
* test_compile: passthrough compile test, raises PythranCompileError Exception.

Basic scenario is to turn a Python AST into C++ code:
>>> code = "def foo(x): return x * 2"
Expand Down
5 changes: 5 additions & 0 deletions pythran/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ class PythranInternalError(Exception):
""" Exception raise on Incorrect internal behavior in Pythran. """


class PythranCompileError(Exception):

""" Exception raise on when Pythran fails the compile to binary step. """


class PythranSyntaxError(SyntaxError):
def __init__(self, msg, node=None):
SyntaxError.__init__(self, msg)
Expand Down
5 changes: 2 additions & 3 deletions pythran/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

import pythran

from pythran.errors import PythranSyntaxError, PythranTypeError
from distutils.errors import CompileError
from pythran.errors import PythranSyntaxError, PythranTypeError, PythranCompileError

logger = logging.getLogger("pythran")

Expand Down Expand Up @@ -211,7 +210,7 @@ def run():
logger.critical("I am in trouble. Your input file does not seem "
"to match Pythran's constraints...\n" + str(e))
sys.exit(1)
except CompileError as e:
except PythranCompileError as e:
logger.critical("Cover me Jack. Jack? Jaaaaack!!!!\n"
"E: " + str(e))
sys.exit(1)
Expand Down
4 changes: 2 additions & 2 deletions pythran/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def run_test_case(self, code, module_name, runas, module_dir=None, **interface):
Raises:
AssertionError by 'unittest' if return value differ.
SyntaxError if code is not python valid.
pythran.CompileError if generated code can't be compiled.
pythran.errors.PythranCompileError if generated code can't be compiled.
...possibly others...
"""
# Extract special keys from interface.
Expand Down Expand Up @@ -284,7 +284,7 @@ def run_test(self, code, *params, **interface):
Raises:
AssertionError by 'unittest' if return value differ.
SyntaxError if code is not python valid.
pythran.CompileError if generated code can't be compiled.
pythran.errors.PythranCompileError if generated code can't be compiled.
...possibly others...
"""
# Extract special keys from interface.
Expand Down
4 changes: 2 additions & 2 deletions pythran/tests/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# TODO: check http://code.google.com/p/unladen-swallow/wiki/Benchmarks
import os
from distutils.version import LooseVersion
from packaging.version import Version
import numpy
import unittest

Expand All @@ -18,7 +18,7 @@ class TestCases(TestFromDir):

TestCases.populate(TestCases)

if LooseVersion(numpy.__version__) >= '1.20':
if Version(numpy.__version__) >= Version('1.20'):
del TestCases.test_train_equalizer_norun0
del TestCases.test_train_eq_run0
del TestCases.test_train_eq_run1
Expand Down
4 changes: 2 additions & 2 deletions pythran/tests/test_openmp.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import unittest
from distutils.errors import CompileError
from pythran.tests import TestFromDir
import os
import pythran
from pythran.syntax import PythranSyntaxError
from pythran.errors import PythranCompileError
from pythran.spec import Spec

class TestOpenMP(TestFromDir):
Expand Down Expand Up @@ -48,7 +48,7 @@ def extract_runas(name, filepath):
TestOpenMPLegacy.populate(TestOpenMPLegacy)
except PythranSyntaxError:
raise
except (CompileError, ImportError):
except (PythranCompileError, ImportError):
pass


Expand Down
17 changes: 7 additions & 10 deletions pythran/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pythran.cxxgen import FunctionBody, FunctionDeclaration, Value, Block
from pythran.cxxgen import ReturnStatement
from pythran.dist import PythranExtension, PythranBuildExt
from pythran.errors import PythranCompileError
from pythran.middlend import refine, mark_unexported_functions
from pythran.passmanager import PassManager
from pythran.tables import pythran_ward
Expand All @@ -21,12 +22,8 @@
from pythran.utils import cxxid
import pythran.frontend as frontend

try:
from distutils.errors import CompileError
from distutils import sysconfig
except ImportError:
from setuptools.errors import CompileError
from setuptools._distutils import sysconfig
import sysconfig

try:
# `numpy.distutils is deprecated, may not be present, or broken
from numpy.distutils.core import setup
Expand Down Expand Up @@ -335,7 +332,7 @@ def warded(module_name, internal_name):
def compile_cxxfile(module_name, cxxfile, output_binary=None, **kwargs):
'''c++ file -> native module
Return the filename of the produced shared library
Raises CompileError on failure
Raises PythranCompileError on failure

'''

Expand All @@ -360,7 +357,7 @@ def compile_cxxfile(module_name, cxxfile, output_binary=None, **kwargs):
'--build-temp', buildtmp]
)
except SystemExit as e:
raise CompileError(str(e))
raise PythranCompileError(str(e))

def copy(src_file, dest_file):
# not using shutil.copy because it fails to copy stat across devices
Expand Down Expand Up @@ -469,7 +466,7 @@ def compile_pythrancode(module_name, pythrancode, specs=None,
str(module),
output_binary=output_file,
**kwargs)
except CompileError:
except PythranCompileError:
logger.warning("Compilation error, "
"trying hard to find its origin...")
error_checker()
Expand Down Expand Up @@ -562,7 +559,7 @@ def import_pythranfile(pythranpath, **kwargs):

def test_compile():
'''Simple passthrough compile test.
May raises CompileError Exception.
May raises PythranCompileError Exception.

'''
code = '''
Expand Down
Loading