def parse_parameter(s): res = [] res.append(format(s.name)) use = format_annotation(s.annotation) if use: res.append(format(":" + use, dim=True)) if s.default != inspect.Parameter.empty: res.append(format("=" + repr(s.default), dim=True)) return "".join(res)
def run(token, pipeline_id, func, use_app, use_shell, msg, starting): from .. import api, shell_ui url = api.Config().get_connect_url(pipeline_id) u_url = log.format(url, underline=True) if starting: tag = api.Config().get_image_tag() manager_image = constants.ImageUtil.get_manager_image(tag) try: client_utils.subprocess_run( ["docker", "image", "inspect", manager_image]) except client_utils.CalledProcessError: docker_parts = ["docker", "pull", manager_image] print( "Downloading the Conducto docker image that runs your pipeline." ) log.debug(" ".join(pipes.quote(s) for s in docker_parts)) client_utils.subprocess_run( docker_parts, msg="Error pulling manager container", ) print(f"{msg} pipeline {pipeline_id}.") func() if _manager_debug(): return if use_app: print( f"Viewing at {u_url}. To disable, specify '--no-app' on the command line." ) hostdet.system_open(url) else: print(f"View at {u_url}") data = api.Pipeline().get(token, pipeline_id) if data.get("is_public"): unauth_password = data["unauth_password"] url = api.Config().get_url() public_url = f"{url}/app/s/{pipeline_id}/{unauth_password}" u_public_url = log.format(public_url, underline=True) print(f"\nPublic view at:\n{u_public_url}") if use_shell: shell_ui.connect(token, pipeline_id, "Deploying")
def render(self): if self.state_counts: state_str = self.state.replace(State.PENDING, "ready").upper() line = "{help} {state} P:{P} Q:{Q} R:{R} D:{D} E:{E} K:{K}".format( help=self.key_mode.help(), state=log.format(state_str, bold=False, color=STATE_TO_COLOR[self.state]), P=self.state_count_str(State.PENDING), Q=self.state_count_str(State.QUEUED), R=self.state_count_str(State.RUNNING), D=self.state_count_str(State.DONE), E=self.state_count_str(State.ERROR), K=self.state_count_str(State.WORKER_ERROR), ) else: line = self.key_mode.help() screen_size = termsize.getTerminalWidth() # NOTE: would use StringIO but we need to examine the string using # `ansilen` at each step output_line = "" for c in line: if ansilen(output_line) >= screen_size: break output_line += c print(f"\r{log.Control.ERASE_LINE}{output_line}", end="", flush=True)
def add_handler(self, text, func): help_str = re.sub( "&(.)", lambda m: log.format(m.group(1).upper(), bold=True, underline=True ), text, ) self.help_clauses.append(help_str) key = re.search("&(.)", text).group(1) self.keymap[key] = func
def beautify(function, name, space): from conducto.shared.log import format, Color sig = inspect.signature(function) def format_annotation(an): if an == inspect.Parameter.empty: return "" if isinstance(an, types.FunctionType) and ( an.__code__.co_filename.endswith("typing.py") and an.__code__.co_name == "new_type" ): return an.__name__ out = inspect.formatannotation(an) out = out.replace("conducto.pipeline.", "") return out def parse_parameter(s): res = [] res.append(format(s.name)) use = format_annotation(s.annotation) if use: res.append(format(":" + use, dim=True)) if s.default != inspect.Parameter.empty: res.append(format("=" + repr(s.default), dim=True)) return "".join(res) def parse_return_annotation(): res = format_annotation(sig.return_annotation) if res: return " -> " + format(res, color="purple") else: return "" def parse_docstring(): if function.__doc__ is None: return "" return "\n".join(" " * 4 + i for i in function.__doc__.split("\n")) add = space - len(name) name = format(name, color=Color.BLUE) name = " " + name + " " * add params = ( f'({", ".join(parse_parameter(p) for p in sig.parameters.values())})' + parse_return_annotation() ) return name + params + parse_docstring()
def print_editor_commands(container_name): flavor = get_linux_flavor(container_name) if flavor == "ubuntu": uid_str = execute_in(container_name, "id -u") base = "apt-get update" each = "apt-get install" if int(uid_str) != 0: base = f"sudo {base}" each = f"sudo {each}" elif flavor == "alpine": base = "apk update" each = "apk add" else: return editors = {"vim": "blue", "emacs": "cyan", "nano": "green"} print("To install an editor, run:", end="") sep = "" for editor, color in editors.items(): print(sep, format(f"{base} && {each} {editor}", color=color), end="") sep = " or" print()
def state_count_str(self, state): count = self.state_counts[state] + self.state_counts[State.skip(state)] return log.format(count, bold=True, color=STATE_TO_COLOR[state])
def parse_return_annotation(): res = format_annotation(sig.return_annotation) if res: return " -> " + format(res, color="purple") else: return ""