Skip to content

Commit acb75f3

Browse files
authored
Merge pull request #499 from InfiniTensor/issue/498
加入 `infinicore` Python 包的 editable 安装支持
2 parents 511aeb8 + 1ac3388 commit acb75f3

File tree

8 files changed

+31
-20
lines changed

8 files changed

+31
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Xmake cache
22
.xmake/
33
build/
4+
python/infinicore/lib/*.so
45

56
# MacOS Cache
67
.DS_Store

python/infinicore/device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from . import _infinicore
1+
from infinicore.lib import _infinicore
22

33

44
class device:

python/infinicore/dtype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from . import _infinicore
1+
from infinicore.lib import _infinicore
22

33

44
class dtype:

python/infinicore/ops/matmul.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
from infinicore.lib import _infinicore
12
from infinicore.tensor import Tensor
23

3-
from .. import _infinicore
4-
54

65
def matmul(input, other, *, out=None):
76
if out is None:

python/infinicore/ops/rearrange.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
from infinicore.lib import _infinicore
12
from infinicore.tensor import Tensor
23

3-
from .. import _infinicore
4-
54

65
def rearrange(input, other, *, out=None):
76
if out is None:

python/infinicore/tensor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import infinicore.device
22
import infinicore.dtype
3-
4-
from . import _infinicore
3+
from infinicore.lib import _infinicore
54

65

76
class Tensor:

setup.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import glob
2-
import os
3-
import shutil
41
import subprocess
5-
from pathlib import Path
62

73
from setuptools import setup
84
from setuptools.command.build import build
@@ -15,12 +11,5 @@ def run(self):
1511
subprocess.run(["xmake", "build", "-y", "_infinicore"])
1612
subprocess.run(["xmake", "install", "_infinicore"])
1713

18-
installation_dir = os.getenv("INFINI_ROOT", str(Path.home() / ".infini"))
19-
lib_dir = os.path.join(installation_dir, "lib")
20-
lib_path = glob.glob(os.path.join(lib_dir, "_infinicore.*"))[0]
21-
package_dir = os.path.join(self.build_lib, "infinicore")
22-
os.makedirs(package_dir, exist_ok=True)
23-
shutil.move(lib_path, package_dir)
24-
2514

2615
setup(package_dir={"": "python"}, cmdclass={"build": Build})

xmake.lua

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,31 @@ target("_infinicore")
347347
add_files("src/infinicore/op/*/*.cc")
348348
add_files("src/infinicore/pybind11/**.cc")
349349

350-
set_installdir(os.getenv("INFINI_ROOT") or (os.getenv(is_host("windows") and "HOMEPATH" or "HOME") .. "/.infini"))
350+
set_installdir("python/infinicore")
351+
target_end()
352+
353+
option("editable")
354+
set_default(false)
355+
set_showmenu(true)
356+
set_description("Install the `infinicore` Python package in editable mode")
357+
option_end()
358+
359+
target("infinicore")
360+
set_kind("phony")
361+
362+
set_default(false)
363+
364+
add_deps("_infinicore")
365+
366+
on_install(function (target)
367+
local pip_install_args = {}
368+
369+
if has_config("editable") then
370+
table.insert(pip_install_args, "--editable")
371+
end
372+
373+
os.execv("python", table.join({"-m", "pip", "install"}, pip_install_args, {"."}))
374+
end)
351375
target_end()
352376

353377
-- Tests

0 commit comments

Comments
 (0)