diff --git a/CMakeLists.txt b/CMakeLists.txt index e25972506..26a2a83c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -770,6 +770,9 @@ add_custom_target(show ${cmd}) # Subdirectories add_subdirectory(src) +# Tools - may depend on storage plugins +add_subdirectory(tools) + # Storage plugins add_subdirectory(storages/json) if(WITH_HDF5) @@ -783,9 +786,6 @@ if(WITH_PYTHON) add_subdirectory(storages/python) endif() -# Tools - may depend on storage plugins -add_subdirectory(tools) - # Fortran - depends on tools if(WITH_FORTRAN) add_subdirectory(bindings/fortran) diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index 8a5f81312..e12a0c60e 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -15,8 +15,8 @@ set(py_sources # Python sub-packages set(py_packages - triplestore - ) + #triplestore +) configure_file(paths.py.in paths.py) if(dlite_PYTHON_BUILD_REDISTRIBUTABLE_PACKAGE) @@ -187,6 +187,7 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E make_directory ${pkgdir}/share/dlite/python-storage-plugins COMMAND ${CMAKE_COMMAND} -E make_directory ${pkgdir}/share/dlite/python-mapping-plugins COMMAND ${CMAKE_COMMAND} -E make_directory ${pkgdir}/share/dlite/storages + COMMAND ${CMAKE_COMMAND} -E make_directory ${pkgdir}/share/dlite/bin COMMAND ${CMAKE_COMMAND} -E copy_if_different "$" ${pkgdir} @@ -199,14 +200,34 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E copy_if_different "$" ${pkgdir}/share/dlite/storage-plugins - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${dlite_SOURCE_DIR}/storages/python/python-storage-plugins - ${pkgdir}/share/dlite/python-storage-plugins - COMMAND ${CMAKE_COMMAND} -E copy_directory - ${dlite_SOURCE_DIR}/bindings/python/python-mapping-plugins - ${pkgdir}/share/dlite/python-mapping-plugins + COMMAND ${CMAKE_COMMAND} + -DSOURCE_DIR=${dlite_SOURCE_DIR}/storages/python/python-storage-plugins + -DDEST_DIR=${pkgdir}/share/dlite/python-storage-plugins + -DPATTERN="*.py" + -P ${dlite_SOURCE_DIR}/cmake/CopyDirectory.cmake + COMMAND ${CMAKE_COMMAND} + -DSOURCE_DIR=${dlite_SOURCE_DIR}/bindings/python/python-mapping-plugins + -DDEST_DIR=${pkgdir}/share/dlite/python-mapping-plugins + -DPATTERN="*.py" + -P ${dlite_SOURCE_DIR}/cmake/CopyDirectory.cmake + COMMAND ${CMAKE_COMMAND} + -DSOURCE_DIR=${dlite_SOURCE_DIR}/storages/python/python-storage-plugins + -DDEST_DIR=${pkgdir}/share/dlite/storages + -DPATTERN="*.json" + -P ${dlite_SOURCE_DIR}/cmake/CopyDirectory.cmake + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${dlite_SOURCE_DIR}/README.md ${dlite_SOURCE_DIR}/LICENSE + ${pkgdir}/share/dlite + COMMAND ${CMAKE_COMMAND} -E copy_if_different + ${CMAKE_BINARY_DIR}/tools/dlite-codegen${EXEEXT} + ${CMAKE_BINARY_DIR}/tools/dlite-env${EXEEXT} + ${CMAKE_BINARY_DIR}/tools/dlite-getuuid${EXEEXT} + ${pkgdir}/share/dlite/bin DEPENDS python_package + dlite-codegen + dlite-env + dlite-getuuid ) # diff --git a/cmake/CopyDirectory.cmake b/cmake/CopyDirectory.cmake new file mode 100644 index 000000000..a1d72df52 --- /dev/null +++ b/cmake/CopyDirectory.cmake @@ -0,0 +1,12 @@ +# Copy directory +# +# Parameters (passed with -D) +# - SOURCE_DIR: directory to copy +# - DEST_DIR: new destination directory +# - PATTERN: pattern matching files to include +# +file( + COPY "${SOURCE_DIR}/" + DESTINATION "${DEST_DIR}" + FILES_MATCHING PATTERN "${PATTERN}" +) diff --git a/python/.gitignore b/python/.gitignore index 0b5510797..993ad7cc1 100644 --- a/python/.gitignore +++ b/python/.gitignore @@ -2,5 +2,7 @@ dist/ wheelhouse/ -dlite_python.egg-info +build/ +dlite_python.egg-info/ +DLite_Python.egg-info/ .eggs diff --git a/python/dlite/.gitignore b/python/DLite-Python/.gitignore similarity index 100% rename from python/dlite/.gitignore rename to python/DLite-Python/.gitignore diff --git a/python/dlite/__init__.py b/python/DLite-Python/__init__.py similarity index 100% rename from python/dlite/__init__.py rename to python/DLite-Python/__init__.py diff --git a/python/MANIFEST.in b/python/MANIFEST.in deleted file mode 100644 index 154c1eed7..000000000 --- a/python/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -include ../LICENSE ../README.md ../CMakeLists.txt pyproject.toml -recursive-include ../. **/* diff --git a/python/setup.py b/python/setup.py index d3090719b..aa1402af0 100644 --- a/python/setup.py +++ b/python/setup.py @@ -2,14 +2,16 @@ import sys import platform import re +import shutil import site import subprocess -from shutil import copytree +from glob import glob from typing import TYPE_CHECKING from pathlib import Path from setuptools import Extension, setup from setuptools.command.build_ext import build_ext +from setuptools.command.install import install if TYPE_CHECKING: from typing import Union @@ -120,8 +122,8 @@ def build_extension(self, ext: CMakeExtension) -> None: build_type = "Debug" if self.debug else "Release" cmake_args = [ "cmake", - str(ext.sourcedir), f"-DCMAKE_CONFIGURATION_TYPES:STRING={build_type}", + str(ext.sourcedir), ] cmake_args.extend(CMAKE_ARGS) cmake_args.extend(environment_cmake_args) @@ -134,7 +136,8 @@ def build_extension(self, ext: CMakeExtension) -> None: cwd=self.build_temp, env=env, capture_output=True, - check=True) + check=True, + ) except subprocess.CalledProcessError as e: print("stdout:", e.stdout.decode("utf-8"), "\n\nstderr:", e.stderr.decode("utf-8")) @@ -145,7 +148,7 @@ def build_extension(self, ext: CMakeExtension) -> None: cwd=self.build_temp, env=env, capture_output=True, - check=True + check=True, ) except subprocess.CalledProcessError as e: print("stdout:", e.stdout.decode("utf-8"), "\n\nstderr:", @@ -153,16 +156,28 @@ def build_extension(self, ext: CMakeExtension) -> None: raise cmake_bdist_dir = Path(self.build_temp) / Path(ext.python_package_dir) - copytree( + shutil.copytree( str(cmake_bdist_dir / ext.name), str(Path(output_dir) / ext.name), dirs_exist_ok=True, ) + +class CustomInstall(install): + """Custom handler for the 'install' command.""" + def run(self): + super().run() + bindir = Path(self.build_lib) / "dlite" / "share" / "dlite" / "bin" + # Possible to make a symlink instead of copy to save space + for prog in glob(str(bindir / "*")): + shutil.copy(prog, self.install_scripts) + + version = re.search( r"project\([^)]*VERSION\s+([0-9.]+)", (SOURCE_DIR / "CMakeLists.txt").read_text(), ).groups()[0] +share = Path(".") / "share" / "dlite" setup( name="DLite-Python", @@ -198,20 +213,20 @@ def build_extension(self, ext: CMakeExtension) -> None: install_requires="numpy>=1.14.5,<1.27.0", #install_requires=requirements, #extras_require=extra_requirements, - packages=["dlite"], + packages=["DLite-Python"], scripts=[ str(SOURCE_DIR / "bindings" / "python" / "scripts" / "dlite-validate"), + str(SOURCE_DIR / "cmake" / "patch-activate.sh"), ], package_data={ "dlite": [ - dlite_compiled_ext, - dlite_compiled_dll_suffix, - str(Path(".") / "share" / "dlite" / "storage-plugins" / - dlite_compiled_dll_suffix), - str(Path(".") / "bin" / "dlite-getuuid"), - str(Path(".") / "bin" / "dlite-codegen"), - str(Path(".") / "bin" / "dlite-env"), - str(Path(".") / "bin" / "patch-activate.sh"), + str(share / "README.md"), + str(share / "LICENSE"), + str(share / "storage-plugins" / dlite_compiled_dll_suffix), + str(share / "mapping-plugins" / dlite_compiled_dll_suffix), + str(share / "python-storage-plugins" / "*.py"), + str(share / "python-mapping-plugins" / "*.py"), + str(share / "storages" / "*.json"), ] }, ext_modules=[ @@ -223,6 +238,7 @@ def build_extension(self, ext: CMakeExtension) -> None: ], cmdclass={ "build_ext": CMakeBuildExt, + "install": CustomInstall, }, zip_safe=False, )