Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# on import, the `__path__` variable of the imported package is extended
# to include existing directories on the plugin search path (via
# extend_path, above). this means that `walk_packages` will walk over all
# modules on the search path at the same level (.e.g in a
# 'rezplugins/type_name' sub-directory).
paths = [package.__path__] if isinstance(package.__path__, basestring) \
else package.__path__
# reverse plugin path order, so that custom plugins have a chance to
# override the builtin plugins (from /rezplugins).
paths = reversed(paths)
for path in paths:
if config.debug("plugins"):
print_debug("searching plugin path %s...", path)
for loader, modname, ispkg in pkgutil.iter_modules(
[path], package.__name__ + '.'):
if loader is None:
continue
plugin_name = modname.split('.')[-1]
if plugin_name.startswith('_'):
continue
if config.debug("plugins"):
print_debug("loading %s plugin at %s: %s..."
% (self.type_name, path, modname))
try:
# load_module will force reload the module if it's
for path in paths:
if config.debug("plugins"):
print_debug("searching plugin path %s...", path)
for loader, modname, ispkg in pkgutil.iter_modules(
[path], package.__name__ + '.'):
if loader is None:
continue
plugin_name = modname.split('.')[-1]
if plugin_name.startswith('_'):
continue
if config.debug("plugins"):
print_debug("loading %s plugin at %s: %s..."
% (self.type_name, path, modname))
try:
# load_module will force reload the module if it's
# already loaded, so check for that
module = sys.modules.get(modname)
if module is None:
module = loader.find_module(modname).load_module(modname)
if hasattr(module, 'register_plugin') and \
hasattr(module.register_plugin, '__call__'):
plugin_class = module.register_plugin()
if plugin_class != None:
self.register_plugin(plugin_name, plugin_class, module)
else:
if config.debug("plugins"):
print_warning(
"'register_plugin' function at %s: %s did not return a class."
if self.settings.print_commands or config.debug("package_release"):
from subprocess import list2cmdline
toks = [program] + args
msgs = []
msgs.append("running command: %s" % list2cmdline(toks))
if env:
for key, value in env.iteritems():
msgs.append(" with: %s=%s" % (key, value))
if self.settings.print_commands:
print('\n'.join(msgs))
else:
for msg in msgs:
print_debug(msg)
if not self.execute_command(cmd_name=program,
cmd_arguments=args,
user=conf.get("user"),
errors=errors,
env=env_):
if self.settings.stop_on_error:
return
py_exe = find_python_in_context(context)
proc = context.execute_command(
# -E and -s are used to isolate the environment as much as possible.
# See python --help for more details. We absolutely don't want to get
# pip from the user home.
[py_exe, "-E", "-s", "-c", "import pip, sys; sys.stdout.write(pip.__version__)"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
out, err = proc.communicate()
if proc.returncode:
print_debug("Failed to get pip from package %s", target)
print_debug(out)
print_debug(err)
return None, None, None
pip_version = out.strip()
variant = context.get_resolved_package(target)
package = variant.parent
print_info(
"Found pip-%s inside %s. Will use it via %s",
pip_version,
package.uri,
py_exe
)
return py_exe, pip_version, context
py_exe = find_python_in_context(context)
proc = context.execute_command(
# -E and -s are used to isolate the environment as much as possible.
# See python --help for more details. We absolutely don't want to get
# pip from the user home.
[py_exe, "-E", "-s", "-c", "import pip, sys; sys.stdout.write(pip.__version__)"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
out, err = proc.communicate()
if proc.returncode:
print_debug("Failed to get pip from package %s", target)
print_debug(out)
print_debug(err)
return None, None, None
pip_version = out.strip()
variant = context.get_resolved_package(target)
package = variant.parent
print_info(
"Found pip-%s inside %s. Will use it via %s",
pip_version,
package.uri,
py_exe
)
return py_exe, pip_version, context
def log_append_pkg_variants(pkg_maker):
template = '{action} [{package.qualified_name}] {package.uri}{suffix}'
actions_variants = [
(
print_info, 'Installed',
installed_variants, pkg_maker.installed_variants or [],
),
(
print_debug, 'Skipped',
skipped_variants, pkg_maker.skipped_variants or [],
),
]
for print_, action, variants, pkg_variants in actions_variants:
for variant in pkg_variants:
variants.append(variant)
package = variant.parent
suffix = (' (%s)' % variant.subpath) if variant.subpath else ''
print_(template.format(**locals()))
def _log(msg):
if _verbose:
print_debug(msg)
return None, None, None
py_exe = find_python_in_context(context)
proc = context.execute_command(
# -E and -s are used to isolate the environment as much as possible.
# See python --help for more details. We absolutely don't want to get
# pip from the user home.
[py_exe, "-E", "-s", "-c", "import pip, sys; sys.stdout.write(pip.__version__)"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
out, err = proc.communicate()
if proc.returncode:
print_debug("Failed to get pip from package %s", target)
print_debug(out)
print_debug(err)
return None, None, None
pip_version = out.strip()
variant = context.get_resolved_package(target)
package = variant.parent
print_info(
"Found pip-%s inside %s. Will use it via %s",
pip_version,
package.uri,
py_exe
)
return py_exe, pip_version, context