Skip to content
This repository was archived by the owner on Apr 6, 2026. It is now read-only.

Commit f1165ed

Browse files
authored
Remove Python bytecode after checks (#286)
The included byte code will be symlinked in snapshots in the Hub cache. However, Python replaces them by regular files, causing havoc for e.g. hash computation in `kernels`.
1 parent 13998b0 commit f1165ed

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

lib/torch-extension/arch.nix

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,25 @@
55

66
lib,
77
stdenv,
8-
cudaPackages,
8+
9+
# Native build inputs
10+
build2cmake,
911
cmake,
1012
cmakeNvccThreadsHook,
11-
ninja,
12-
build2cmake,
1313
get-kernel-check,
1414
kernel-abi-check,
15+
ninja,
1516
python3,
17+
remove-bytecode-hook,
1618
rewrite-nix-paths-macho,
17-
rocmPackages,
1819
writeScriptBin,
20+
21+
# Framework packages
22+
cudaPackages,
23+
rocmPackages,
1924
xpuPackages,
2025

26+
# Build inputs
2127
apple-sdk_15,
2228
clr,
2329
oneapi-torch-dev,
@@ -102,6 +108,7 @@ stdenv.mkDerivation (prevAttrs: {
102108
cmake
103109
ninja
104110
build2cmake
111+
remove-bytecode-hook
105112
]
106113
++ lib.optionals doGetKernelCheck [
107114
get-kernel-check

overlay.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ final: prev: {
1111

1212
rewrite-nix-paths-macho = prev.callPackage ./pkgs/rewrite-nix-paths-macho { };
1313

14+
remove-bytecode-hook = prev.callPackage ./pkgs/remove-bytecode-hook { };
15+
1416
stdenvGlibc_2_27 = prev.callPackage ./pkgs/stdenv-glibc-2_27 { };
1517

1618
# Python packages
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{ makeSetupHook, python3 }:
2+
3+
makeSetupHook {
4+
name = "remove-bytecode-hook";
5+
} ./remove-bytecode-hook.sh
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
echo "Sourcing remove-bytecode-hook.sh"
4+
5+
removeBytecodeHook() {
6+
echo "Removing Python bytecode"
7+
find $out -type d -name '__pycache__' -exec rm -rf {} +
8+
}
9+
10+
if [ -z "${dontRemoveBytecode-}" ]; then
11+
appendToVar preDistPhases removeBytecodeHook
12+
fi

0 commit comments

Comments
 (0)