scikit-build-core: bug: build directory should always be ignored

After a couple of days of wrangling I was finally able to get my wheel built and working properly. After everything was tested, I noticed that the custom local _build directory was showing up when I typed git status so I added that directory to .gitignore. Once it was in there, the wheel build broke. I was able to fix broken build by removing the directory from .gitingore. I verified this multiple times both directions.

For reference, this commit has the broken build:

https://github.com/andrewprock/pokerstove/commit/d67da05c79bf421d6151668b976fa0d35b61f852

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20

Commits related to this issue

Most upvoted comments

We use the .gitignore by default to filter the contents of the SDist, and the documentation states this. It is a natural and useful default - hatchling also does this. You can manually include files and exclude files to override the .gitignore, but that’s how we filter by default.

By the way, this is also how a lot of modern tooling works; Meson, Cargo, etc all integrate with git to help with packaging.

@henryiii meson emphatically does NOT do this. A gitignore file contains diametrically opposed semantics – it is defined by git(1) to indicate files which shall not be committed to the git repository but which are build artifacts such as compiled .so files. If you use --force to add a file to the git repository anyway, then gitignore will be ignored and not processed for that file (since it is already checked into git, its sole use case no longer exists).

Using gitignore for sdist or wheel filtering would prevent using gitignore for git. You’d either logically prevent inclusion of files you specifically want to include such as prebuilt arch-independent assets (sdist) or extension modules (wheel), or you would prevent checking useful development-related files into git, such as .github/workflows/* or ci-scripts/*.

Meson uses gitattributes for sdist filtering, via the “export-ignore” attribute, which also tells git archive to not include those files e.g. when using GitHub autogenerated tarballs. This is semantically relevant, because it’s intended by git(1) to be used for files which are in a git repository, but which shouldn’t be exported out of it. (And that is exactly what you want for e.g. files that are only ever processed by GitHub Actions or CircleCI).

It’s absolutely a backend bug if a project tries to correctly use correct git technology to perform git-related tasks and the backend inappropriately used it to mean something different.

This patch fixes it for me:

diff --git a/pyproject.toml b/pyproject.toml
index a7c63bb..697f8ba 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -7,16 +7,12 @@ name = "pokerstove"
 version = "1.2"

 [tool.scikit-build]
-build-dir = "_build"
-wheel.packages = ["_build/python/pokerstove"]
-cmake.version = ">=3.5"
-cmake.build-type = "Release"
+build-dir = "_build/{wheel_tag}"
+wheel.packages = []
+cmake.version = ">=3.15"
 build.targets = ["pokerstove"]
-install.components = ["pokerstove"]
+install.components = ["python"]
 sdist.exclude = ["src/programs", "android", "win32", "src/ext", "doc", ".*"]
-# build.verbose = true
-# logging.level = "DEBUG"
-
 [tool.scikit-build.cmake.define]
 BUILD_PYTHON = "ON"

diff --git a/src/lib/python/CMakeLists.txt b/src/lib/python/CMakeLists.txt
index 4c42a44..e8a0dcb 100644
--- a/src/lib/python/CMakeLists.txt
+++ b/src/lib/python/CMakeLists.txt
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.18)

 # find swig and python and configure them
 set(CMAKE_SWIG_FLAGS)
+set(UseSWIG_MODULE_VERSION 2)
 find_package(SWIG REQUIRED)
 include(UseSWIG)

@@ -26,10 +27,13 @@ set_property(SOURCE pokerstove.i PROPERTY SWIG_MODULE_NAME ${PS_TARGET})
 swig_add_library(${PS_TARGET}
   TYPE MODULE
   LANGUAGE python
-  OUTPUT_DIR ${PYTHON_PROJECT_DIR}
   SOURCES pokerstove.i)
 add_library(${PROJECT_NAMESPACE}::${PS_TARGET} ALIAS ${PS_TARGET})

+install(TARGETS ${PS_TARGET} DESTINATION . COMPONENT python)
+get_property(_support_files TARGET ${PS_TARGET} PROPERTY SWIG_SUPPORT_FILES)
+install(FILES "${_support_files}" DESTINATION . COMPONENT python)
+
 # note: macOS is APPLE and also UNIX !
 if(APPLE)
   set_property(TARGET ${PS_TARGET} APPEND PROPERTY

Checked via:

$ uv build
$ tar -zvtf dist/*.tar.gz
$ unzip -l dist/*.whl
$ uv venv
$ uv pip install dist/*.whl
$ ./.venv/bin/python src/lib/python/test-python
-- rank --
2 6 4
-- suits --
c h c
-- cards --
2c 4c As
-- card sets --
empty card set:
3c4c5c9c 8cAc8dAh2s 8hAh
-- poker evals --
null eval:
one pair:      J5
three str8:    T
-- poker hand evals --
h1:
h2:  one pair:      J5
h3:  three str8:    T
-- poker hand --
ph1:
ph2:  8cAc8dAh2s
ph3:  AcAd3c4s5h6d7c
-- holdem hand evaluation --
high card:     A8
two pair:      A8K
-- holdem facts --
holdem board size:  5
num holdem rounds:  4
-- simple deck --
deck:  2c3c4c5c6c7c8c9cTcJcQcKcAc2d3d4d5d6d7d8d9dTdJdQdKdAd2h3h4h5h6h7h8h9hThJhQhKhAh2s3s4s5s6s7s8s9sTsJsQsKsAs/
deck:  Qc4cTdKsTc4dJs8c9sAhJcAd2d8s7sAc3cAs9cKdQd9hJdKh5h5s3d7d7hKc2h8d8h2c6c7cJh9d6h6dTh4hQs6sTs3sQh3h5c4s5d2s/
peek bottom:  4cQc
peek top:  2s
burn:  2s
holdem:  5d4s 5c3hQh
dealt (dead):  5c5d3hQh2s4s
deck:  Qc4cTdKsTc4dJs8c9sAhJcAd2d8s7sAc3cAs9cKdQd9hJdKh5h5s3d7d7hKc2h8d8h2c6c7cJh9d6h6dTh4hQs6sTs3s/Qh3h5c4s5d2s
-- card distribution --

Using install to assemble artifacts for an installer

The “installer” in pip is literally just a zip extractor. Wheel installs do nothing more than extract a few directories in a zip file (with a .whl extension) into specific locations. That’s it.

If you want to make site-packages/example.<...>.so, then you should do:

python_add_library(example MODULE example.c WITH_SOABI)
install(TARGETS example LIBRARY DESTINATION .)

And if you want to make to make site-packages/example/extension.<...>.so, then you should do:

python_add_library(extension MODULE extension.c WITH_SOABI)
install(TARGETS extension LIBRARY DESTINATION example)

You are “installing” into the main wheel directory (there are a few other directories that you can manually target, as well, like SKBUILD_SCRIPTS_DIR). Then these directors are zipped up into a zip file with a .whl extension. Pip builds this wheel file, then installs it exactly the same way as if it download the .whl directly.

Documentation can always be improved! Where were you looking and expecting to find it? It’s currently at https://scikit-build-core.readthedocs.io/en/latest/configuration.html#configuring-source-file-inclusion.