forked from modular/mojo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_mod.py
41 lines (36 loc) · 1.42 KB
/
check_mod.py
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
# ===----------------------------------------------------------------------=== #
# Copyright (c) 2024, Modular Inc. All rights reserved.
#
# Licensed under the Apache License v2.0 with LLVM Exceptions:
# https://llvm.org/LICENSE.txt
#
# 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.
# ===----------------------------------------------------------------------=== #
import shutil
import subprocess
from importlib.util import find_spec
FIX = """
-------------------------------------------------------------------------
fix following the steps here:
https://github.com/modularml/mojo/issues/1085#issuecomment-1771403719
-------------------------------------------------------------------------
"""
def install_if_missing(name: str):
if find_spec(name):
return
print(f"{name} not found, installing...")
try:
if shutil.which("python3"):
python = "python3"
elif shutil.which("python"):
python = "python"
else:
raise ImportError("python not on path" + FIX)
subprocess.check_call([python, "-m", "pip", "install", name])
return
except:
raise ImportError(f"{name} not found" + FIX)