liangsu9988 commited on
Commit
176bfb2
·
verified ·
1 Parent(s): ebcc50e

Promote latest kernel artifacts to main

Browse files
Files changed (17) hide show
  1. README.md +0 -9
  2. build/torch212-cxx11-cu130-x86_64-linux/_ops.py +3 -3
  3. build/{torch213-cxx11-cu130-x86_64-linux/_sageattention2_blackwell_cuda_5a0fd7c.abi3.so → torch212-cxx11-cu130-x86_64-linux/_sageattention2_blackwell_cuda_5542189.abi3.so} +2 -2
  4. build/torch212-cxx11-cu130-x86_64-linux/metadata.json +6 -6
  5. build/torch212-cxx11-cu130-x86_64-linux/sageattention2_blackwell/__init__.py +0 -26
  6. build/torch212-cxx11-cu132-x86_64-linux/_ops.py +3 -3
  7. build/{torch212-cxx11-cu130-x86_64-linux/_sageattention2_blackwell_cuda_5a0fd7c.abi3.so → torch212-cxx11-cu132-x86_64-linux/_sageattention2_blackwell_cuda_5542189.abi3.so} +2 -2
  8. build/torch212-cxx11-cu132-x86_64-linux/metadata.json +6 -6
  9. build/torch212-cxx11-cu132-x86_64-linux/sageattention2_blackwell/__init__.py +0 -26
  10. build/torch213-cxx11-cu130-x86_64-linux/_ops.py +3 -3
  11. build/{torch213-cxx11-cu132-x86_64-linux/_sageattention2_blackwell_cuda_5a0fd7c.abi3.so → torch213-cxx11-cu130-x86_64-linux/_sageattention2_blackwell_cuda_5542189.abi3.so} +2 -2
  12. build/torch213-cxx11-cu130-x86_64-linux/metadata.json +6 -6
  13. build/torch213-cxx11-cu130-x86_64-linux/sageattention2_blackwell/__init__.py +0 -26
  14. build/torch213-cxx11-cu132-x86_64-linux/_ops.py +3 -3
  15. build/{torch212-cxx11-cu132-x86_64-linux/_sageattention2_blackwell_cuda_5a0fd7c.abi3.so → torch213-cxx11-cu132-x86_64-linux/_sageattention2_blackwell_cuda_5542189.abi3.so} +2 -2
  16. build/torch213-cxx11-cu132-x86_64-linux/metadata.json +6 -6
  17. build/torch213-cxx11-cu132-x86_64-linux/sageattention2_blackwell/__init__.py +0 -26
README.md DELETED
@@ -1,9 +0,0 @@
1
- # flashrt/sageattention2-blackwell
2
-
3
- This repository is a compatibility mirror for older `kernels` clients
4
- that resolve repositories through the default Hugging Face model repo API.
5
-
6
- Canonical Kernel Hub repo: https://huggingface.co/kernels/flashrt/sageattention2-blackwell
7
-
8
- Do not edit this mirror by hand. It is generated from the Kernel Hub
9
- `vN` branches and contains the same `build/**` artifacts.
 
 
 
 
 
 
 
 
 
 
build/torch212-cxx11-cu130-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _sageattention2_blackwell_cuda_5a0fd7c
3
- ops = torch.ops._sageattention2_blackwell_cuda_5a0fd7c
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_sageattention2_blackwell_cuda_5a0fd7c::{op_name}"
 
1
  import torch
2
+ from . import _sageattention2_blackwell_cuda_5542189
3
+ ops = torch.ops._sageattention2_blackwell_cuda_5542189
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_sageattention2_blackwell_cuda_5542189::{op_name}"
build/{torch213-cxx11-cu130-x86_64-linux/_sageattention2_blackwell_cuda_5a0fd7c.abi3.so → torch212-cxx11-cu130-x86_64-linux/_sageattention2_blackwell_cuda_5542189.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:10b95b1b6a442136aa59173636c65658d01b9c748a53dcf1aea56741eee39c9f
3
- size 1955000
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:890ba58ff538a10e9f653567cc73980549c19e2359ec294f12b626485af1ed70
3
+ size 1942872
build/torch212-cxx11-cu130-x86_64-linux/metadata.json CHANGED
@@ -1,9 +1,10 @@
1
  {
2
  "name": "sageattention2-blackwell",
3
- "id": "_sageattention2_blackwell_cuda_5a0fd7c",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
 
7
  "backend": {
8
  "type": "cuda",
9
  "archs": [
@@ -15,19 +16,18 @@
15
  "algorithm": "sha256",
16
  "files": {
17
  "__init__.py": "8RunKSRFou+DKdhegD8QAZyIVl14pLifEwNYbIa72jY=",
18
- "_ops.py": "aw3gYxBOMlkvKm5pwWx+yzY8pCIs/lgXZV5fqYHr0IU=",
19
- "_sageattention2_blackwell_cuda_5a0fd7c.abi3.so": "QBhrNyqwcmwVxtOvaTEuCZq1oVBDR2QbvpeG5C7YjNU=",
20
- "sageattention2_blackwell/__init__.py": "DFYPlrhXwYjEqCl/8n0SmWGZV8NFml5DPhMjKfv98GY="
21
  }
22
  },
23
  "provenance": {
24
  "kernel-builder": {
25
  "version": "0.17.0-dev0",
26
- "sha": "b39ca23f1b36383df00b27b3ffe1276cd5dbea85",
27
  "dirty": false
28
  },
29
  "kernel": {
30
- "sha": "5a0fd7c325e3521f288901f25624000c5f597d95",
31
  "dirty": false
32
  }
33
  }
 
1
  {
2
  "name": "sageattention2-blackwell",
3
+ "id": "_sageattention2_blackwell_cuda_5542189",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
7
+ "kernel-depends": [],
8
  "backend": {
9
  "type": "cuda",
10
  "archs": [
 
16
  "algorithm": "sha256",
17
  "files": {
18
  "__init__.py": "8RunKSRFou+DKdhegD8QAZyIVl14pLifEwNYbIa72jY=",
19
+ "_ops.py": "pDaNx2t5PnKVEVqTSd3ensPGiyrHpyDIzxhNCbNH9FY=",
20
+ "_sageattention2_blackwell_cuda_5542189.abi3.so": "iQulj/U4oQ6fZTVnzHOYBUnBniNZ7ClPErYmSFrx7XA="
 
21
  }
22
  },
23
  "provenance": {
24
  "kernel-builder": {
25
  "version": "0.17.0-dev0",
26
+ "sha": "3a5c09d941a19f582fe551d038dc2b3bc6b0a03d",
27
  "dirty": false
28
  },
29
  "kernel": {
30
+ "sha": "5542189ca3e6593cabfd117a3b1becf0661c60d3",
31
  "dirty": false
32
  }
33
  }
build/torch212-cxx11-cu130-x86_64-linux/sageattention2_blackwell/__init__.py DELETED
@@ -1,26 +0,0 @@
1
- import ctypes
2
- import importlib.util
3
- import sys
4
- from pathlib import Path
5
- from types import ModuleType
6
-
7
-
8
- def _import_from_path(file_path: Path) -> ModuleType:
9
- # We cannot use the module name as-is, after adding it to `sys.modules`,
10
- # it would also be used for other imports. So, we make a module name that
11
- # depends on the path for it to be unique using the hex-encoded hash of
12
- # the path.
13
- path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
14
- module_name = path_hash
15
- spec = importlib.util.spec_from_file_location(module_name, file_path)
16
- if spec is None:
17
- raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
18
- module = importlib.util.module_from_spec(spec)
19
- if module is None:
20
- raise ImportError(f"Cannot load module {module_name} from spec")
21
- sys.modules[module_name] = module
22
- spec.loader.exec_module(module) # type: ignore
23
- return module
24
-
25
-
26
- globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
build/torch212-cxx11-cu132-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _sageattention2_blackwell_cuda_5a0fd7c
3
- ops = torch.ops._sageattention2_blackwell_cuda_5a0fd7c
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_sageattention2_blackwell_cuda_5a0fd7c::{op_name}"
 
1
  import torch
2
+ from . import _sageattention2_blackwell_cuda_5542189
3
+ ops = torch.ops._sageattention2_blackwell_cuda_5542189
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_sageattention2_blackwell_cuda_5542189::{op_name}"
build/{torch212-cxx11-cu130-x86_64-linux/_sageattention2_blackwell_cuda_5a0fd7c.abi3.so → torch212-cxx11-cu132-x86_64-linux/_sageattention2_blackwell_cuda_5542189.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:40186b372ab0726c15c6d3af69312e099ab5a1504347641bbe9786e42ed88cd5
3
- size 1955160
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3e0bf409f82574c40d33c63b20950f5b898f6ecaad8a8f8e2cf7db638afd804e
3
+ size 1799616
build/torch212-cxx11-cu132-x86_64-linux/metadata.json CHANGED
@@ -1,9 +1,10 @@
1
  {
2
  "name": "sageattention2-blackwell",
3
- "id": "_sageattention2_blackwell_cuda_5a0fd7c",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
 
7
  "backend": {
8
  "type": "cuda",
9
  "archs": [
@@ -15,19 +16,18 @@
15
  "algorithm": "sha256",
16
  "files": {
17
  "__init__.py": "8RunKSRFou+DKdhegD8QAZyIVl14pLifEwNYbIa72jY=",
18
- "_ops.py": "aw3gYxBOMlkvKm5pwWx+yzY8pCIs/lgXZV5fqYHr0IU=",
19
- "_sageattention2_blackwell_cuda_5a0fd7c.abi3.so": "48/BFgoespqJQEtVKYwK9ZxYW0ihorsHyAca4yvzYLE=",
20
- "sageattention2_blackwell/__init__.py": "DFYPlrhXwYjEqCl/8n0SmWGZV8NFml5DPhMjKfv98GY="
21
  }
22
  },
23
  "provenance": {
24
  "kernel-builder": {
25
  "version": "0.17.0-dev0",
26
- "sha": "b39ca23f1b36383df00b27b3ffe1276cd5dbea85",
27
  "dirty": false
28
  },
29
  "kernel": {
30
- "sha": "5a0fd7c325e3521f288901f25624000c5f597d95",
31
  "dirty": false
32
  }
33
  }
 
1
  {
2
  "name": "sageattention2-blackwell",
3
+ "id": "_sageattention2_blackwell_cuda_5542189",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
7
+ "kernel-depends": [],
8
  "backend": {
9
  "type": "cuda",
10
  "archs": [
 
16
  "algorithm": "sha256",
17
  "files": {
18
  "__init__.py": "8RunKSRFou+DKdhegD8QAZyIVl14pLifEwNYbIa72jY=",
19
+ "_ops.py": "pDaNx2t5PnKVEVqTSd3ensPGiyrHpyDIzxhNCbNH9FY=",
20
+ "_sageattention2_blackwell_cuda_5542189.abi3.so": "Pgv0CfgldMQNM8Y7IJUPW4mPbsqtio+OLPfbY4r9gE4="
 
21
  }
22
  },
23
  "provenance": {
24
  "kernel-builder": {
25
  "version": "0.17.0-dev0",
26
+ "sha": "3a5c09d941a19f582fe551d038dc2b3bc6b0a03d",
27
  "dirty": false
28
  },
29
  "kernel": {
30
+ "sha": "5542189ca3e6593cabfd117a3b1becf0661c60d3",
31
  "dirty": false
32
  }
33
  }
build/torch212-cxx11-cu132-x86_64-linux/sageattention2_blackwell/__init__.py DELETED
@@ -1,26 +0,0 @@
1
- import ctypes
2
- import importlib.util
3
- import sys
4
- from pathlib import Path
5
- from types import ModuleType
6
-
7
-
8
- def _import_from_path(file_path: Path) -> ModuleType:
9
- # We cannot use the module name as-is, after adding it to `sys.modules`,
10
- # it would also be used for other imports. So, we make a module name that
11
- # depends on the path for it to be unique using the hex-encoded hash of
12
- # the path.
13
- path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
14
- module_name = path_hash
15
- spec = importlib.util.spec_from_file_location(module_name, file_path)
16
- if spec is None:
17
- raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
18
- module = importlib.util.module_from_spec(spec)
19
- if module is None:
20
- raise ImportError(f"Cannot load module {module_name} from spec")
21
- sys.modules[module_name] = module
22
- spec.loader.exec_module(module) # type: ignore
23
- return module
24
-
25
-
26
- globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
build/torch213-cxx11-cu130-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _sageattention2_blackwell_cuda_5a0fd7c
3
- ops = torch.ops._sageattention2_blackwell_cuda_5a0fd7c
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_sageattention2_blackwell_cuda_5a0fd7c::{op_name}"
 
1
  import torch
2
+ from . import _sageattention2_blackwell_cuda_5542189
3
+ ops = torch.ops._sageattention2_blackwell_cuda_5542189
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_sageattention2_blackwell_cuda_5542189::{op_name}"
build/{torch213-cxx11-cu132-x86_64-linux/_sageattention2_blackwell_cuda_5a0fd7c.abi3.so → torch213-cxx11-cu130-x86_64-linux/_sageattention2_blackwell_cuda_5542189.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:3374124176237ceff0aa9adbf09a1ea610ef7ab3cd85f7e91b53577b7938ee33
3
- size 1811744
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:438f5764f533bee2f7c970a837789a9722d5c8841399d4fa8f5e4eee145508fb
3
+ size 1942712
build/torch213-cxx11-cu130-x86_64-linux/metadata.json CHANGED
@@ -1,9 +1,10 @@
1
  {
2
  "name": "sageattention2-blackwell",
3
- "id": "_sageattention2_blackwell_cuda_5a0fd7c",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
 
7
  "backend": {
8
  "type": "cuda",
9
  "archs": [
@@ -15,19 +16,18 @@
15
  "algorithm": "sha256",
16
  "files": {
17
  "__init__.py": "8RunKSRFou+DKdhegD8QAZyIVl14pLifEwNYbIa72jY=",
18
- "_ops.py": "aw3gYxBOMlkvKm5pwWx+yzY8pCIs/lgXZV5fqYHr0IU=",
19
- "_sageattention2_blackwell_cuda_5a0fd7c.abi3.so": "ELlbG2pEITaqWRc2NsZWWNAbnHSKU9zxrqVnQe7jnJ8=",
20
- "sageattention2_blackwell/__init__.py": "DFYPlrhXwYjEqCl/8n0SmWGZV8NFml5DPhMjKfv98GY="
21
  }
22
  },
23
  "provenance": {
24
  "kernel-builder": {
25
  "version": "0.17.0-dev0",
26
- "sha": "b39ca23f1b36383df00b27b3ffe1276cd5dbea85",
27
  "dirty": false
28
  },
29
  "kernel": {
30
- "sha": "5a0fd7c325e3521f288901f25624000c5f597d95",
31
  "dirty": false
32
  }
33
  }
 
1
  {
2
  "name": "sageattention2-blackwell",
3
+ "id": "_sageattention2_blackwell_cuda_5542189",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
7
+ "kernel-depends": [],
8
  "backend": {
9
  "type": "cuda",
10
  "archs": [
 
16
  "algorithm": "sha256",
17
  "files": {
18
  "__init__.py": "8RunKSRFou+DKdhegD8QAZyIVl14pLifEwNYbIa72jY=",
19
+ "_ops.py": "pDaNx2t5PnKVEVqTSd3ensPGiyrHpyDIzxhNCbNH9FY=",
20
+ "_sageattention2_blackwell_cuda_5542189.abi3.so": "Q49XZPUzvuL3yXCoN3ialyLVyIQTmdT6j15O7hRVCPs="
 
21
  }
22
  },
23
  "provenance": {
24
  "kernel-builder": {
25
  "version": "0.17.0-dev0",
26
+ "sha": "3a5c09d941a19f582fe551d038dc2b3bc6b0a03d",
27
  "dirty": false
28
  },
29
  "kernel": {
30
+ "sha": "5542189ca3e6593cabfd117a3b1becf0661c60d3",
31
  "dirty": false
32
  }
33
  }
build/torch213-cxx11-cu130-x86_64-linux/sageattention2_blackwell/__init__.py DELETED
@@ -1,26 +0,0 @@
1
- import ctypes
2
- import importlib.util
3
- import sys
4
- from pathlib import Path
5
- from types import ModuleType
6
-
7
-
8
- def _import_from_path(file_path: Path) -> ModuleType:
9
- # We cannot use the module name as-is, after adding it to `sys.modules`,
10
- # it would also be used for other imports. So, we make a module name that
11
- # depends on the path for it to be unique using the hex-encoded hash of
12
- # the path.
13
- path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
14
- module_name = path_hash
15
- spec = importlib.util.spec_from_file_location(module_name, file_path)
16
- if spec is None:
17
- raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
18
- module = importlib.util.module_from_spec(spec)
19
- if module is None:
20
- raise ImportError(f"Cannot load module {module_name} from spec")
21
- sys.modules[module_name] = module
22
- spec.loader.exec_module(module) # type: ignore
23
- return module
24
-
25
-
26
- globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
build/torch213-cxx11-cu132-x86_64-linux/_ops.py CHANGED
@@ -1,9 +1,9 @@
1
  import torch
2
- from . import _sageattention2_blackwell_cuda_5a0fd7c
3
- ops = torch.ops._sageattention2_blackwell_cuda_5a0fd7c
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
- return f"_sageattention2_blackwell_cuda_5a0fd7c::{op_name}"
 
1
  import torch
2
+ from . import _sageattention2_blackwell_cuda_5542189
3
+ ops = torch.ops._sageattention2_blackwell_cuda_5542189
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
  """
7
  Prefix op by namespace.
8
  """
9
+ return f"_sageattention2_blackwell_cuda_5542189::{op_name}"
build/{torch212-cxx11-cu132-x86_64-linux/_sageattention2_blackwell_cuda_5a0fd7c.abi3.so → torch213-cxx11-cu132-x86_64-linux/_sageattention2_blackwell_cuda_5542189.abi3.so} RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:e3cfc1160a1eb29a89404b55298c0af59c585b48a1a2bb07c8071ae32bf360b1
3
- size 1811904
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3a57447f1952300a6b372a8711cc8ac75640ed108a18bf8955f6744b8bd0c926
3
+ size 1799456
build/torch213-cxx11-cu132-x86_64-linux/metadata.json CHANGED
@@ -1,9 +1,10 @@
1
  {
2
  "name": "sageattention2-blackwell",
3
- "id": "_sageattention2_blackwell_cuda_5a0fd7c",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
 
7
  "backend": {
8
  "type": "cuda",
9
  "archs": [
@@ -15,19 +16,18 @@
15
  "algorithm": "sha256",
16
  "files": {
17
  "__init__.py": "8RunKSRFou+DKdhegD8QAZyIVl14pLifEwNYbIa72jY=",
18
- "_ops.py": "aw3gYxBOMlkvKm5pwWx+yzY8pCIs/lgXZV5fqYHr0IU=",
19
- "_sageattention2_blackwell_cuda_5a0fd7c.abi3.so": "M3QSQXYjfO/wqprb8JoephDverPNhffpG1NXe3k47jM=",
20
- "sageattention2_blackwell/__init__.py": "DFYPlrhXwYjEqCl/8n0SmWGZV8NFml5DPhMjKfv98GY="
21
  }
22
  },
23
  "provenance": {
24
  "kernel-builder": {
25
  "version": "0.17.0-dev0",
26
- "sha": "b39ca23f1b36383df00b27b3ffe1276cd5dbea85",
27
  "dirty": false
28
  },
29
  "kernel": {
30
- "sha": "5a0fd7c325e3521f288901f25624000c5f597d95",
31
  "dirty": false
32
  }
33
  }
 
1
  {
2
  "name": "sageattention2-blackwell",
3
+ "id": "_sageattention2_blackwell_cuda_5542189",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
7
+ "kernel-depends": [],
8
  "backend": {
9
  "type": "cuda",
10
  "archs": [
 
16
  "algorithm": "sha256",
17
  "files": {
18
  "__init__.py": "8RunKSRFou+DKdhegD8QAZyIVl14pLifEwNYbIa72jY=",
19
+ "_ops.py": "pDaNx2t5PnKVEVqTSd3ensPGiyrHpyDIzxhNCbNH9FY=",
20
+ "_sageattention2_blackwell_cuda_5542189.abi3.so": "OldEfxlSMAprNyqHEcyKx1ZA7RCKGL+JVfZ0S4vQySY="
 
21
  }
22
  },
23
  "provenance": {
24
  "kernel-builder": {
25
  "version": "0.17.0-dev0",
26
+ "sha": "3a5c09d941a19f582fe551d038dc2b3bc6b0a03d",
27
  "dirty": false
28
  },
29
  "kernel": {
30
+ "sha": "5542189ca3e6593cabfd117a3b1becf0661c60d3",
31
  "dirty": false
32
  }
33
  }
build/torch213-cxx11-cu132-x86_64-linux/sageattention2_blackwell/__init__.py DELETED
@@ -1,26 +0,0 @@
1
- import ctypes
2
- import importlib.util
3
- import sys
4
- from pathlib import Path
5
- from types import ModuleType
6
-
7
-
8
- def _import_from_path(file_path: Path) -> ModuleType:
9
- # We cannot use the module name as-is, after adding it to `sys.modules`,
10
- # it would also be used for other imports. So, we make a module name that
11
- # depends on the path for it to be unique using the hex-encoded hash of
12
- # the path.
13
- path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
14
- module_name = path_hash
15
- spec = importlib.util.spec_from_file_location(module_name, file_path)
16
- if spec is None:
17
- raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
18
- module = importlib.util.module_from_spec(spec)
19
- if module is None:
20
- raise ImportError(f"Cannot load module {module_name} from spec")
21
- sys.modules[module_name] = module
22
- spec.loader.exec_module(module) # type: ignore
23
- return module
24
-
25
-
26
- globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))