Skip to content

Commit 8a41427

Browse files
committed
Revert "Add install_requirements.{sh,py} that only install requirements (#7715)"
This reverts commit cd0e584.
1 parent 565dc28 commit 8a41427

File tree

5 files changed

+137
-197
lines changed

5 files changed

+137
-197
lines changed

install_executorch.py

Lines changed: 121 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,59 @@
1010
import glob
1111
import itertools
1212
import os
13+
import platform
14+
import re
1315
import shutil
1416
import subprocess
1517
import sys
1618

17-
from install_requirements import (
18-
install_requirements,
19-
python_is_compatible,
20-
TORCH_NIGHTLY_URL,
21-
)
19+
# Before doing anything, cd to the directory containing this script.
20+
os.chdir(os.path.dirname(os.path.abspath(__file__)))
21+
22+
23+
def python_is_compatible():
24+
# Scrape the version range from pyproject.toml, which should be in the current directory.
25+
version_specifier = None
26+
with open("pyproject.toml", "r") as file:
27+
for line in file:
28+
if line.startswith("requires-python"):
29+
match = re.search(r'"([^"]*)"', line)
30+
if match:
31+
version_specifier = match.group(1)
32+
break
33+
34+
if not version_specifier:
35+
print(
36+
"WARNING: Skipping python version check: version range not found",
37+
file=sys.stderr,
38+
)
39+
return False
40+
41+
# Install the packaging module if necessary.
42+
try:
43+
import packaging
44+
except ImportError:
45+
subprocess.run(
46+
[sys.executable, "-m", "pip", "install", "packaging"], check=True
47+
)
48+
# Compare the current python version to the range in version_specifier. Exits
49+
# with status 1 if the version is not compatible, or with status 0 if the
50+
# version is compatible or the logic itself fails.
51+
try:
52+
import packaging.specifiers
53+
import packaging.version
54+
55+
python_version = packaging.version.parse(platform.python_version())
56+
version_range = packaging.specifiers.SpecifierSet(version_specifier)
57+
if python_version not in version_range:
58+
print(
59+
f'ERROR: ExecuTorch does not support python version {python_version}: must satisfy "{version_specifier}"',
60+
file=sys.stderr,
61+
)
62+
return False
63+
except Exception as e:
64+
print(f"WARNING: Skipping python version check: {e}", file=sys.stderr)
65+
return True
2266

2367

2468
def clean():
@@ -35,6 +79,78 @@ def clean():
3579
VALID_PYBINDS = ["coreml", "mps", "xnnpack"]
3680

3781

82+
# The pip repository that hosts nightly torch packages.
83+
TORCH_NIGHTLY_URL = "https://download.pytorch.org/whl/nightly/cpu"
84+
85+
86+
# Since ExecuTorch often uses main-branch features of pytorch, only the nightly
87+
# pip versions will have the required features.
88+
#
89+
# NOTE: If a newly-fetched version of the executorch repo changes the value of
90+
# NIGHTLY_VERSION, you should re-run this script to install the necessary
91+
# package versions.
92+
NIGHTLY_VERSION = "dev20250104"
93+
94+
95+
def install_requirements(use_pytorch_nightly):
96+
# pip packages needed by exir.
97+
EXIR_REQUIREMENTS = [
98+
# Setting use_pytorch_nightly to false to test the pinned PyTorch commit. Note
99+
# that we don't need to set any version number there because they have already
100+
# been installed on CI before this step, so pip won't reinstall them
101+
f"torch==2.6.0.{NIGHTLY_VERSION}" if use_pytorch_nightly else "torch",
102+
(
103+
f"torchvision==0.22.0.{NIGHTLY_VERSION}"
104+
if use_pytorch_nightly
105+
else "torchvision"
106+
), # For testing.
107+
]
108+
109+
EXAMPLES_REQUIREMENTS = [
110+
f"torchaudio==2.6.0.{NIGHTLY_VERSION}" if use_pytorch_nightly else "torchaudio",
111+
]
112+
113+
# Assemble the list of requirements to actually install.
114+
# TODO: Add options for reducing the number of requirements.
115+
REQUIREMENTS_TO_INSTALL = EXIR_REQUIREMENTS + EXAMPLES_REQUIREMENTS
116+
117+
# Install the requirements. `--extra-index-url` tells pip to look for package
118+
# versions on the provided URL if they aren't available on the default URL.
119+
subprocess.run(
120+
[
121+
sys.executable,
122+
"-m",
123+
"pip",
124+
"install",
125+
"-r",
126+
"requirements-examples.txt",
127+
*REQUIREMENTS_TO_INSTALL,
128+
"--extra-index-url",
129+
TORCH_NIGHTLY_URL,
130+
],
131+
check=True,
132+
)
133+
134+
LOCAL_REQUIREMENTS = [
135+
"third-party/ao", # We need the latest kernels for fast iteration, so not relying on pypi.
136+
]
137+
138+
# Install packages directly from local copy instead of pypi.
139+
# This is usually not recommended.
140+
subprocess.run(
141+
[
142+
sys.executable,
143+
"-m",
144+
"pip",
145+
"install",
146+
# Without --no-build-isolation, setup.py can't find the torch module.
147+
"--no-build-isolation",
148+
*LOCAL_REQUIREMENTS,
149+
],
150+
check=True,
151+
)
152+
153+
38154
def main(args):
39155
if not python_is_compatible():
40156
sys.exit(1)
@@ -136,9 +252,4 @@ def main(args):
136252

137253

138254
if __name__ == "__main__":
139-
# Before doing anything, cd to the directory containing this script.
140-
os.chdir(os.path.dirname(os.path.abspath(__file__)))
141-
if not python_is_compatible():
142-
sys.exit(1)
143-
144255
main(sys.argv[1:])

install_executorch.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,19 @@
77

88
# Before doing anything, cd to the directory containing this script.
99
cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null || /bin/true
10-
./run_python_script.sh ./install_executorch.py "$@"
10+
11+
# Find the names of the python tools to use.
12+
if [[ -z $PYTHON_EXECUTABLE ]];
13+
then
14+
if [[ -z $CONDA_DEFAULT_ENV ]] || [[ $CONDA_DEFAULT_ENV == "base" ]] || [[ ! -x "$(command -v python)" ]];
15+
then
16+
PYTHON_EXECUTABLE=python3
17+
else
18+
PYTHON_EXECUTABLE=python
19+
fi
20+
fi
21+
22+
$PYTHON_EXECUTABLE ./install_executorch.py "$@"
23+
24+
# Exit with the same status as the python script.
25+
exit $?

install_requirements.py

Lines changed: 0 additions & 150 deletions
This file was deleted.

install_requirements.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

run_python_script.sh

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)