Skip to content

Commit

Permalink
Updated installation of Python packages
Browse files Browse the repository at this point in the history
- include utility programs like dlite-getuuid
- include storages
- include README.md and LICENSE
  • Loading branch information
jesper-friis committed Sep 3, 2024
1 parent 83d0332 commit e43afcd
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 28 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
37 changes: 29 additions & 8 deletions bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
"$<TARGET_FILE:dlite>"
${pkgdir}
Expand All @@ -199,14 +200,34 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"$<TARGET_FILE:dlite-plugins-json>"
${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
)

#
Expand Down
12 changes: 12 additions & 0 deletions cmake/CopyDirectory.cmake
Original file line number Diff line number Diff line change
@@ -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}"
)
4 changes: 3 additions & 1 deletion python/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

dist/
wheelhouse/
dlite_python.egg-info
build/
dlite_python.egg-info/
DLite_Python.egg-info/
.eggs
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions python/MANIFEST.in

This file was deleted.

44 changes: 30 additions & 14 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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"))
Expand All @@ -145,24 +148,36 @@ 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"))
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",
Expand Down Expand Up @@ -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=[
Expand All @@ -223,6 +238,7 @@ def build_extension(self, ext: CMakeExtension) -> None:
],
cmdclass={
"build_ext": CMakeBuildExt,
"install": CustomInstall,
},
zip_safe=False,
)

0 comments on commit e43afcd

Please sign in to comment.