diff --git a/doc/contributors_guide/tips_and_tricks.md b/doc/contributors_guide/tips_and_tricks.md index bec06f1f6..2ff1daa80 100644 --- a/doc/contributors_guide/tips_and_tricks.md +++ b/doc/contributors_guide/tips_and_tricks.md @@ -17,7 +17,7 @@ This can be done as follows: python -m venv ~/.envs/testenv source ~/.envs/testenv/bin/activate pip install -U pip - pip install wheel -r requirements.txt + pip install requirements_dev.txt 2. Build the wheel diff --git a/python/setup.py b/python/setup.py index b3fe6892e..875f4ed3d 100644 --- a/python/setup.py +++ b/python/setup.py @@ -13,8 +13,6 @@ from setuptools.command.build_ext import build_ext from setuptools.command.install import install -import numpy as np - if TYPE_CHECKING: from typing import Union @@ -25,10 +23,10 @@ SETUP_DIR = Path(__file__).resolve().parent SOURCE_DIR = SETUP_DIR.parent -# Set platform-specific CMAKE_ARGS if platform.system() == "Linux": dlite_compiled_ext = "_dlite.so" dlite_compiled_dll_suffix = "*.so" + CMAKE_ARGS = [ "-DWITH_DOC=OFF", "-DWITH_HDF5=OFF", @@ -47,11 +45,12 @@ f"{site.USER_BASE if '--user' in sys.argv else sys.prefix}", ] ) + + elif platform.system() == "Windows": dlite_compiled_ext = "_dlite.pyd" dlite_compiled_dll_suffix = "*.dll" is_64bits = sys.maxsize > 2**32 - arch = 'x64' if is_64bits else 'x86' v = sys.version_info CMAKE_ARGS = [ #"-G", "Visual Studio 15 2017", @@ -60,9 +59,10 @@ "-DWITH_HDF5=OFF", f"-DPYTHON_VERSION={v.major}.{v.minor}", "-Ddlite_PYTHON_BUILD_REDISTRIBUTABLE_PACKAGE=YES", - f"-DCMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE={arch}", + f"-DCMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE={'x64' if is_64bits else 'x86'}", "-DPython3_FIND_VIRTUALENV=STANDARD", ] + else: raise NotImplementedError(f"Unsupported platform: {platform.system()}") @@ -125,50 +125,43 @@ def build_extension(self, ext: CMakeExtension) -> None: self.get_ext_fullpath(ext.name))) environment_cmake_args = os.getenv("CI_BUILD_CMAKE_ARGS", "") - environment_cmake_args = ( - environment_cmake_args.split(",") if environment_cmake_args else [] - ) - - # Remove old CMakeCache if it exists in build directory - cachefile = Path(self.build_temp) / "CMakeCache.txt" - if cachefile.exists(): - cachefile.unlink() - - # Find cmake executable (using os.path for Python 3.7 compatibility) - stem, fileext = os.path.splitext(sys.executable) - cmake_exe = os.path.join(os.path.dirname(stem), "cmake" + fileext) - if "CMAKE_EXECUTABLE" in os.environ: - cmake_exe = os.environ["CMAKE_EXECUTABLE"] - elif not os.path.exists(cmake_exe): - cmake_exe = shutil.which("cmake" + fileext) + environment_cmake_args = environment_cmake_args.split(",") if environment_cmake_args else [] build_type = "Debug" if self.debug else "Release" cmake_args = [ - cmake_exe, - str(ext.sourcedir), + "cmake", f"-DCMAKE_CONFIGURATION_TYPES:STRING={build_type}", - f"-DPython3_NumPy_INCLUDE_DIRS={np.get_include()}", + str(ext.sourcedir), ] cmake_args.extend(CMAKE_ARGS) cmake_args.extend(environment_cmake_args) env = os.environ.copy() - subprocess.run( - cmake_args, - cwd=self.build_temp, - env=env, - #capture_output=True, - check=True, - ) - - subprocess.run( - ["cmake", "--build", ".", "--config", build_type, "--verbose"], - cwd=self.build_temp, - env=env, - #capture_output=True, - check=True, - ) + try: + subprocess.run( + cmake_args, + cwd=self.build_temp, + env=env, + capture_output=True, + check=True, + ) + except subprocess.CalledProcessError as e: + print("stdout:", e.stdout.decode("utf-8"), "\n\nstderr:", + e.stderr.decode("utf-8")) + raise + try: + subprocess.run( + ["cmake", "--build", ".", "--config", build_type, "--verbose"], + cwd=self.build_temp, + env=env, + capture_output=True, + check=True, + ) + except subprocess.CalledProcessError as e: + print("stdout:", e.stdout.decode("utf-8"), "\n\nstderr:", + e.stderr.decode("utf-8")) + raise cmake_bdist_dir = Path(self.build_temp) / Path(ext.python_package_dir) shutil.copytree(