From 4a6f727ad6bdfbd537fa6fd93112cf01328f8492 Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Tue, 20 Aug 2024 21:36:36 +0200 Subject: [PATCH] Remove dependency on setuptools for `pythran -E` This should simplify the life of scipy maintainers, see #2228. --- .github/workflows/no-setuptools.yml | 32 +++++++++++++++++++++++++++++ pythran/toolchain.py | 15 +++++++------- 2 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/no-setuptools.yml diff --git a/.github/workflows/no-setuptools.yml b/.github/workflows/no-setuptools.yml new file mode 100644 index 000000000..c2406a411 --- /dev/null +++ b/.github/workflows/no-setuptools.yml @@ -0,0 +1,32 @@ +name: no-setuptools + +on: + push: + branches: + - master + pull_request: + branches: + - master +jobs: + build: + runs-on: ubuntu-20.04 + strategy: + matrix: + python-version: [3.12] + steps: + - uses: actions/checkout@v2 + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install scipy-openblas64 + - name: Setup + run: | + python -m pip install . + python -m pip uninstall -y setuptools # the goal of that check is to test codegen without setuptools + - name: Testing scipy + run: | + find pythran/tests/scipy/ -name '*.py' -exec pythran -E {} \; diff --git a/pythran/toolchain.py b/pythran/toolchain.py index fde290260..ba6a9aafe 100644 --- a/pythran/toolchain.py +++ b/pythran/toolchain.py @@ -8,7 +8,6 @@ from pythran.cxxgen import PythonModule, Include, Line, Statement 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 @@ -24,12 +23,6 @@ import sysconfig -try: - # `numpy.distutils is deprecated, may not be present, or broken - from numpy.distutils.core import setup -except Exception: - from setuptools import setup - from tempfile import mkdtemp, NamedTemporaryFile import gast as ast import importlib @@ -335,6 +328,14 @@ def compile_cxxfile(module_name, cxxfile, output_binary=None, **kwargs): Raises PythranCompileError on failure ''' + # local import so that we don't depend on setuptools for the code generation + # part + from pythran.dist import PythranExtension, PythranBuildExt + try: + # `numpy.distutils is deprecated, may not be present, or broken + from numpy.distutils.core import setup + except Exception: + from setuptools import setup builddir = mkdtemp() buildtmp = mkdtemp()