本文整理汇总了Python中rez.resolved_context.ResolvedContext类的典型用法代码示例。如果您正苦于以下问题:Python ResolvedContext类的具体用法?Python ResolvedContext怎么用?Python ResolvedContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResolvedContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _test_package
def _test_package(self, pkg, env, expected_commands):
orig_environ = os.environ.copy()
r = ResolvedContext([str(pkg)], caching=False)
# this environ should not have changed
self.assertEqual(orig_environ, os.environ)
commands = r.get_actions(parent_environ=env)
commands_ = []
# ignore some commands that don't matter or change depending on system
ignore_keys = set(["REZ_USED",
"REZ_USED_VERSION",
"REZ_USED_TIMESTAMP",
"REZ_USED_REQUESTED_TIMESTAMP",
"REZ_USED_PACKAGES_PATH",
"REZ_USED_IMPLICIT_PACKAGES",
"PATH"])
for cmd in commands:
if isinstance(cmd, (Comment, Shebang)):
continue
elif isinstance(cmd, EnvAction) and cmd.key in ignore_keys:
continue
else:
commands_.append(cmd)
self.assertEqual(commands_, expected_commands)
开发者ID:rvsiy,项目名称:rez,代码行数:27,代码来源:test_commands.py
示例2: create_build_context
def create_build_context(self, variant, build_type, build_path):
"""Create a context to build the variant within."""
request = variant.get_requires(build_requires=True,
private_build_requires=True)
requests_str = ' '.join(map(str, request))
self._print("Resolving build environment: %s", requests_str)
if build_type == BuildType.local:
packages_path = self.package.config.packages_path
else:
packages_path = self.package.config.nonlocal_packages_path
context = ResolvedContext(request,
package_paths=packages_path,
building=True)
if self.verbose:
context.print_info()
# save context before possible fail, so user can debug
rxt_filepath = os.path.join(build_path, "build.rxt")
context.save(rxt_filepath)
if context.status != ResolverStatus.solved:
raise BuildContextResolveError(context)
return context, rxt_filepath
开发者ID:rvsiy,项目名称:rez,代码行数:25,代码来源:build_process_.py
示例3: test_8
def test_8(self):
"""Ensure that include modules are copied."""
self._reset_dest_repository()
src_pkg = self._get_src_pkg("foo", "1.1.0")
copy_package(
package=src_pkg,
dest_repository=self.dest_install_root,
)
dest_pkg = self._get_dest_pkg("foo", "1.1.0")
dest_variant = dest_pkg.iter_variants().next()
# do a resolve
ctxt = ResolvedContext(
["foo==1.1.0"],
package_paths=[self.dest_install_root, self.install_root]
)
resolved_variant = ctxt.get_resolved_package("foo")
self.assertEqual(dest_variant.handle, resolved_variant.handle)
# this can only match if the include module was copied with the package
environ = ctxt.get_environ(parent_environ={})
self.assertEqual(environ.get("EEK"), "2")
开发者ID:mottosso,项目名称:rez,代码行数:25,代码来源:test_copy_package.py
示例4: run_rez_shell
def run_rez_shell(command, rez_pkg, weight=False):
"""Runs provided command inside rez-resolved shell.
Args:
command (str): custom command
Returns:
pid: Process object of subshell.
Note: pid runs in separate process and needs to be waited with wait()
command outside this function, if commad takes time.
"""
if not REZ_FOUND:
print "Can't execute command in rez configured subshell."
print "No rez package found! (does $REZ_CONFIG_FILE exist?) "
return False
from rez.resolved_context import ResolvedContext
if not command:
return self.EmtyProcess()
context = ResolvedContext(rez_pkg)
rez_pid = context.execute_command(command)
return rez_pid
开发者ID:symek,项目名称:harm-sge,代码行数:25,代码来源:utilities.py
示例5: spawnRezManagedCommandWatcher
def spawnRezManagedCommandWatcher(pidfile, logfile, args, watcherPackages, env):
"""
| Uses rez module to start a process with a proper rez env.
:param pidfile: full path to the comand pid file (usally /var/run/puli/cw<command_id>.pid)
:param logfile: file object to store process log content
:param args: arguments passed to the CommandWatcher script
:param watcherPackages: A list of packages that will be resolved when creating Rez context
:param env: a dict holding key/value pairs that will be merged into the current env and used in subprocess
:return: a CommandWatcherProcess object holding command watcher process handle
"""
try:
from rez.resources import clear_caches
from rez.resolved_context import ResolvedContext
from rez.resolver import ResolverStatus
except ImportError as e:
LOGGER.error("Unable to load rez package in a rez managed environment.")
raise e
try:
if watcherPackages is None:
LOGGER.warning("No package specified for this command, it might not find the runner for this command.")
watcherPackagesList = []
elif type(watcherPackages) in [str, unicode]:
watcherPackagesList = watcherPackages.split()
else:
watcherPackagesList = watcherPackages
clear_caches()
context = ResolvedContext(watcherPackagesList)
success = (context.status == ResolverStatus.solved)
if not success:
context.print_info(buf=sys.stderr)
raise
# normalize environment
# JSA do not transmit env (eg PYTHONHOME) to command watcher
# envN = os.environ.copy()
envN = {}
for key in env:
envN[str(key)] = str(env[key])
proc = context.execute_shell(
command=args,
shell='bash',
stdin=False,
stdout=logfile,
stderr=subprocess.STDOUT,
block=False,
parent_environ=envN
)
LOGGER.info("Starting subprocess, log: %r, args: %r" % (logfile.name, args))
except Exception as e:
LOGGER.error("Impossible to start process: %s" % e)
raise e
file(pidfile, "w").write(str(proc.pid))
return CommandWatcherProcess(proc, pidfile, proc.pid)
开发者ID:Alayad,项目名称:OpenRenderManagement,代码行数:60,代码来源:process.py
示例6: resolve_context
def resolve_context(self, verbosity=0, max_fails=-1, timestamp=None,
callback=None, buf=None, package_load_callback=None):
"""Update the current context by performing a re-resolve.
The newly resolved context is only applied if it is a successful solve.
Returns:
`ResolvedContext` object, which may be a successful or failed solve.
"""
package_filter = PackageFilterList.from_pod(self.package_filter)
context = ResolvedContext(
self.request,
package_paths=self.packages_path,
package_filter=package_filter,
verbosity=verbosity,
max_fails=max_fails,
timestamp=timestamp,
buf=buf,
callback=callback,
package_load_callback=package_load_callback)
if context.success:
if self._context and self._context.load_path:
context.set_load_path(self._context.load_path)
self._set_context(context)
self._modified = True
return context
开发者ID:rvsiy,项目名称:rez,代码行数:28,代码来源:ContextModel.py
示例7: test_serialize
def test_serialize(self):
"""Test save/load of context."""
# save
file = os.path.join(self.root, "test.rxt")
r = ResolvedContext(["hello_world"])
r.save(file)
# load
r2 = ResolvedContext.load(file)
self.assertEqual(r.resolved_packages, r2.resolved_packages)
开发者ID:rvsiy,项目名称:rez,代码行数:9,代码来源:test_context.py
示例8: test_execute_command
def test_execute_command(self):
"""Test command execution in context."""
if platform_.name == "windows":
self.skipTest("This test does not run on Windows due to problems"
" with the automated binding of the 'hello_world'"
" executable.")
r = ResolvedContext(["hello_world"])
p = r.execute_command(["hello_world"], stdout=subprocess.PIPE)
stdout, _ = p.communicate()
stdout = stdout.strip()
self.assertEqual(stdout, "Hello Rez World!")
开发者ID:rvsiy,项目名称:rez,代码行数:12,代码来源:test_context.py
示例9: create_context
def create_context(pip_version=None, python_version=None):
"""Create a context containing the specific pip and python.
Args:
pip_version (str or `Version`): Version of pip to use, or latest if None.
python_version (str or `Version`): Python version to use, or latest if
None.
Returns:
`ResolvedContext`: Context containing pip and python.
"""
# determine pip pkg to use for install, and python variants to install on
if pip_version:
pip_req = "pip-%s" % str(pip_version)
else:
pip_req = "pip"
if python_version:
ver = Version(str(python_version))
major_minor_ver = ver.trim(2)
py_req = "python-%s" % str(major_minor_ver)
else:
# use latest major.minor
package = get_latest_package("python")
if package:
major_minor_ver = package.version.trim(2)
else:
# no python package. We're gonna fail, let's just choose current
# python version (and fail at context creation time)
major_minor_ver = ".".join(map(str, sys.version_info[:2]))
py_req = "python-%s" % str(major_minor_ver)
# use pip + latest python to perform pip download operations
request = [pip_req, py_req]
with convert_errors(
from_=(PackageFamilyNotFoundError, PackageNotFoundError),
to=BuildError,
msg="Cannot run - pip or python rez " "package is not present",
):
context = ResolvedContext(request)
# print pip package used to perform the install
pip_variant = context.get_resolved_package("pip")
pip_package = pip_variant.parent
print_info("Using %s (%s)" % (pip_package.qualified_name, pip_variant.uri))
return context
开发者ID:sonictk,项目名称:rez,代码行数:49,代码来源:pip.py
示例10: _print_context_info
def _print_context_info(self, value, buf=sys.stdout, b=False):
word = "is also" if b else "is"
_pr = Printer(buf)
path = os.path.abspath(value)
if not os.path.isfile(path):
return False
try:
ResolvedContext.load(path)
except:
return False
_pr("'%s' %s a context. Use 'rez-context' for more information." % (path, word))
return True
开发者ID:RovioAnimation,项目名称:rez,代码行数:15,代码来源:status.py
示例11: __init__
def __init__(self, filepath):
"""Create a wrapper given its executable file."""
from rez.suite import Suite
def _err(msg):
raise RezSystemError("Invalid executable file %s: %s"
% (filepath, msg))
with open(filepath) as f:
content = f.read()
try:
doc = yaml.load(content)
doc = doc["kwargs"]
context_name = doc["context_name"]
tool_name = doc["tool_name"]
prefix_char = doc.get("prefix_char")
except YAMLError as e:
_err(str(e))
# check that the suite is there - a wrapper may have been moved out of
# a suite's ./bin path, which renders it useless.
suite_path = os.path.dirname(os.path.dirname(filepath))
try:
Suite.load(suite_path)
except SuiteError as e:
_err(str(e))
path = os.path.join(suite_path, "contexts", "%s.rxt" % context_name)
context = ResolvedContext.load(path)
self._init(suite_path, context_name, context, tool_name, prefix_char)
开发者ID:rvsiy,项目名称:rez,代码行数:30,代码来源:wrapper.py
示例12: _FWD__spawn_build_shell
def _FWD__spawn_build_shell(working_dir, build_dir):
# This spawns a shell that the user can run 'bez' in directly
context = ResolvedContext.load(os.path.join(build_dir, "build.rxt"))
config.override("prompt", "BUILD>")
retcode, _, _ = context.execute_shell(block=True, cwd=build_dir)
sys.exit(retcode)
开发者ID:rvsiy,项目名称:rez,代码行数:7,代码来源:bez.py
示例13: context
def context(self):
"""Get the current context.
Returns:
`ResolvedContext` or None if not in a context.
"""
path = self.context_file
return ResolvedContext.load(path) if path else None
开发者ID:RovioAnimation,项目名称:rez,代码行数:8,代码来源:status.py
示例14: test_execute_command_environ
def test_execute_command_environ(self):
"""Test that execute_command properly sets environ dict."""
parent_environ = {"BIGLY": "covfefe"}
r = ResolvedContext(["hello_world"])
pycode = ("import os; "
"print os.getenv(\"BIGLY\"); "
"print os.getenv(\"OH_HAI_WORLD\")")
args = ["python", "-c", pycode]
p = r.execute_command(args, parent_environ=parent_environ,
stdout=subprocess.PIPE)
stdout, _ = p.communicate()
stdout = stdout.strip()
parts = [x.strip() for x in stdout.split('\n')]
self.assertEqual(parts, ["covfefe", "hello"])
开发者ID:Pixomondo,项目名称:rez,代码行数:18,代码来源:test_context.py
示例15: _FWD__invoke_suite_tool_alias
def _FWD__invoke_suite_tool_alias(context_name, tool_name, prefix_char=None, _script=None, _cli_args=None):
suite_path = os.path.dirname(os.path.dirname(_script))
path = os.path.join(suite_path, "contexts", "%s.rxt" % context_name)
context = ResolvedContext.load(path)
from rez.wrapper import Wrapper
w = Wrapper.__new__(Wrapper)
w._init(suite_path, context_name, context, tool_name, prefix_char)
retcode = w.run(*(_cli_args or []))
sys.exit(retcode)
开发者ID:mstreatfield,项目名称:rez,代码行数:11,代码来源:suite.py
示例16: test_create_context
def test_create_context(self):
"""Test creation of context."""
r = ResolvedContext([])
r.print_info()
r = ResolvedContext(["hello_world"])
r.print_info()
开发者ID:rvsiy,项目名称:rez,代码行数:7,代码来源:test_context.py
示例17: get_package_info
def get_package_info(path, variant_index):
"""
Get valuable information about a package that can be used in different contexts.
:param path: Path to the root of a project
:param variant: index of the variant to resolve
:return: Dict with various info about a package
"""
data = {
"variants": [],
}
package = get_developer_package(path)
variants = list(package.iter_variants())
for v in variants:
data["variants"].append(v.qualified_name)
variant = variants[variant_index]
request = variant.get_requires(build_requires=True, private_build_requires=True)
context = ResolvedContext(request)
data["name"] = package.name
data["interpreter"] = context.which("python")
data["dependencies"] = get_dependencies(context)
return data
开发者ID:marcusolofsson,项目名称:RezHelper,代码行数:22,代码来源:rez_info.py
示例18: create_build_context
def create_build_context(self, variant, build_type, build_path):
"""Create a context to build the variant within."""
request = variant.get_requires(build_requires=True,
private_build_requires=True)
req_strs = map(str, request)
quoted_req_strs = map(quote, req_strs)
self._print("Resolving build environment: %s", ' '.join(quoted_req_strs))
if build_type == BuildType.local:
packages_path = self.package.config.packages_path
else:
packages_path = self.package.config.nonlocal_packages_path
if self.package.config.is_overridden("package_filter"):
from rez.package_filter import PackageFilterList
data = self.package.config.package_filter
package_filter = PackageFilterList.from_pod(data)
else:
package_filter = None
context = ResolvedContext(request,
package_paths=packages_path,
package_filter=package_filter,
building=True)
if self.verbose:
context.print_info()
# save context before possible fail, so user can debug
rxt_filepath = os.path.join(build_path, "build.rxt")
context.save(rxt_filepath)
if context.status != ResolverStatus.solved:
raise BuildContextResolveError(context)
return context, rxt_filepath
开发者ID:LumaPictures,项目名称:rez,代码行数:36,代码来源:build_process_.py
示例19: _FWD__spawn_build_shell
def _FWD__spawn_build_shell(working_dir, build_dir, variant_index):
# This spawns a shell that the user can run 'make' in directly
context = ResolvedContext.load(os.path.join(build_dir, "build.rxt"))
package = get_developer_package(working_dir)
variant = package.get_variant(variant_index)
config.override("prompt", "BUILD>")
callback = functools.partial(CMakeBuildSystem._add_build_actions,
context=context,
package=package,
variant=variant,
build_type=BuildType.local)
retcode, _, _ = context.execute_shell(block=True,
cwd=build_dir,
actions_callback=callback)
sys.exit(retcode)
开发者ID:cb109,项目名称:rez,代码行数:17,代码来源:cmake.py
示例20: load_context
def load_context(self, filepath):
context = None
busy_cursor = QtGui.QCursor(QtCore.Qt.WaitCursor)
with self.status("Loading %s..." % filepath):
QtGui.QApplication.setOverrideCursor(busy_cursor)
try:
context = ResolvedContext.load(filepath)
except ResolvedContextError as e:
QtGui.QMessageBox.critical(self.main_window,
"Failed to load context", str(e))
finally:
QtGui.QApplication.restoreOverrideCursor()
if context:
path = os.path.realpath(filepath)
self.config.prepend_string_list("most_recent_contexts", path,
"max_most_recent_contexts")
return context
开发者ID:LumaPictures,项目名称:rez,代码行数:19,代码来源:App.py
注:本文中的rez.resolved_context.ResolvedContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论