Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
35 changes: 35 additions & 0 deletions .github/scripts/check_sdist_artifacts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Check native source distributions after compiled extensions exist."""

import shutil
import sys
import tarfile
import tempfile
import tomllib
from pathlib import Path

from hatchling.builders.sdist import SdistBuilder

source = Path(sys.argv[1]).resolve()
with tempfile.TemporaryDirectory() as temporary:
project = Path(temporary) / "project"
shutil.copytree(
source,
project,
ignore=shutil.ignore_patterns(".git", ".venv", "__pycache__", "node_modules", "target", "dist", "vcpkg", "vcpkg_installed", "emsdk"),
)
config = tomllib.loads((project / "pyproject.toml").read_text())
module = config["tool"]["hatch"]["build"]["targets"]["wheel"]["packages"][0]
extensions = (".so", ".dll", ".dylib", ".pyd")
for suffix in extensions:
(project / module / f"_sdist_binary_check{suffix}").write_bytes(b"prebuilt binary")

output = Path(temporary) / "dist"
output.mkdir()
filename = next(SdistBuilder(str(project)).build(directory=str(output)))
with tarfile.open(output / filename) as archive:
names = archive.getnames()

binaries = [name for name in names if name.endswith(extensions)]
assert not binaries, f"Source distribution contains compiled extensions: {binaries}"
assert any(name.endswith((".cpp", ".rs")) for name in names), "Source distribution is missing native sources"
print(f"{source.name}: source distribution excludes compiled extensions and retains native sources")
6 changes: 6 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,9 @@ jobs:

- name: Test template
run: make test-${{ matrix.template }}

- name: Check source distribution artifacts
run: python .github/scripts/check_sdist_artifacts.py ../python-template-${{ matrix.template }}
env:
HATCH_BUILD_NO_HOOKS: '1'
if: matrix.template == 'cpp' || matrix.template == 'cppjswasm' || matrix.template == 'rust' || matrix.template == 'rustjswasm'
13 changes: 6 additions & 7 deletions python/cpp/pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,6 @@ exclude_also = [
ignore_errors = true
fail_under = 50

[tool.hatch.build]
artifacts = [
"{{ module }}/*.dll",
"{{ module }}/*.dylib",
"{{ module }}/*.so",
]

[tool.hatch.build.sources]
src = "/"

Expand All @@ -138,6 +131,7 @@ libraries = [
]

[tool.hatch.build.targets.sdist]
exclude = ["*.dll", "*.dylib", "*.so", "*.pyd"]
packages = [
"{{ module }}",
"cpp",
Expand All @@ -149,6 +143,11 @@ packages = [
{% endif %}

[tool.hatch.build.targets.wheel]
artifacts = [
"{{ module }}/*.dll",
"{{ module }}/*.dylib",
"{{ module }}/*.so",
]
packages = [
"{{ module }}",
]
Expand Down
10 changes: 7 additions & 3 deletions python/cppjswasm/pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ fail_under = 50

[tool.hatch.build]
artifacts = [
"{{ module }}/*.dll",
"{{ module }}/*.dylib",
"{{ module }}/*.so",
"{{ module }}/extension",
]

Expand All @@ -159,6 +156,7 @@ libraries = [
]

[tool.hatch.build.targets.sdist]
exclude = ["*.dll", "*.dylib", "*.so", "*.pyd"]
packages = [
"{{ module }}",
"cpp",
Expand All @@ -171,6 +169,12 @@ packages = [
{% endif %}

[tool.hatch.build.targets.wheel]
artifacts = [
"{{ module }}/*.dll",
"{{ module }}/*.dylib",
"{{ module }}/*.so",
"{{ module }}/extension",
]
packages = [
"{{ module }}",
]
Expand Down
16 changes: 9 additions & 7 deletions python/rust/pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,6 @@ exclude_also = [
ignore_errors = true
fail_under = 50

[tool.hatch.build]
artifacts = [
"{{ module }}/*.dll",
"{{ module }}/*.dylib",
"{{ module }}/*.so",
]

[tool.hatch.build.sources]
src = "/"

Expand All @@ -165,11 +158,20 @@ packages = [
"Cargo.lock",
]
exclude = [
"*.dll",
"*.dylib",
"*.so",
"*.pyd",
"rust/Makefile",
"target",
]

[tool.hatch.build.targets.wheel]
artifacts = [
"{{ module }}/*.dll",
"{{ module }}/*.dylib",
"{{ module }}/*.so",
]
packages = [
"{{ module }}",
]
Expand Down
16 changes: 10 additions & 6 deletions python/rustjswasm/pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@ fail_under = 50

[tool.hatch.build]
artifacts = [
"{{ module }}/*.dll",
"{{ module }}/*.dylib",
"{{ module }}/*.so",
"{{ module }}/extension",
]

Expand Down Expand Up @@ -188,9 +185,10 @@ packages = [
"Cargo.lock",
]
exclude = [
"{{ module }}/*.dll",
"{{ module }}/*.dylib",
"{{ module }}/*.so",
"*.dll",
"*.dylib",
"*.so",
"*.pyd",
"{{ module }}/extension",
"js/dist",
"js/node_modules",
Expand All @@ -199,6 +197,12 @@ exclude = [
]

[tool.hatch.build.targets.wheel]
artifacts = [
"{{ module }}/*.dll",
"{{ module }}/*.dylib",
"{{ module }}/*.so",
"{{ module }}/extension",
]
packages = [
"{{ module }}",
]
Expand Down
Loading