def main() -> None: try: # Everyone on board # Note that this action should not be triggered in the module scope, because it # makes it difficult for tests to rollback changes. hooks.Actions.CORE_READY.do() cli() # pylint: disable=no-value-for-parameter except KeyboardInterrupt: pass except exceptions.TutorError as e: fmt.echo_error(f"Error: {e.args[0]}") sys.exit(1)
def discover_all(cls) -> None: for entrypoint in pkg_resources.iter_entry_points(cls.ENTRYPOINT): try: error: t.Optional[str] = None cls(entrypoint) except pkg_resources.VersionConflict as e: error = e.report() except Exception as e: # pylint: disable=broad-except error = str(e) if error: fmt.echo_error( f"Failed to load entrypoint '{entrypoint.name} = {entrypoint.module_name}' from distribution {entrypoint.dist}: {error}" )
def patch(self, name: str, separator: str = "\n", suffix: str = "") -> str: """ Render calls to {{ patch("...") }} in environment templates from plugin patches. """ patches = [] for patch in plugins.iter_patches(name): try: patches.append(self.render_str(patch)) except exceptions.TutorError: fmt.echo_error(f"Error rendering patch '{name}': {patch}") raise rendered = separator.join(patches) if rendered: rendered += suffix return rendered
def render_template(self, template_name: str) -> t.Union[str, bytes]: """ Render a template file. Return the corresponding string. If it's a binary file (as indicated by its path), return bytes. The template_name *always* uses "/" separators, and is not os-dependent. Do not pass the result of os.path.join(...) to this function. """ if is_binary_file(template_name): # Don't try to render binary files with open(self.find_os_path(template_name), "rb") as f: return f.read() try: template = self.environment.get_template(template_name) except Exception: fmt.echo_error("Error loading template " + template_name) raise try: return self.__render(template) except (jinja2.exceptions.TemplateError, exceptions.TutorError): fmt.echo_error("Error rendering template " + template_name) raise except Exception: fmt.echo_error("Unknown error rendering template " + template_name) raise