Skip to content

Commit

Permalink
Fix sdist
Browse files Browse the repository at this point in the history
  • Loading branch information
almarklein committed Sep 23, 2024
1 parent 6220bda commit fb840b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ path = "wgpu/__init__.py"
[tool.hatch.build.targets.sdist]
packages = ["wgpu"]
exclude = ["*.so", "*.dll", "*.dylib"]
force-include = { "tools" = "tools" }

[tool.hatch.build.targets.wheel]
packages = ["wgpu"]
Expand Down
25 changes: 19 additions & 6 deletions tools/hatch_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Set wheel to being platform-specific (not pure Python).
* Download the wgpu-native library before creating the wheel.
* Support cross-platform wheel building with a custom env var.
* Note that for sdist we go into pure-Python mode.
"""

# Note on an alternative approach:
Expand All @@ -24,11 +25,12 @@

import os
import sys
from subprocess import getoutput
from subprocess import run, PIPE, STDOUT

from hatchling.builders.hooks.plugin.interface import BuildHookInterface

sys.path.insert(0, os.path.abspath(os.path.join(__file__, "..")))
root_dir = os.path.abspath(os.path.join(__file__, "..", ".."))
sys.path.insert(0, os.path.join(root_dir, "tools"))

from download_wgpu_native import main as download_lib # noqa

Expand All @@ -37,7 +39,11 @@ class CustomBuildHook(BuildHookInterface):
def initialize(self, version, build_data):
# See https://hatch.pypa.io/latest/plugins/builder/wheel/#build-data

if self.target_name == "wheel":
# We only do our thing when this is a wheel build from the repo.
# If this is an sdist build, or a wheel build from an sdist,
# we go pure-Python mode, and expect the user to set WGPU_LIB_PATH.

if self.target_name == "wheel" and is_git_repo():

# Prepare
check_git_status()
Expand All @@ -63,16 +69,23 @@ def initialize(self, version, build_data):
check_git_status()


def is_git_repo():
return os.path.isdir(os.path.join(root_dir, ".git"))


def check_git_status():
git_status = getoutput("git status --porcelain")
p = run(
"git status --porcelain", shell=True, cwd=root_dir, stdout=PIPE, stderr=STDOUT
)
git_status = p.stdout.decode(errors="ignore")
# print("Git status:\n" + git_status)
for line in git_status.splitlines():
assert not line.strip().startswith("M wgpu/"), "Git has open changes!"


def remove_all_libs():
dir = "wgpu/resources/"
dir = os.path.join(root_dir, "wgpu", "resources")
for fname in os.listdir(dir):
if fname.endswith((".so", ".dll", ".dylib")):
os.remove(dir + fname)
os.remove(os.path.join(dir, fname))
print(f"Removed {fname} from resource dir")

0 comments on commit fb840b6

Please sign in to comment.