def test_2(self): """Resolve a package with a dependency, see that their commands are concatenated as expected.""" pkg = VersionedObject("rextest2-2") base = os.path.join(self.packages_path, "rextest", "1.3") base2 = os.path.join(self.packages_path, "rextest2", "2") cmds = [ Setenv('REZ_USED_REQUEST', "rextest2-2"), Setenv('REZ_USED_RESOLVE', "rextest-1.3 rextest2-2"), # rez's rextest vars Setenv('REZ_REXTEST_VERSION', "1.3"), Setenv('REZ_REXTEST_BASE', base), Setenv('REZ_REXTEST_ROOT', base), # rez's rextest2 vars Setenv('REZ_REXTEST2_VERSION', '2'), Setenv('REZ_REXTEST2_BASE', base2), Setenv('REZ_REXTEST2_ROOT', base2), # rextest's commands Setenv('REXTEST_ROOT', base), Setenv('REXTEST_VERSION', "1.3"), Setenv('REXTEST_MAJOR_VERSION', "1"), Setenv('REXTEST_DIRS', "/".join([base, "data"])), Alias('rextest', 'foobar'), # rextext2's commands Appendenv('REXTEST_DIRS', "/".join([base2, "data2"])), Setenv('REXTEST2_REXTEST_VER', '1.3'), Setenv('REXTEST2_REXTEST_BASE', os.path.join(self.packages_path, "rextest", "1.3")) ] self._test_package(pkg, {}, cmds) # first prepend should still override self._test_package(pkg, {"REXTEST_DIRS": "TEST"}, cmds)
def remove_package_family(opts, parser, force=False): from rez.vendor.version.requirement import VersionedObject from rez.package_remove import remove_package_family from rez.exceptions import PackageRepositoryError if opts.dry_run: parser.error("--dry-run is not supported with --family") if not opts.PATH: parser.error("Must specify PATH with --family") obj = VersionedObject(opts.family) if obj.version: parser.error("Expected package name, not version") success = False try: success = remove_package_family(obj.name, opts.PATH, force=force) except PackageRepositoryError as e: print("Error: %s" % e, file=sys.stderr) sys.exit(1) if success: print("Package family removed.") else: print("Package family not found.", file=sys.stderr) sys.exit(1)
def command(opts, parser, extra_arg_groups=None): from rez.vendor.version.requirement import VersionedObject from rez.packages import get_package_from_repository from rez.package_move import move_package import sys obj = VersionedObject(opts.PKG) if opts.PATH is None: list_repos_containing_pkg(obj.name, obj.version) sys.exit(0) # find src pkg src_pkg = get_package_from_repository(obj.name, obj.version, opts.PATH) if src_pkg is None: print("Package not found.", file=sys.stderr) sys.exit(1) move_package( package=src_pkg, dest_repository=opts.dest_path, keep_timestamp=opts.keep_timestamp, force=opts.force, verbose=opts.verbose )
def qualified_name(self): """Get the qualified name of the package. Returns: str: Name of the package with version, eg "maya-2016.1". """ o = VersionedObject.construct(self.name, self.version) return str(o)
def as_exact_requirement(self): """Get the package, as an exact requirement string. Returns: Equivalent requirement string, eg "maya==2016.1" """ o = VersionedObject.construct(self.name, self.version) return o.as_exact_requirement()
def _test_rextest_package(self, version): pkg = VersionedObject("rextest-%s" % version) cmds = [Setenv('REZ_USED_REQUEST', str(pkg)), Setenv('REZ_USED_RESOLVE', str(pkg))] cmds += self._get_rextest_commands(pkg) self._test_package(pkg, {}, cmds) # first prepend should still override self._test_package(pkg, {"REXTEST_DIRS": "TEST"}, cmds)
def expand_requirement(request): """Expands a requirement string like 'python-2.*' Only trailing wildcards are supported; they will be replaced with the latest package version found within the range. If none are found, the wildcards will just be stripped. Example: >>> print expand_requirement('python-2.*') python-2.7 Args: request (str): Request to expand, eg 'python-2.*' Returns: str: Expanded request string. """ if '*' not in request: return request from rez.vendor.version.requirement import VersionedObject, Requirement from rez.packages_ import get_latest_package txt = request.replace('*', '_') obj = VersionedObject(txt) rank = len(obj.version) request_ = request while request_.endswith('*'): request_ = request_[:-2] # strip sep + * req = Requirement(request_) package = get_latest_package(name=req.name, range_=req.range_) if package is None: return request_ obj.version_ = package.version.trim(rank) return str(obj)
def get_package_from_string(txt, paths=None): """Get a package given a string. Args: txt (str): String such as 'foo', 'bah-1.3'. paths (list of str, optional): paths to search for package, defaults to `config.packages_path`. Returns: `Package` instance, or None if no package was found. """ o = VersionedObject(txt) return get_package(o.name, o.version, paths=paths)
def remove_package(opts, parser): from rez.vendor.version.requirement import VersionedObject from rez.package_remove import remove_package if opts.dry_run: parser.error("--dry-run is not supported with --package") if not opts.PATH: parser.error("Must specify PATH with --package") obj = VersionedObject(opts.package) if remove_package(obj.name, obj.version, opts.PATH): print("Package removed.") else: print("Package not found.", file=sys.stderr) sys.exit(1)
def command(opts, parser, extra_arg_groups=None): from rez.package_repository import package_repository_manager from rez.vendor.version.requirement import VersionedObject import sys obj = VersionedObject(opts.PKG) if opts.PATH is None: if opts.allow_missing: list_repos() else: list_repos_containing_pkg(obj.name, obj.version) sys.exit(0) repo = package_repository_manager.get_repository(opts.PATH) if opts.unignore: i = repo.unignore_package(obj.name, obj.version) else: i = repo.ignore_package(obj.name, obj.version, allow_missing=opts.allow_missing) if i == 1: if opts.unignore: print("Package is now visible to resolves once more") else: print("Package is now ignored and will not be visible to resolves") elif i == 0: if opts.unignore: print("No action taken - package was already visible") else: print("No action taken - package was already ignored") else: print("Package not found", file=sys.stderr) sys.exit(1)
def command(opts, parser, extra_arg_groups=None): from rez.config import config from rez.exceptions import RezBindError from rez import module_root_path from rez.util import get_close_pkgs from rez.utils.formatting import columnise, PackageRequest from rez.vendor.version.requirement import VersionedObject import os.path import os import sys # gather the params install_path = (config.local_packages_path if opts.install_path is None else opts.install_path) req = PackageRequest(opts.PKG) name = req.name version_range = None if req.range.is_any() else req.range if req.conflict: parser.error("PKG cannot be a conflict requirement") # find the bind module builtin_path = os.path.join(module_root_path, "bind") searchpaths = config.bind_module_path + [builtin_path] bindfile = None bindnames = {} for path in searchpaths: if opts.verbose: print "searching %s..." % path if not os.path.isdir(path): continue filename = os.path.join(path, name + ".py") if os.path.isfile(filename): if opts.search: print filename sys.exit(0) else: bindfile = filename break else: for filename in os.listdir(path): fpath = os.path.join(path, filename) fname, ext = os.path.splitext(filename) if os.path.isfile(fpath) and ext == ".py" \ and not fname.startswith('_'): bindnames[fname] = fpath if not bindfile: fuzzy_matches = get_close_pkgs(name, bindnames.keys()) if opts.search: if fuzzy_matches: rows = [(x[0], bindnames[x[0]]) for x in fuzzy_matches] print "'%s' not found. Close matches:" % name print '\n'.join(columnise(rows)) else: print "No matches." sys.exit(0) else: msg = "bind module not found for '%s'" % name if fuzzy_matches: matches_s = ', '.join(x[0] for x in fuzzy_matches) msg += "\ndid you mean one of: %s" % matches_s raise RezBindError(msg) # load the bind module stream = open(bindfile) namespace = {} exec stream in namespace # parse bind module params bind_parser = argparse.ArgumentParser(prog="rez bind %s" % name, description="%s bind module" % name) parserfunc = namespace.get("setup_parser") if parserfunc: parserfunc(bind_parser) bind_opts = bind_parser.parse_args(opts.BIND_ARG) # make the package if opts.verbose: print "creating package '%s' in %s..." % (name, install_path) bindfunc = namespace.get("bind") if not bindfunc: raise RezBindError("'bind' function missing in %s" % bindfile) name, version = bindfunc(path=install_path, version_range=version_range, opts=bind_opts, parser=bind_parser) o = VersionedObject.construct(name, version) print "created package '%s' in %s" % (str(o), install_path)
def match(self, package): o = VersionedObject.construct(package.name, package.version) return not self._requirement.conflicts_with(o)
def qualified_package_name(self): o = VersionedObject.construct(self.name, self.version) return str(o)
def command(opts, parser, extra_arg_groups=None): from rez.config import config from rez.exceptions import RezBindError from rez import module_root_path from rez.util import get_close_pkgs from rez.utils.formatting import columnise, PackageRequest from rez.vendor.version.requirement import VersionedObject import os.path import os import sys # gather the params install_path = (config.local_packages_path if opts.install_path is None else opts.install_path) req = PackageRequest(opts.PKG) name = req.name version_range = None if req.range.is_any() else req.range if req.conflict: parser.error("PKG cannot be a conflict requirement") # find the bind module builtin_path = os.path.join(module_root_path, "bind") searchpaths = config.bind_module_path + [builtin_path] bindfile = None bindnames = {} for path in searchpaths: if opts.verbose: print "searching %s..." % path if not os.path.isdir(path): continue filename = os.path.join(path, name + ".py") if os.path.isfile(filename): if opts.search: print filename sys.exit(0) else: bindfile = filename break else: for filename in os.listdir(path): fpath = os.path.join(path, filename) fname, ext = os.path.splitext(filename) if os.path.isfile(fpath) and ext == ".py" \ and not fname.startswith('_'): bindnames[fname] = fpath if not bindfile: fuzzy_matches = get_close_pkgs(name, bindnames.keys()) if opts.search: if fuzzy_matches: rows = [(x[0], bindnames[x[0]]) for x in fuzzy_matches] print "'%s' not found. Close matches:" % name print '\n'.join(columnise(rows)) else: print "No matches." sys.exit(0) else: msg = "bind module not found for '%s'" % name if fuzzy_matches: matches_s = ', '.join(x[0] for x in fuzzy_matches) msg += "\ndid you mean one of: %s" % matches_s raise RezBindError(msg) # load the bind module stream = open(bindfile) namespace = {} exec stream in namespace # parse bind module params bind_parser = argparse.ArgumentParser(prog = "rez bind %s" % name, description="%s bind module" % name) parserfunc = namespace.get("setup_parser") if parserfunc: parserfunc(bind_parser) bind_opts = bind_parser.parse_args(opts.BIND_ARG) # make the package if opts.verbose: print "creating package '%s' in %s..." % (name, install_path) bindfunc = namespace.get("bind") if not bindfunc: raise RezBindError("'bind' function missing in %s" % bindfile) name, version = bindfunc(path=install_path, version_range=version_range, opts=bind_opts, parser=bind_parser) o = VersionedObject.construct(name, version) print "created package '%s' in %s" % (str(o), install_path)
def _uri(self): obj = VersionedObject.construct(self.name, self.version) return "%s:%s" % (self.location, str(obj))