Skip to content

Commit 1439c58

Browse files
d4l3kfacebook-github-bot
authored andcommitted
multipy/setup.py: make whl/sdist builds installable w/ C++ build (#238)
Summary: This makes the whl/sdist builds include the C++ artifacts. This will enable us to upload the released version to pypi. Pull Request resolved: #238 Test Plan: ``` python setup.py clean sdist bdist_wheel pip install dist/multipy-0.1.0.dev0-cp38-cp38-linux_x86_64.whl pip install dist/multipy-0.1.0.dev0.tar.gz # check presence ~/venvs/multipy3.8.6/lib/python3.8/site-packages/multipy/runtime/build/interactive_embedded_interpreter ``` Reviewed By: PaliC Differential Revision: D40781426 Pulled By: d4l3k fbshipit-source-id: 42e881fcd72705a36af0c7e30c75543664a264bb
1 parent 64963c1 commit 1439c58

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed

.github/workflows/install_test.yaml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
workflow_dispatch:
1212

1313
jobs:
14-
unittest:
14+
installtest:
1515
strategy:
1616
matrix:
1717
python3-minor-version: [7,8,9,10]
@@ -76,14 +76,37 @@ jobs:
7676
pip install -e . --install-option="--cmakeoff"
7777
deactivate
7878
79-
- name: Run pip install within virtualenv
79+
- name: Run pip editable install within virtualenv
8080
run: |
8181
set -eux
8282
source ~/venvs/multipy/bin/activate
8383
rm -rf multipy/runtime/build*
8484
pip install -e .
8585
deactivate
8686
87+
- name: Run setup.py install within virtualenv
88+
run: |
89+
set -eux
90+
source ~/venvs/multipy/bin/activate
91+
python setup.py install
92+
test -e ~/venvs/multipy/lib/python3.*/site-packages/multipy/runtime/build/libtorch_deploy.a
93+
94+
- name: Install sdist
95+
run: |
96+
set -eux
97+
source ~/venvs/multipy/bin/activate
98+
python setup.py sdist
99+
pip install dist/*.tar.gz --force-reinstall
100+
test -e ~/venvs/multipy/lib/python3.*/site-packages/multipy/runtime/build/libtorch_deploy.a
101+
102+
- name: Install bdist_wheel
103+
run: |
104+
set -eux
105+
source ~/venvs/multipy/bin/activate
106+
python setup.py bdist_wheel
107+
pip install dist/*.whl --force-reinstall
108+
test -e ~/venvs/multipy/lib/python3.*/site-packages/multipy/runtime/build/libtorch_deploy.a
109+
87110
- name: Install dependencies with conda for 3.8+
88111
run: |
89112
set -eux

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ examples/**/*.pt
1111
**/.DS_Store/**
1212
docs/source/api/
1313
docs/src/
14+
dist/

setup.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
# LICENSE file in the root directory of this source tree.
77

88
import os
9+
import os.path
910
import re
11+
import shutil
1012
import subprocess
1113
import sys
1214
from datetime import date
15+
from distutils.command.clean import clean
1316

1417
from setuptools import Extension, find_packages, setup
1518
from setuptools.command.build_ext import build_ext
@@ -79,6 +82,7 @@ def run(self):
7982
if not os.path.exists(build_dir_abs):
8083
os.makedirs(build_dir_abs)
8184

85+
print(f"build_lib {self.build_lib}")
8286
print(f"-- Running multipy runtime makefile in dir {build_dir_abs}")
8387
try:
8488
subprocess.run(
@@ -118,6 +122,33 @@ def run(self):
118122
except subprocess.CalledProcessError as e:
119123
raise RuntimeError(e.output.decode("utf-8")) from None
120124

125+
print("-- Copying build outputs")
126+
paths = [
127+
"multipy/runtime/build/libtorch_deploy.a",
128+
"multipy/runtime/build/interactive_embedded_interpreter",
129+
"multipy/runtime/build/test_deploy",
130+
]
131+
for path in paths:
132+
target = os.path.join(self.build_lib, path)
133+
target_dir = os.path.dirname(target)
134+
if not os.path.exists(target_dir):
135+
print(f"creating dir {target_dir}")
136+
os.makedirs(target_dir)
137+
print(f"copying {path} -> {target}")
138+
shutil.copy2(path, target)
139+
140+
141+
class MultipyRuntimeClean(clean):
142+
def run(self):
143+
paths = [
144+
"multipy/runtime/build",
145+
]
146+
for path in paths:
147+
if os.path.exists(path):
148+
print(f"removing: {path}")
149+
shutil.rmtree(path)
150+
super().run()
151+
121152

122153
class MultipyRuntimeInstall(MultipyRuntimeCmake, install):
123154
user_options = install.user_options + MultipyRuntimeCmake.user_options
@@ -224,7 +255,29 @@ def get_nightly_version():
224255
"build_ext": MultipyRuntimeBuild,
225256
"develop": MultipyRuntimeDevelop,
226257
"install": MultipyRuntimeInstall,
258+
"clean": MultipyRuntimeClean,
259+
},
260+
package_data={
261+
"multipy": [
262+
"runtime/*",
263+
"runtime/example/*",
264+
"runtime/example/fx/*",
265+
"runtime/interpreter/*",
266+
"runtime/third-party/fmt/*",
267+
"runtime/third-party/fmt/include/fmt/*",
268+
"runtime/third-party/fmt/src/*",
269+
"runtime/third-party/fmt/support/cmake/*",
270+
]
227271
},
272+
data_files=[
273+
(
274+
"",
275+
[
276+
"requirements.txt",
277+
"dev-requirements.txt",
278+
],
279+
)
280+
],
228281
# PyPI package information.
229282
classifiers=[
230283
"Development Status :: 4 - Beta",

0 commit comments

Comments
 (0)