Skip to content

Commit f2be07b

Browse files
PaliCfacebook-github-bot
authored andcommitted
change install options to use env variables (#323)
Summary: Pull Request resolved: #323 Test Plan: Imported from OSS Should build in CI Reviewed By: malfet, huydhn Differential Revision: D46771967 Pulled By: PaliC fbshipit-source-id: 02ddaf4e7a950b45d25adca996a430b2cbbcadaf
1 parent 45c9b82 commit f2be07b

File tree

7 files changed

+33
-91
lines changed

7 files changed

+33
-91
lines changed

.github/workflows/build_test_release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
echo "::endgroup::"
6262
6363
echo "::group::Install"
64-
python -m pip install -e . --install-option="--cudatests"
64+
BUILD_CUDA_TESTS=1 python -m pip install -e .
6565
echo "::endgroup::"
6666
6767
echo "::group::Generate examples"

.github/workflows/install_test.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
steps:
2222
- name: Set Python Version
2323
run: |
24-
echo "python-version=3.${{ matrix.python3-minor-version }}" >> $GITHUB_ENV
24+
echo "python-version=3.${{ matrix.python3-minor-version }}" >> "$GITHUB_ENV"
2525
- name: Setup Python ${{ env.python-version }}
2626
uses: actions/setup-python@v2
2727
with:
@@ -66,38 +66,38 @@ jobs:
6666
- name: Install dependencies
6767
run: |
6868
set -eux
69-
source ~/venvs/multipy/bin/activate
70-
pip install -r dev-requirements.txt
69+
source "$HOME/venvs/multipy/bin/activate"
70+
python -m pip install -r dev-requirements.txt
7171
pip3 install --pre torch
7272
deactivate
7373
7474
- name: Run lightweight pip install within virtualenv
7575
run: |
7676
set -eux
77-
source ~/venvs/multipy/bin/activate
78-
pip install -e . --install-option="--cmakeoff"
77+
source "$HOME/venvs/multipy/bin/activate"
78+
INSTALL_PYTHON_ONLY=1 python -m pip install -e .
7979
deactivate
8080
8181
- name: Run pip editable install within virtualenv
8282
run: |
8383
set -eux
84-
source ~/venvs/multipy/bin/activate
84+
source "$HOME/venvs/multipy/bin/activate"
8585
rm -rf multipy/runtime/build*
8686
pip install -e .
8787
deactivate
8888
8989
- name: Run setup.py install within virtualenv
9090
run: |
9191
set -eux
92-
source ~/venvs/multipy/bin/activate
92+
source "$HOME/venvs/multipy/bin/activate"
9393
python setup.py install
9494
test -e ~/venvs/multipy/lib/python3.${{ matrix.python3-minor-version }}/site-packages/multipy/runtime/build/libtorch_deploy.a
9595
deactivate
9696
9797
- name: Install sdist
9898
run: |
9999
set -eux
100-
source ~/venvs/multipy/bin/activate
100+
source "$HOME/venvs/multipy/bin/activate"
101101
python setup.py sdist
102102
pip install dist/*.tar.gz --force-reinstall
103103
test -e ~/venvs/multipy/lib/python3.${{ matrix.python3-minor-version }}/site-packages/multipy/runtime/build/libtorch_deploy.a
@@ -106,18 +106,18 @@ jobs:
106106
- name: Install bdist_wheel
107107
run: |
108108
set -eux
109-
source ~/venvs/multipy/bin/activate
109+
source "$HOME/venvs/multipy/bin/activate"
110110
python setup.py bdist_wheel
111111
pip install dist/*.whl --force-reinstall
112112
test -e ~/venvs/multipy/lib/python3.${{ matrix.python3-minor-version }}/site-packages/multipy/runtime/build/libtorch_deploy.a
113113
deactivate
114114
115-
- name: Install bdist_wheel with cudatests
115+
- name: Install bdist_wheel with cuda tests
116116
run: |
117117
set -eux
118-
source ~/venvs/multipy/bin/activate
118+
source "$HOME/venvs/multipy/bin/activate"
119119
python setup.py bdist_wheel
120-
pip install dist/*.whl --force-reinstall --install-option="--cudatests"
120+
BUILD_CUDA_TESTS=1 pip install dist/*.whl "--force-reinstall"
121121
test -e ~/venvs/multipy/lib/python3.${{ matrix.python3-minor-version }}/site-packages/multipy/runtime/build/libtorch_deploy.a
122122
deactivate
123123

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ RUN ls && pwd && rm -rf multipy/runtime/build && \
102102
source ~/venvs/multipy/bin/activate; \
103103
fi && \
104104
if [[ ${BUILD_CUDA_TESTS} -eq 1 ]]; then \
105-
python -m pip install -e . --install-option="--cudatests"; \
105+
BUILD_CUDA_TESTS=1 python -m pip install -e .; \
106106
else \
107107
python -m pip install -e .; \
108108
fi && \

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ The C++ binaries should be available in `/opt/dist`.
140140

141141
Alternatively, one can install only the python modules without invoking `cmake` as follows:
142142
```shell
143-
pip install -e . --install-option="--cmakeoff"
143+
INSTALL_PYTHON_ONLY=1 pip install -e .
144144
```
145145

146146
> **NOTE** As of 10/11/2022 the linking of prebuilt static fPIC versions of python downloaded from `conda-forge` can be problematic on certain systems (for example Centos 8), with linker errors like `libpython_multipy.a: error adding symbols: File format not recognized`. This seems to be an issue with `binutils`, and the steps in https://wiki.gentoo.org/wiki/Project:Toolchain/Binutils_2.32_upgrade_notes/elfutils_0.175:_unable_to_initialize_decompress_status_for_section_.debug_info can help. Alternatively, the user can go with the `virtualenv`/`pyenv` flow above.
@@ -164,7 +164,7 @@ cd multipy
164164
git submodule sync && git submodule update --init --recursive
165165

166166
# install python parts of `torch::deploy` in multipy/multipy/utils
167-
pip install -e . --install-option="--cmakeoff"
167+
INSTALL_PYTHON_ONLY=1 pip install -e .
168168

169169
cd multipy/runtime
170170

docs/source/setup.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Alternatively, one can install only the python modules without invoking
132132
.. code:: shell
133133
134134
# from base multipy directory
135-
pip install -e . --install-option="--cmakeoff"
135+
INSTALL_PYTHON_ONLY=1 pip install -e .
136136
137137
.. warning::
138138
As of 10/11/2022 the linking of prebuilt static ``-fPIC``
@@ -164,7 +164,7 @@ Building
164164
165165
cd multipy
166166
# install python parts of `torch::deploy` in multipy/multipy/utils
167-
pip install -e . --install-option="--cmakeoff"
167+
INSTALL_PYTHON_ONLY=1 pip install -e .
168168
169169
cd multipy/runtime
170170

multipy/runtime/interpreter/interpreter_impl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <torch/csrc/DynamicTypes.h>
2222
#include <torch/csrc/autograd/generated/variable_factories.h>
2323
#include <torch/csrc/jit/frontend/tracer.h>
24+
#include <torch/csrc/utils/pybind.h>
2425
#include <cassert>
2526
#include <cstdio>
2627
#include <iostream>

setup.py

Lines changed: 14 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
# This source code is licensed under the BSD-style license found in the
66
# LICENSE file in the root directory of this source tree.
77

8+
9+
# Environment variables you are probably interested in:
10+
#
11+
# BUILD_CUDA_TESTS=0
12+
# Build cuda tests
13+
#
14+
# INSTALL_PYTHON_ONLY=0
15+
# install only the python parts of multipy
16+
#
17+
818
import os
919
import os.path
1020
import re
@@ -16,8 +26,6 @@
1626

1727
from setuptools import Extension, find_packages, setup
1828
from setuptools.command.build_ext import build_ext
19-
from setuptools.command.develop import develop
20-
from setuptools.command.install import install
2129

2230

2331
class MultipyRuntimeExtension(Extension):
@@ -30,34 +38,9 @@ def get_cmake_version():
3038
return output.splitlines()[0].split()[2]
3139

3240

33-
class MultipyRuntimeCmake(object):
34-
user_options = [
35-
("cmakeoff", None, None),
36-
("cudatests", None, None),
37-
]
38-
39-
40-
class MultipyRuntimeDevelop(MultipyRuntimeCmake, develop):
41-
user_options = develop.user_options + MultipyRuntimeCmake.user_options
42-
43-
def initialize_options(self):
44-
develop.initialize_options(self)
45-
self.cmakeoff = None
46-
47-
self.cudatests = None
48-
49-
def finalize_options(self):
50-
develop.finalize_options(self)
51-
if self.cmakeoff is not None:
52-
self.distribution.get_command_obj("build_ext").cmake_off = True
53-
if self.cudatests is not None:
54-
self.distribution.get_command_obj("build_ext").cuda_tests_flag = "ON"
55-
56-
57-
class MultipyRuntimeBuild(MultipyRuntimeCmake, build_ext):
58-
user_options = build_ext.user_options + MultipyRuntimeCmake.user_options
59-
cmake_off = False
60-
cuda_tests_flag = "OFF"
41+
class MultipyRuntimeBuild(build_ext):
42+
cmake_off = os.environ.get("INSTALL_PYTHON_ONLY", 0)
43+
cuda_tests_flag = os.environ.get("BUILD_CUDA_TESTS", 0)
6144

6245
def run(self):
6346
if self.cmake_off:
@@ -145,44 +128,6 @@ def run(self):
145128
super().run()
146129

147130

148-
class MultipyRuntimeInstall(MultipyRuntimeCmake, install):
149-
user_options = install.user_options + MultipyRuntimeCmake.user_options
150-
151-
def initialize_options(self):
152-
install.initialize_options(self)
153-
self.cmakeoff = None
154-
self.cudatests = None
155-
156-
def finalize_options(self):
157-
install.finalize_options(self)
158-
if self.cmakeoff is not None:
159-
self.distribution.get_command_obj("build_ext").cmake_off = True
160-
if self.cudatests is not None:
161-
self.distribution.get_command_obj("build_ext").cuda_tests_flag = "ON"
162-
163-
def run(self):
164-
# Setuptools/setup.py on docker image has some interesting behavior, in that the
165-
# optional "--cmakeoff" flag gets applied to dependencies specified in
166-
# requirements.txt as well (installed using "install-requires" argument of setup()).
167-
# Since we obviously don't want things like "pip install numpy --install-option=--cmakeoff",
168-
# we install these deps directly in this overridden install command without
169-
# spurious options, instead of using "install-requires".
170-
base_dir = os.path.abspath(os.path.dirname(__file__))
171-
try:
172-
reqs_filename = "requirements.txt"
173-
subprocess.run(
174-
[f"pip install -r {reqs_filename}"],
175-
cwd=base_dir,
176-
shell=True,
177-
check=True,
178-
stdout=subprocess.PIPE,
179-
stderr=subprocess.STDOUT,
180-
)
181-
except subprocess.CalledProcessError as e:
182-
raise RuntimeError(e.output.decode("utf-8")) from None
183-
install.run(self)
184-
185-
186131
ext_modules = [
187132
MultipyRuntimeExtension("multipy.so"),
188133
]
@@ -206,15 +151,13 @@ def get_nightly_version():
206151
if __name__ == "__main__":
207152
if sys.version_info < (3, 7):
208153
sys.exit("python >= 3.7 required for multipy")
209-
210154
name = "torchdeploy"
211155
NAME_ARG = "--override-name"
212156
if NAME_ARG in sys.argv:
213157
idx = sys.argv.index(NAME_ARG)
214158
name = sys.argv.pop(idx + 1)
215159
sys.argv.pop(idx)
216160
is_nightly = "nightly" in name
217-
218161
with open("README.md", encoding="utf8") as f:
219162
readme = f.read()
220163

@@ -230,7 +173,7 @@ def get_nightly_version():
230173
version=version,
231174
author="MultiPy Devs",
232175
# TODO: @sahanp create email for MultiPy
233-
author_email="sahanp@fb.com",
176+
author_email="sahanp@meta.com",
234177
description="torch::deploy (multipy) is a C++ library that makes it easier to run eager PyTorch models in production by using independent python interpreters to avoid the GIL.",
235178
long_description=readme,
236179
long_description_content_type="text/markdown",
@@ -251,8 +194,6 @@ def get_nightly_version():
251194
ext_modules=ext_modules,
252195
cmdclass={
253196
"build_ext": MultipyRuntimeBuild,
254-
"develop": MultipyRuntimeDevelop,
255-
"install": MultipyRuntimeInstall,
256197
"clean": MultipyRuntimeClean,
257198
},
258199
package_data={

0 commit comments

Comments
 (0)