Skip to content

Commit

Permalink
Build featomic wheels against metatensor wheels
Browse files Browse the repository at this point in the history
Instead of pulling a separate metatensor version from github
  • Loading branch information
Luthaf committed Nov 29, 2024
1 parent 82f48c3 commit a89bbd6
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions python/featomic/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include featomic-cxx-*.tar.gz
include git_version_info
include build-backend/backend.py

include pyproject.toml
include AUTHORS
Expand Down
15 changes: 15 additions & 0 deletions python/featomic/build-backend/backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from setuptools import build_meta


get_requires_for_build_sdist = build_meta.get_requires_for_build_sdist
prepare_metadata_for_build_wheel = build_meta.prepare_metadata_for_build_wheel
build_wheel = build_meta.build_wheel
build_sdist = build_meta.build_sdist


def get_requires_for_build_wheel(config_settings=None):
defaults = build_meta.get_requires_for_build_wheel(config_settings)
return defaults + [
"cmake",
"metatensor-core >=0.1.11,<0.2.0",
]
7 changes: 5 additions & 2 deletions python/featomic/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ requires = [
"setuptools",
"wheel",
"packaging",
"cmake",
]
build-backend = "setuptools.build_meta"

# use a custom build backend to add a dependency on metatensor/cmake only when
# building the wheels
build-backend = "backend"
backend-path = ["build-backend"]

[tool.setuptools]
zip-safe = true
Expand Down
18 changes: 3 additions & 15 deletions python/featomic/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import glob
import os
import shutil
import subprocess
import sys

Expand Down Expand Up @@ -45,6 +44,8 @@ class cmake_ext(build_ext):

def run(self):
"""Run cmake build and install the resulting library."""
import metatensor

source_dir = FEATOMIC_SRC
build_dir = os.path.join(ROOT, "build", "cmake-build")
install_dir = os.path.join(os.path.realpath(self.build_lib), "featomic")
Expand All @@ -58,7 +59,7 @@ def run(self):
f"-DCMAKE_INSTALL_PREFIX={install_dir}",
"-DCMAKE_INSTALL_LIBDIR=lib",
f"-DCMAKE_BUILD_TYPE={FEATOMIC_BUILD_TYPE}",
"-DFEATOMIC_FETCH_METATENSOR=ON",
f"-DCMAKE_PREFIX_PATH={metatensor.utils.cmake_prefix_path}",
"-DFEATOMIC_INSTALL_BOTH_STATIC_SHARED=OFF",
"-DBUILD_SHARED_LIBS=ON",
"-DEXTRA_RUST_FLAGS=-Cstrip=symbols",
Expand Down Expand Up @@ -113,19 +114,6 @@ def run(self):
check=True,
)

# do not include metatensor libraries/headers/cmake config within
# featomic wheel
for file in glob.glob(os.path.join(install_dir, "lib", "libmetatensor.*")):
os.unlink(file)

for file in glob.glob(os.path.join(install_dir, "bin", "metatensor.dll")):
os.unlink(file)

shutil.rmtree(os.path.join(install_dir, "lib", "cmake", "metatensor"))

for file in glob.glob(os.path.join(install_dir, "include", "metatensor*")):
os.unlink(file)


class bdist_egg_disabled(bdist_egg):
"""Disabled version of bdist_egg
Expand Down
1 change: 1 addition & 0 deletions python/featomic_torch/build-backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
def get_requires_for_build_wheel(config_settings=None):
defaults = build_meta.get_requires_for_build_wheel(config_settings)
return defaults + [
"cmake",
"torch >= 1.12",
"metatensor-torch >=0.6.0,<0.7.0",
FEATOMIC_DEP,
Expand Down
1 change: 0 additions & 1 deletion python/featomic_torch/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ requires = [
"setuptools",
"wheel",
"packaging",
"cmake",
]

# use a custom build backend to add a dependency on the right version of featomic
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ description =
passenv = *
deps =
{[testenv]packaging_deps}
{[testenv]metatensor-core-requirement}


commands =
Expand Down

0 comments on commit a89bbd6

Please sign in to comment.