Skip to content

Commit

Permalink
Reverted setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jesper-friis committed Dec 15, 2024
1 parent 174e488 commit c04ceb0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 40 deletions.
2 changes: 1 addition & 1 deletion doc/contributors_guide/tips_and_tricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
71 changes: 32 additions & 39 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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()}")

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit c04ceb0

Please sign in to comment.