Skip to content

Commit

Permalink
changing build system used by pip (setuptools -> scikit-build-core)
Browse files Browse the repository at this point in the history
  • Loading branch information
wojdyr committed Sep 14, 2023
1 parent 01ae131 commit 863cf47
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 258 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ tags
/docs/_build
/.eggs/
.gdb_history
.*.swp

# files generated by cmake
/CMakeFiles/
Expand Down
33 changes: 15 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ string(REGEX REPLACE ".+\"([0-9]+\.[0-9]+\.[0-9]+)(-dev)?\"" "\\1"
project(gemmi LANGUAGES C CXX VERSION ${gemmi_version_str})
message(STATUS "Gemmi version ${PROJECT_VERSION}")

include(GNUInstallDirs) # for CMAKE_INSTALL_LIBDIR
include(GNUInstallDirs) # for CMAKE_INSTALL_LIBDIR, etc

if (DEFINED SKBUILD) # building with scikit-build-core (pip install)
# we set wheel.install-dir="/data" in pyproject.toml,
# so here we need to only set paths to /platlib and /scripts
set(PYTHON_INSTALL_DIR "${SKBUILD_PLATLIB_DIR}")
#set(CMAKE_INSTALL_BINDIR "${SKBUILD_SCRIPTS_DIR}")
endif()

option(BUILD_SHARED_LIBS "Build using shared library" OFF)
option(BUILD_GEMMI_PROGRAM "Build gemmi command-line program" ON)
option(USE_FORTRAN "Build Fortran bindings" OFF)
option(USE_PYTHON "Build Python bindings" OFF)
option(INSTALL_EGG_INFO "Install .egg-info via setup.py" ON)
option(EXTRA_WARNINGS "Set extra warning flags" OFF)
option(USE_WMAIN "(Windows only) take Unicode arguments in gemmi program" ON)
set(GEMMI_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/gemmi" CACHE STRING
Expand Down Expand Up @@ -106,7 +112,10 @@ else()
message(STATUS "The build will use zlib code from third_party/zlib.")
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/third_party/zlib")
endif()
find_package(benchmark 1.3 QUIET)

if (NOT DEFINED SKBUILD)
find_package(benchmark 1.3 QUIET)
endif()
if (benchmark_FOUND)
message(STATUS "Found benchmark: ${benchmark_DIR}")
else (NOT benchmark_FOUND)
Expand Down Expand Up @@ -379,6 +388,7 @@ endif()
### Python bindings ###
if (USE_PYTHON)
message(STATUS "The python module will be built.")
# CMake >=3.18 has subcomponent Development.Module
find_package(Python ${PYTHON_VERSION} REQUIRED COMPONENTS Interpreter Development)
if (EXISTS "${CMAKE_HOME_DIRECTORY}/pybind11")
message(STATUS "Using ${CMAKE_HOME_DIRECTORY}/pybind11 (internal copy).")
Expand Down Expand Up @@ -422,6 +432,7 @@ write_basic_package_version_file(gemmi-config-version.cmake
install(DIRECTORY include/gemmi DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")

if (BUILD_GEMMI_PROGRAM)
# Is it useful to have the program location in gemmi-targets.cmake?
install(TARGETS gemmi_prog EXPORT GemmiTargets)
endif()
install(TARGETS gemmi_cpp
Expand All @@ -439,24 +450,10 @@ if (USE_PYTHON)
if (DEFINED PYTHON_INSTALL_DIR)
message(STATUS "Install directory for Python module: ${PYTHON_INSTALL_DIR}")
set(Python_SITEARCH "${PYTHON_INSTALL_DIR}")
set(Python_SITELIB "${PYTHON_INSTALL_DIR}")
endif()
file(TO_CMAKE_PATH "${Python_SITEARCH}" Python_SITEARCH)
file(TO_CMAKE_PATH "${Python_SITELIB}" Python_SITELIB)
# Using Python_SITEARCH and SITELIB is not good, because they are absolute
# Using Python_SITEARCH/SITELIB is not good, because they are absolute
# and don't respect CMAKE_INSTALL_PREFIX.
# https://discourse.cmake.org/t/findpython3-how-to-specify-local-installation-directory-for-python-module/3580/5
install(TARGETS gemmi_py DESTINATION "${Python_SITEARCH}")
install(DIRECTORY examples/ DESTINATION "${Python_SITELIB}/gemmi-examples"
FILES_MATCHING PATTERN "*.py")
if (INSTALL_EGG_INFO)
install(CODE
"execute_process(COMMAND \"${Python_EXECUTABLE}\" setup.py install_egg_info --install-dir \"\$ENV{DESTDIR}${Python_SITELIB}\"
WORKING_DIRECTORY \"${CMAKE_SOURCE_DIR}\"
RESULT_VARIABLE EGG_STATUS)"
)
if (EGG_STATUS AND NOT EGG_STATUS EQUAL 0)
message(FATAL_ERROR "Failed to install egg-info. Use -D INSTALL_EGG_INFO=OFF to disable.")
endif()
endif()
endif()
10 changes: 0 additions & 10 deletions MANIFEST.in

This file was deleted.

4 changes: 0 additions & 4 deletions docs/cif.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1581,10 +1581,6 @@ Examples
The examples here use C++11 or Python.
Full working code code can be found in the examples__ directory.

If you have the Python ``gemmi`` module installed you should also have
the Python examples -- try ``python -m gemmi-examples`` if not sure
where they are.

The examples below can be run on one or more PDBx/mmCIF files.
The ones that perform PDB-wide analysis are meant to be run on a
`local copy <https://www.wwpdb.org/download/downloads>`_ of the mmCIF
Expand Down
4 changes: 1 addition & 3 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ If the compiler is not installed, pip shows a message with a download link.
If gemmi is already installed, uninstall the old version first
(``pip uninstall``) or add option ``--upgrade``.

Setuptools compile only one unit at a time and the whole process
takes several minutes. To make it faster, build in parallel with CMake.
Clone the project and do::
Alternatively, you can build a cloned project with CMake::

cmake -D USE_PYTHON=1 .
make -j4 py
Expand Down
Empty file removed examples/__init__.py
Empty file.
10 changes: 0 additions & 10 deletions examples/__main__.py

This file was deleted.

75 changes: 75 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
[build-system]
requires = ["scikit-build-core==0.5.0", "pybind11>=2.6.2"]
build-backend = "scikit_build_core.build"

# https://packaging.python.org/en/latest/specifications/declaring-project-metadata/
[project]
name = "gemmi"
dynamic = ["version"]
requires-python = ">=3.7"
description="library for structural biology"
readme = "README.md"
authors = [
{ name = "Marcin Wojdyr", email = "[email protected]" },
]
urls.repository = "https://github.com/project-gemmi/gemmi"
license = {text = "MPL-2.0"} # or, at your option, LGPL-3.0
keywords = ["structural bioinformatics", "structural biology",
"crystallography", "CIF", "mmCIF", "PDB", "CCP4", "MTZ"]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Scientific/Engineering :: Bio-Informatics",
"Topic :: Scientific/Engineering :: Chemistry",
"Programming Language :: C++",
"Programming Language :: Python",
]

[tool.scikit-build]
#build-dir = "/tmp/gemmi_build2/{wheel_tag}"
experimental = true # needed for install-dir
wheel.install-dir = "/data"
wheel.expand-macos-universal-tags = true # not sure if this is useful
wheel.packages = []
sdist.exclude = ["*"]
sdist.include = [
"/README.md",
"/LICENSE.txt",
"/CMakeLists.txt",
"/pyproject.toml",
"docs/code/*.cpp",
"examples/*.py",
"examples/*.cpp",
"include/gemmi/**/*.hpp",
"include/gemmi/third_party/*.h",
"include/gemmi/third_party/tao/**",
"src/*.cpp",
"prog/*.cpp",
"prog/*.h*",
"python/*.cpp",
"python/*.h*",
"third_party/README",
"third_party/*.h",
"third_party/zlib/*",
"tests/*",
"!tests/*.pyc",
"tools/gemmi-config.cmake.in"
]
cmake.build-type = "Release"
cmake.verbose = true
[tool.scikit-build.cmake.define]
USE_PYTHON = "ON"
#BUILD_GEMMI_PROGRAM = "OFF"

[tool.scikit-build.metadata.version]
provider = "scikit_build_core.metadata.regex"
input = "include/gemmi/version.hpp"
regex = "#define GEMMI_VERSION \"(?P<value>[0-9dev.-]+)\""

[tool.pytest.ini_options]
minversion = "6.0"
addopts = ["-ra", "-q"]
testpaths = ["tests"]
2 changes: 1 addition & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if [ -z "${NO_DOCTEST-}" ]; then
(cd docs && make doctest SPHINXOPTS="-q -n -E")
fi

flake8 docs/ examples/ tests/ tools/ setup.py
flake8 docs/ examples/ tests/ tools/
pybind11-stubgen --dry-run --exit-code gemmi


Expand Down
Loading

0 comments on commit 863cf47

Please sign in to comment.