def create_release_vcs(path, vcs_name=None): """Return a new release VCS that can release from this source path.""" from rez.plugin_managers import plugin_manager vcs_types = get_release_vcs_types() if vcs_name: if vcs_name not in vcs_types: raise ReleaseVCSError("Unknown version control system: %r" % vcs_name) cls = plugin_manager.get_plugin_class('release_vcs', vcs_name) return cls(path) clss = [] for vcs_name in vcs_types: cls = plugin_manager.get_plugin_class('release_vcs', vcs_name) if cls.is_valid_root(path): clss.append(cls) if len(clss) > 1: clss_str = ", ".join(x.name() for x in clss) raise ReleaseVCSError("Several version control systems are associated " "with the path %s: %s. Use rez-release --vcs to " "choose." % (path, clss_str)) elif not clss: raise ReleaseVCSError("No version control system for package " "releasing is associated with the path %s" % path) else: return clss[0](path)
def get_valid_build_systems(working_dir, package=None): """Returns the build system classes that could build the source in given dir. Args: working_dir (str): Dir containing the package definition and potentially build files. package (`Package`): Package to be built. This may or may not be needed to determine the build system. For eg, cmake just has to look for a CMakeLists.txt file, whereas the 'build_command' package field must be present for the 'custom' build system type. Returns: List of class: Valid build system class types. """ from rez.plugin_managers import plugin_manager from rez.exceptions import PackageMetadataError try: package = package or get_developer_package(working_dir) except PackageMetadataError: # no package, or bad package pass if package: if getattr(package, "build_command", None) is not None: buildsys_name = "custom" else: buildsys_name = getattr(package, "build_system", None) # package explicitly specifies build system if buildsys_name: cls = plugin_manager.get_plugin_class('build_system', buildsys_name) return [cls] # detect valid build systems clss = [] for buildsys_name in get_buildsys_types(): cls = plugin_manager.get_plugin_class('build_system', buildsys_name) if cls.is_valid_root(working_dir, package=package): clss.append(cls) # Sometimes files for multiple build systems can be present, because one # build system uses another (a 'child' build system) - eg, cmake uses # make. Detect this case and ignore files from the child build system. # child_clss = set(x.child_build_system() for x in clss) clss = list(set(clss) - child_clss) return clss
def create_build_system(working_dir, buildsys_type=None, package=None, opts=None, write_build_scripts=False, verbose=False, build_args=[], child_build_args=[]): """Return a new build system that can build the source in working_dir.""" from rez.plugin_managers import plugin_manager if buildsys_type: cls = plugin_manager.get_plugin_class('build_system', buildsys_type) clss = [cls] else: clss = get_valid_build_systems(working_dir) if clss: # deal with leftover tempfiles from child buildsys in working dir child_clss = set(x.child_build_system() for x in clss) clss = set(clss) - child_clss if len(clss) > 1: s = ', '.join(x.name() for x in clss) raise BuildSystemError(("Source could be built with one of: %s; " "Please specify a build system") % s) else: cls = iter(clss).next() return cls(working_dir, opts=opts, package=package, write_build_scripts=write_build_scripts, verbose=verbose, build_args=build_args, child_build_args=child_build_args) else: raise BuildSystemError("No build system is associated with the path %s" % working_dir)
def create_build_process(process_type, working_dir, build_system, package=None, vcs=None, ensure_latest=True, skip_repo_errors=False, ignore_existing_tag=False, verbose=False, quiet=False): """Create a `BuildProcess` instance.""" from rez.plugin_managers import plugin_manager process_types = get_build_process_types() if process_type not in process_types: raise BuildProcessError("Unknown build process: %r" % process_type) cls = plugin_manager.get_plugin_class('build_process', process_type) return cls( working_dir, # ignored (deprecated) build_system, package=package, # ignored (deprecated) vcs=vcs, ensure_latest=ensure_latest, skip_repo_errors=skip_repo_errors, ignore_existing_tag=ignore_existing_tag, verbose=verbose, quiet=quiet)
def create_build_system(working_dir, buildsys_type=None, package=None, opts=None, write_build_scripts=False, verbose=False, build_args=[], child_build_args=[]): """Return a new build system that can build the source in working_dir.""" from rez.plugin_managers import plugin_manager # detect build system if necessary if not buildsys_type: clss = get_valid_build_systems(working_dir, package=package) if not clss: raise BuildSystemError( "No build system is associated with the path %s" % working_dir) if len(clss) != 1: s = ', '.join(x.name() for x in clss) raise BuildSystemError(("Source could be built with one of: %s; " "Please specify a build system") % s) buildsys_type = next(iter(clss)).name() # create instance of build system cls_ = plugin_manager.get_plugin_class('build_system', buildsys_type) return cls_(working_dir, opts=opts, package=package, write_build_scripts=write_build_scripts, verbose=verbose, build_args=build_args, child_build_args=child_build_args)
def create_build_system(working_dir, buildsys_type=None, package=None, opts=None, write_build_scripts=False, verbose=False, build_args=[], child_build_args=[]): """Return a new build system that can build the source in working_dir.""" from rez.plugin_managers import plugin_manager # detect build system if necessary if not buildsys_type: clss = get_valid_build_systems(working_dir, package=package) if not clss: raise BuildSystemError( "No build system is associated with the path %s" % working_dir) if len(clss) != 1: s = ', '.join(x.name() for x in clss) raise BuildSystemError(("Source could be built with one of: %s; " "Please specify a build system") % s) buildsys_type = iter(clss).next().name() # create instance of build system cls_ = plugin_manager.get_plugin_class('build_system', buildsys_type) return cls_(working_dir, opts=opts, package=package, write_build_scripts=write_build_scripts, verbose=verbose, build_args=build_args, child_build_args=child_build_args)
def create_release_vcs(path, vcs_name=None): """Return a new release VCS that can release from this source path.""" from rez.plugin_managers import plugin_manager vcs_types = get_release_vcs_types() if vcs_name: if vcs_name not in vcs_types: raise ReleaseVCSError("Unknown version control system: %r" % vcs_name) cls = plugin_manager.get_plugin_class('release_vcs', vcs_name) return cls(path) classes_by_level = {} for vcs_name in vcs_types: cls = plugin_manager.get_plugin_class('release_vcs', vcs_name) result = cls.find_vcs_root(path) if not result: continue vcs_path, levels_up = result classes_by_level.setdefault(levels_up, []).append((cls, vcs_path)) if not classes_by_level: raise ReleaseVCSError("No version control system for package " "releasing is associated with the path %s" % path) # it's ok to have multiple results, as long as there is only one at the # "closest" directory up from this dir - ie, if we start at: # /blah/foo/pkg_root # and these dirs exist: # /blah/.hg # /blah/foo/.git # ...then this is ok, because /blah/foo/.git is "closer" to the original # dir, and will be picked. However, if these two directories exist: # /blah/foo/.git # /blah/foo/.hg # ...then we error, because we can't decide which to use lowest_level = sorted(classes_by_level)[0] clss = classes_by_level[lowest_level] if len(clss) > 1: clss_str = ", ".join(x[0].name() for x in clss) raise ReleaseVCSError("Several version control systems are associated " "with the path %s: %s. Use rez-release --vcs to " "choose." % (path, clss_str)) else: cls, vcs_root = clss[0] return cls(pkg_root=path, vcs_root=vcs_root)
def test_plugin_override_2(self): """Test plugin from python modules can override the default""" with restore_sys_path(): sys.path.append(self.data_path("extensions")) mem_cls = plugin_manager.get_plugin_class("package_repository", "memory") self.assertEqual("bar", mem_cls.on_test)
def test_plugin_override_1(self): """Test plugin from plugin_path can override the default""" self.update_settings( dict(plugin_path=[self.data_path("extensions", "non-mod")])) mem_cls = plugin_manager.get_plugin_class("package_repository", "memory") self.assertEqual("non-mod", mem_cls.on_test)
def test_new_loading_style(self): """Test loading rez plugin from python modules""" with restore_sys_path(): sys.path.append(self.data_path("extensions")) cloud_cls = plugin_manager.get_plugin_class( "package_repository", "cloud") self.assertEqual(cloud_cls.name(), "cloud")
def test_old_loading_style(self): """Test loading rez plugin from plugin_path""" self.update_settings( dict(plugin_path=[self.data_path("extensions", "foo")])) cloud_cls = plugin_manager.get_plugin_class("package_repository", "cloud") self.assertEqual(cloud_cls.name(), "cloud")
def get_valid_build_systems(working_dir): """Returns the build system classes that could build the source in given dir.""" from rez.plugin_managers import plugin_manager clss = [] for buildsys_name in get_buildsys_types(): cls = plugin_manager.get_plugin_class('build_system', buildsys_name) if cls.is_valid_root(working_dir): clss.append(cls) return clss
def test_plugin_override_3(self): """Test plugin from python modules can override plugin_path""" with restore_sys_path(): # setup new sys.path.append(self.data_path("extensions")) # setup old self.update_settings( dict(plugin_path=[self.data_path("extensions", "non-mod")])) mem_cls = plugin_manager.get_plugin_class("package_repository", "memory") self.assertEqual("bar", mem_cls.on_test)
def create_memory_package_repository(repository_data): """Create a standalone in-memory package repository from the data given. See rezplugins/package_repository/memory.py for more details. Args: repository_data (dict): Package repository data. Returns: `PackageRepository` object. """ cls_ = plugin_manager.get_plugin_class("package_repository", "memory") return cls_.create_repository(repository_data)
def get_shell_class(shell=None): """Get the plugin class associated with the given or current shell. Returns: class: Plugin class for shell. """ if not shell: shell = config.default_shell if not shell: from rez.system import system shell = system.shell from rez.plugin_managers import plugin_manager return plugin_manager.get_plugin_class("shell", shell)
def get_valid_build_systems(working_dir): """Returns the build system classes that could build the source in given dir.""" from rez.plugin_managers import plugin_manager clss = [] for buildsys_name in get_buildsys_types(): cls = plugin_manager.get_plugin_class('build_system', buildsys_name) if cls.is_valid_root(working_dir): clss.append(cls) # explicit build command in package.py takes precedence if "custom" in [x.name() for x in clss]: clss = [x for x in clss if x.name() == "custom"] return clss
def create_build_process(process_type, working_dir, build_system, vcs=None, ensure_latest=True, skip_repo_errors=False, ignore_existing_tag=False, verbose=False): """Create a `BuildProcess` instance.""" from rez.plugin_managers import plugin_manager process_types = get_build_process_types() if process_type not in process_type: raise BuildProcessError("Unknown build process: %r" % process_type) cls = plugin_manager.get_plugin_class('build_process', process_type) return cls(working_dir, build_system=build_system, vcs=vcs, ensure_latest=ensure_latest, skip_repo_errors=skip_repo_errors, ignore_existing_tag=ignore_existing_tag, verbose=verbose)
def create_build_process(process_type, working_dir, build_system, vcs=None, ensure_latest=True, verbose=False): """Create a `BuildProcess` instance.""" from rez.plugin_managers import plugin_manager process_types = get_build_process_types() if process_type not in process_type: raise BuildProcessError("Unknown build process: %r" % process_type) cls = plugin_manager.get_plugin_class('build_process', process_type) return cls(working_dir, build_system=build_system, vcs=vcs, ensure_latest=ensure_latest, verbose=verbose)
def diff_packages(pkg1, pkg2=None): """Invoke a diff editor to show the difference between the source of two packages. Args: pkg1 (`Package`): Package to diff. pkg2 (`Package`): Package to diff against. If None, the next most recent package version is used. """ if pkg2 is None: it = iter_packages(pkg1.name) pkgs = [x for x in it if x.version < pkg1.version] if not pkgs: raise RezError("No package to diff with - %s is the earliest " "package version" % pkg1.qualified_name) pkgs = sorted(pkgs, key=lambda x: x.version) pkg2 = pkgs[-1] def _check_pkg(pkg): if not (pkg.vcs and pkg.revision): raise RezError("Cannot diff package %s: it is a legacy format " "package that does not contain enough information" % pkg.qualified_name) _check_pkg(pkg1) _check_pkg(pkg2) path = mkdtemp(prefix="rez-pkg-diff") paths = [] for pkg in (pkg1, pkg2): print("Exporting %s..." % pkg.qualified_name) path_ = os.path.join(path, pkg.qualified_name) vcs_cls_1 = plugin_manager.get_plugin_class("release_vcs", pkg1.vcs) vcs_cls_1.export(revision=pkg.revision, path=path_) paths.append(path_) difftool = config.difftool print("Opening diff viewer %s..." % difftool) with Popen([difftool] + paths) as p: p.wait()
def diff_packages(pkg1, pkg2=None): """Invoke a diff editor to show the difference between the source of two packages. Args: pkg1 (`Package`): Package to diff. pkg2 (`Package`): Package to diff against. If None, the next most recent package version is used. """ if pkg2 is None: it = iter_packages(pkg1.name) pkgs = [x for x in it if x.version < pkg1.version] if not pkgs: raise RezError("No package to diff with - %s is the earliest " "package version" % pkg1.qualified_name) pkgs = sorted(pkgs, key=lambda x: x.version) pkg2 = pkgs[-1] def _check_pkg(pkg): if not (pkg.vcs and pkg.revision): raise RezError("Cannot diff package %s: it is a legacy format " "package that does not contain enough information" % pkg.qualified_name) _check_pkg(pkg1) _check_pkg(pkg2) path = mkdtemp(prefix="rez-pkg-diff") paths = [] for pkg in (pkg1, pkg2): print "Exporting %s..." % pkg.qualified_name path_ = os.path.join(path, pkg.qualified_name) vcs_cls_1 = plugin_manager.get_plugin_class("release_vcs", pkg1.vcs) vcs_cls_1.export(revision=pkg.revision, path=path_) paths.append(path_) difftool = config.difftool print "Opening diff viewer %s..." % difftool proc = Popen([difftool] + paths) proc.wait()
def create_build_system(working_dir, buildsys_type=None, package=None, opts=None, write_build_scripts=False, verbose=False, build_args=[], child_build_args=[]): """Return a new build system that can build the source in working_dir.""" from rez.plugin_managers import plugin_manager # detect build system if necessary if not buildsys_type: clss = get_valid_build_systems(working_dir, package=package) if not clss: # Special case - bez. This is an old deprecated build system, # which expects a rezbuild.py file. Include info in error showing # how to port to a custom build command. # if os.path.exists(os.path.join(working_dir, "rezbuild.py")): msg = ( "No build system is associated with the path %s.\n" "\n" "There is a rezbuild.py file present, suggesting you were " "using the deprecated bez build system. You need to use a " "custom build command instead. You can port your existing " "rezbuild.py like so:\n" "\n" "Add this line to package.py:\n" "\n" " build_command = 'python {root}/rezbuild.py {install}'\n" "\n" "Add these lines to rezbuild.py:\n" "\n" " if __name__ == '__main__':\n" " import os, sys\n" " build(\n" " source_path=os.environ['REZ_BUILD_SOURCE_PATH'],\n" " build_path=os.environ['REZ_BUILD_PATH'],\n" " install_path=os.environ['REZ_BUILD_INSTALL_PATH'],\n" " targets=sys.argv[1:]\n" " )") raise BuildSystemError(msg % working_dir) raise BuildSystemError( "No build system is associated with the path %s" % working_dir) if len(clss) != 1: s = ', '.join(x.name() for x in clss) raise BuildSystemError(("Source could be built with one of: %s; " "Please specify a build system") % s) buildsys_type = next(iter(clss)).name() # create instance of build system cls_ = plugin_manager.get_plugin_class('build_system', buildsys_type) return cls_(working_dir, opts=opts, package=package, write_build_scripts=write_build_scripts, verbose=verbose, build_args=build_args, child_build_args=child_build_args)
def _get_repository(self, path, **repo_args): repo_type, location = path.split('@', 1) cls = plugin_manager.get_plugin_class('package_repository', repo_type) repo = cls(location, self.pool, **repo_args) return repo
def _get_repository(self, path): repo_type, location = path.split('@', 1) cls = plugin_manager.get_plugin_class('package_repository', repo_type) repo = cls(location, self.pool) return repo