in source/neuropod/backends/python_bridge/_neuropod_native_bootstrap/pip_utils.py [0:0]
def _load_deps_internal(lockfile_contents):
"""
See `load_deps` above for details
"""
print(
"Neuropod Info: Installing python packages required by the current model. "
"If this takes a long time, set NEUROPOD_LOG_PY_DEPS to log all dependencies of the model "
"and consider preinstalling large dependencies using `neuropod.backends.python.utils.preinstall_deps`"
)
requirements = []
for line in lockfile_contents.splitlines():
# Remove comments
pos = line.find("#")
if pos != -1:
line = line[:pos]
# Remove surrounding whitespace
line = line.strip()
if not line:
continue
# Anything else must be of the form name==version or we error
parts = line.split("==")
if len(parts) != 2:
raise ValueError(
"Expected requirements of the form name==version but got {}".format(
line
)
)
# Add it to our list of requirements
requirements.append(line.lower())
# Create our package base dir if necessary
create_if_not_exists(PACKAGE_BASE_DIR)
for requirement in requirements:
req_path = os.path.abspath(os.path.join(PACKAGE_BASE_DIR, requirement))
# Sanity check to guard against bad input
if not req_path.startswith(PACKAGE_BASE_DIR):
raise ValueError("Invalid dependency: {}".format(requirement))
# Check if we need to install the package
if not os.path.exists(req_path + ".complete"):
if LOG_PY_DEPS:
print("[Neuropod] Installing python package required by model: {}...".format(requirement))
# Acquire a lock
# TODO(vip): it's possible that this'll conflict with a package if the version ends in `.lock`
lock = FileLock(req_path + ".lock")
with lock:
# Check again if we need to install the package
# (maybe another process installed it before we got the lock)
if not os.path.exists(req_path + ".complete"):
# Install
install_package(requirement, req_path)
# Mark the installation as complete
open(req_path + ".complete", "a").close()
else:
if LOG_PY_DEPS:
print("[Neuropod] Python package required by model already installed: {}...".format(requirement))
# Add this package to the pythonpath
sys.path.insert(
0, glob.glob("{}/lib/python*/site-packages".format(req_path))[0]
)