science/py-spglib: Build using PEP517 tools instead of cmake

This commit is contained in:
Yuri Victorovich 2024-02-12 00:08:37 -08:00
parent 9e7ebc197d
commit 8aafb5f26d
5 changed files with 6 additions and 125 deletions

View file

@ -1,6 +1,7 @@
PORTNAME= spglib
DISTVERSIONPREFIX= v
DISTVERSION= 2.3.1
PORTREVISION= 1
CATEGORIES= science python
PKGNAMEPREFIX= ${PYTHON_PKGNAMEPREFIX}
@ -12,18 +13,17 @@ LICENSE= BSD3CLAUSE
BUILD_DEPENDS= ${PYTHON_PKGNAMEPREFIX}setuptools_scm>0:devel/py-setuptools_scm@${PY_FLAVOR} \
${PYTHON_PKGNAMEPREFIX}scikit-build-core>0:devel/py-scikit-build-core@${PY_FLAVOR} \
${PYTHON_PKGNAMEPREFIX}pyproject-metadata>0:devel/py-pyproject-metadata@${PY_FLAVOR} \
cmake:devel/cmake-core \
${PYNUMPY}
LIB_DEPENDS= libsymspg.so:science/spglib
RUN_DEPENDS= ${PYNUMPY}
USES= cmake python
USE_PYTHON= flavors pytest # tests fail to run, see https://github.com/spglib/spglib/issues/192
USES= python
USE_PYTHON= pep517 autoplist pytest # tests fail to run, see https://github.com/spglib/spglib/issues/192
USE_GITHUB= yes
CMAKE_ARGS= -DPython3_EXECUTABLE=${PYTHON_CMD}
WRKSRC_SUBDIR= python
MAKE_ENV= SETUPTOOLS_SCM_PRETEND_VERSION=${DISTVERSION}
TEST_WRKSRC= ${WRKSRC}
@ -33,10 +33,6 @@ post-patch:
##@cd ${WRKSRC} && ${RLN} ../test .
#@cd ${WRKSRC} && ${CP} -r ../test .
# workaround for https://github.com/spglib/spglib/issues/429
@${REINPLACE_CMD} -i '' -e 's|^from ._version import|#&|' ${WRKSRC}/spglib/__init__.py
# patch in the correct symspg lib
@${REINPLACE_CMD} -i '' \
-e 's|, bundled_lib)|, "${LOCALBASE}/lib/libsymspg.so")|' \
${WRKSRC}/spglib/spglib.py
@${REINPLACE_CMD} -i '' -e 's|^from ._version import|#&|' ${WRKSRC}/python/spglib/__init__.py
.include <bsd.port.mk>

View file

@ -1,42 +0,0 @@
--- CMakeLists.txt.orig 2024-02-11 01:27:19 UTC
+++ CMakeLists.txt
@@ -1,8 +1,13 @@
+cmake_minimum_required(VERSION 3.15)
+
+find_package(Spglib REQUIRED)
+find_package(Python3 COMPONENTS REQUIRED Interpreter Development.Module NumPy)
+
Python3_add_library(Spglib_python MODULE WITH_SOABI _spglib.c)
set_target_properties(Spglib_python PROPERTIES
OUTPUT_NAME _spglib)
target_link_libraries(Spglib_python PRIVATE
- Spglib_symspg Python3::NumPy)
+ Spglib::symspg Python3::NumPy)
if (NOT Python_INSTALL_DIR)
if (SKBUILD)
# If built with scikit-build-core, let it handle the installation
@@ -12,16 +17,16 @@ endif ()
set(Python_INSTALL_DIR ${Python3_SITEARCH}/spglib)
endif ()
endif ()
-if (SPGLIB_INSTALL)
+if (TRUE)
# TODO: Cmake forces to install PUBLIC_HEADER when defined
# https://gitlab.kitware.com/cmake/cmake/-/issues/24326
- install(TARGETS Spglib_symspg
- LIBRARY DESTINATION ${Python_INSTALL_DIR} COMPONENT Spglib_Runtime
- NAMELINK_COMPONENT Spglib_Development
- ARCHIVE DESTINATION ${Python_INSTALL_DIR} COMPONENT Spglib_Development
- PUBLIC_HEADER DESTINATION ${Python_INSTALL_DIR} COMPONENT Spglib_Development
- RUNTIME DESTINATION ${Python_INSTALL_DIR} COMPONENT Spglib_Runtime
- )
+ #install(TARGETS Spglib_symspg
+ # LIBRARY DESTINATION ${Python_INSTALL_DIR} COMPONENT Spglib_Runtime
+ # NAMELINK_COMPONENT Spglib_Development
+ # ARCHIVE DESTINATION ${Python_INSTALL_DIR} COMPONENT Spglib_Development
+ # PUBLIC_HEADER DESTINATION ${Python_INSTALL_DIR} COMPONENT Spglib_Development
+ # RUNTIME DESTINATION ${Python_INSTALL_DIR} COMPONENT Spglib_Runtime
+ #)
install(TARGETS Spglib_python
LIBRARY DESTINATION ${Python_INSTALL_DIR} COMPONENT Spglib_Runtime
)

View file

@ -1,31 +0,0 @@
--- spglib/spglib.py.orig 2024-02-11 17:45:53 UTC
+++ spglib/spglib.py
@@ -46,17 +46,17 @@ except ImportError:
import re
from ctypes import cdll
- bundled_lib = next(
- filter(
- lambda fl: re.match(".*symspg\\..*", fl),
- sorted(os.listdir(os.path.dirname(__file__))),
- ),
- None,
- )
- if not bundled_lib:
- raise FileNotFoundError(
- "Spglib C library is not installed and no bundled version was detected"
- )
+ #bundled_lib = next(
+ # filter(
+ # lambda fl: re.match(".*symspg\\..*", fl),
+ # sorted(os.listdir(os.path.dirname(__file__))),
+ # ),
+ # None,
+ #)
+ #if not bundled_lib:
+ # raise FileNotFoundError(
+ # "Spglib C library is not installed and no bundled version was detected"
+ # )
cdll.LoadLibrary(os.path.join(os.path.dirname(__file__), bundled_lib))
from spglib import _spglib as spg # type: ignore[attr-defined]

View file

@ -1,39 +0,0 @@
import numpy as np
import spglib
lattice = np.array([[0.0, 0.5, 0.5],
[0.5, 0.0, 0.5],
[0.5, 0.5, 0.0]]) * 5.4
positions = [[0.875, 0.875, 0.875],
[0.125, 0.125, 0.125]]
numbers= [1,] * 2
cell = (lattice, positions, numbers)
print(spglib.get_spacegroup(cell, symprec=1e-5))
mesh = [8, 8, 8]
#
# Gamma centre mesh
#
mapping, grid = spglib.get_ir_reciprocal_mesh(mesh, cell, is_shift=[0, 0, 0])
# All k-points and mapping to ir-grid points
for i, (ir_gp_id, gp) in enumerate(zip(mapping, grid)):
print("%3d ->%3d %s" % (i, ir_gp_id, gp.astype(float) / mesh))
# Irreducible k-points
print("Number of ir-kpoints: %d" % len(np.unique(mapping)))
print(grid[np.unique(mapping)] / np.array(mesh, dtype=float))
#
# With shift
#
mapping, grid = spglib.get_ir_reciprocal_mesh(mesh, cell, is_shift=[1, 1, 1])
# All k-points and mapping to ir-grid points
for i, (ir_gp_id, gp) in enumerate(zip(mapping, grid)):
print("%3d ->%3d %s" % (i, ir_gp_id, (gp + [0.5, 0.5, 0.5]) / mesh))
# Irreducible k-points
print("Number of ir-kpoints: %d" % len(np.unique(mapping)))
print((grid[np.unique(mapping)] + [0.5, 0.5, 0.5]) / mesh)

View file

@ -1,3 +0,0 @@
%%PYTHON_SITELIBDIR%%/spglib/__init__.py
%%PYTHON_SITELIBDIR%%/spglib/_spglib%%PYTHON_EXT_SUFFIX%%.so
%%PYTHON_SITELIBDIR%%/spglib/spglib.py