Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically call CMake as part of PEP 517 build #1512

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["setuptools >= 63.0.0"]
build-backend = "setuptools.build_meta"
requires = ["scikit-build-core", "setuptools >= 63.0.0"]
build-backend = "scikit_build_core.setuptools.build_meta"

[project]
name = "bitsandbytes"
Expand Down
24 changes: 23 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from distutils.errors import DistutilsModuleError
from warnings import warn

from setuptools import find_packages, setup
from setuptools.command.build_py import build_py
from setuptools.dist import Distribution


Expand All @@ -12,4 +16,22 @@ def has_ext_modules(self):
return True


setup(version="0.45.3.dev0", packages=find_packages(), distclass=BinaryDistribution)
class ExtBuildPy(build_py):
def run(self):
# build_cmake needs to be called prior to build_py, as the latter
# collects the files output into the package directory.
try:
self.run_command("build_cmake")
except DistutilsModuleError:
warn("scikit-build-core not installed, CMake will not be invoked automatically. "
"Please install scikit-build-core or run CMake manually to build extensions.")
super().run()


setup(version="0.45.3.dev0",
packages=find_packages(),
distclass=BinaryDistribution,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, this is no longer necessary when CMake is called. However, since I preserved the support for using setup.py without scikit-build-core installed, I've left this hack in.

cmake_source_dir=".",
cmdclass={
"build_py": ExtBuildPy,
})
Loading