2016-07-20 16:32:01 +02:00
|
|
|
# ##### BEGIN GPL LICENSE BLOCK #####
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
#
|
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
|
|
|
|
2016-03-18 16:53:52 +01:00
|
|
|
"""External dependencies loader."""
|
|
|
|
|
|
|
|
import glob
|
|
|
|
import os.path
|
|
|
|
import sys
|
|
|
|
import logging
|
|
|
|
|
|
|
|
my_dir = os.path.join(os.path.dirname(__file__))
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def load_wheel(module_name, fname_prefix):
|
|
|
|
"""Loads a wheel from 'fname_prefix*.whl', unless the named module can be imported.
|
|
|
|
|
|
|
|
This allows us to use system-installed packages before falling back to the shipped wheels.
|
|
|
|
This is useful for development, less so for deployment.
|
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
|
|
|
module = __import__(module_name)
|
2016-05-18 11:57:32 +02:00
|
|
|
except ImportError as ex:
|
2021-02-16 11:21:06 +01:00
|
|
|
log.debug("Unable to import %s directly, will try wheel: %s", module_name, ex)
|
2016-03-18 16:53:52 +01:00
|
|
|
else:
|
2021-02-16 11:21:06 +01:00
|
|
|
log.debug(
|
|
|
|
"Was able to load %s from %s, no need to load wheel %s",
|
|
|
|
module_name,
|
|
|
|
module.__file__,
|
|
|
|
fname_prefix,
|
|
|
|
)
|
2016-03-18 16:53:52 +01:00
|
|
|
return
|
|
|
|
|
2017-06-22 14:43:12 +02:00
|
|
|
sys.path.append(wheel_filename(fname_prefix))
|
|
|
|
module = __import__(module_name)
|
2021-02-16 11:21:06 +01:00
|
|
|
log.debug("Loaded %s from %s", module_name, module.__file__)
|
2017-06-22 14:43:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
def wheel_filename(fname_prefix: str) -> str:
|
2021-02-16 11:21:06 +01:00
|
|
|
path_pattern = os.path.join(my_dir, "%s*.whl" % fname_prefix)
|
2016-03-18 16:53:52 +01:00
|
|
|
wheels = glob.glob(path_pattern)
|
|
|
|
if not wheels:
|
2021-02-16 11:21:06 +01:00
|
|
|
raise RuntimeError("Unable to find wheel at %r" % path_pattern)
|
2016-03-18 16:53:52 +01:00
|
|
|
|
2016-06-28 15:31:56 +02:00
|
|
|
# If there are multiple wheels that match, load the latest one.
|
|
|
|
wheels.sort()
|
2017-06-22 14:43:12 +02:00
|
|
|
return wheels[-1]
|
2016-03-18 16:53:52 +01:00
|
|
|
|
|
|
|
|
|
|
|
def load_wheels():
|
2021-02-16 11:21:06 +01:00
|
|
|
load_wheel("blender_asset_tracer", "blender_asset_tracer")
|
|
|
|
load_wheel("lockfile", "lockfile")
|
|
|
|
load_wheel("cachecontrol", "CacheControl")
|
|
|
|
load_wheel("pillarsdk", "pillarsdk")
|