Repository navigation
Expand file tree
/
Copy pathsetup.py
More file actions
89 lines (76 loc) · 3.9 KB
/
Copy pathsetup.py
File metadata and controls
89 lines (76 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Copyright 2026 Huawei Technologies Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""Package standalone Python sources and an explicitly built native payload."""
import json
import os
from pathlib import Path
import runpy
import shutil
import sys
from packaging.requirements import Requirement
from setuptools import Distribution, find_packages, setup
from setuptools.command.build_py import build_py
ROOT = Path(__file__).resolve().parent
BUILD_HELPERS = runpy.run_path(str(ROOT / "hyper_multicore/_build/artifacts.py"))
COMPONENT_VERSION = BUILD_HELPERS["COMPONENT_VERSION"]
payload = os.environ.get("HYPER_MULTICORE_NATIVE_OUTPUT_ROOT", "").strip()
info = (json.loads((Path(payload) / "build_info.json").read_text(encoding="utf-8"))
if payload and "sdist" not in sys.argv else None)
def get_install_requires() -> list[str]:
"""Read runtime requirements and pin Torch to an explicitly selected native build."""
requirements = [line.strip() for line in (ROOT / "requirements.txt").read_text(encoding="utf-8").splitlines()
if line.strip() and not line.strip().startswith("#")]
if info is not None:
requirements = [f"torch=={info['torch_version']}" if Requirement(value).name.lower() == "torch" else value
for value in requirements]
return requirements
class BuildPy(build_py):
"""Copy only a validated, explicitly selected native payload into a wheel."""
def run(self) -> None:
"""Reject release wheels without native files; permit editable Host development."""
if info is None and "editable_wheel" not in sys.argv:
raise RuntimeError("Native payload required for wheels; run bash build.sh. Use editable for Host UT.")
if info is not None:
BUILD_HELPERS["validate_payload"](Path(payload), info)
# Removed modules and native libraries must not survive an incremental wheel build.
package_build = Path(self.build_lib) / "hyper_multicore"
if package_build.exists():
shutil.rmtree(package_build)
super().run()
if info is not None:
shutil.copytree(payload, Path(self.build_lib) / "hyper_multicore", dirs_exist_ok=True)
class BinaryDistribution(Distribution):
"""Keep native wheel tags specific to the actual Python ABI and Host platform."""
def has_ext_modules(self) -> bool:
"""Return true because published wheels contain native extensions."""
return True
setup(
name="hyper-multicore",
version=info["artifact_version"] if info else COMPONENT_VERSION,
description="Huawei Ascend SuperNode Megakernel Development Framework Based on Heterogeneous Multi-Core Scheduling",
long_description=(ROOT / "README.md").read_text(encoding="utf-8"),
long_description_content_type="text/markdown",
url="https://github.com/mindspore-ai/hyper-multicore",
license="Apache-2.0",
license_files=["LICENSE", "Third_Party_Open_Source_Software_Notice"],
python_requires=">=3.10,<3.13",
packages=find_packages(include=["hyper_multicore", "hyper_multicore.*"]),
install_requires=get_install_requires(),
scripts=["scripts/hyper_multicore_set_env.bash"],
include_package_data=False,
package_data={"hyper_multicore": ["ops/runtime/*.h", "ops/runtime/*.hpp"]},
cmdclass={"build_py": BuildPy},
distclass=BinaryDistribution,
)