def test_status(): console = Console( color_system=None, width=80, legacy_windows=False, get_time=lambda: 0.0 ) status = Status("foo", console=console) assert status.console == console status.update(status="bar", spinner="dots2", spinner_style="red", speed=2.0) assert isinstance(status.renderable, Table) # TODO: Testing output is tricky with threads with status: sleep(0.2)
def _generate_status(self) -> Status: """Generate the status.""" msg = f"Collected {self._n_collected_tasks} tasks." if self._n_errors > 0: msg += f" {self._n_errors} errors." status = Status(msg, spinner="dots") return status
def test_renderable(): console = Console( color_system=None, width=80, legacy_windows=False, get_time=lambda: 0.0 ) status = Status("foo", console=console) console.begin_capture() console.print(status) assert console.end_capture() == "РаІ foo\n"
def shell(self, ident, pass_env): for n, inst in enumerate(self.venv.instances()): if ident != f"#{n}" and not hex(hash(inst))[2:].startswith(ident): continue assert inst.py is not None, inst try: venv_path = inst.py.venv_path except FileNotFoundError: raise RuntimeError("%s not available" % inst.py) logger.info("Launching shell inside venv instance %s", inst) # Generate the environment for the instance. if pass_env: env = os.environ.copy() env.update(dict(inst.env)) else: env = dict(inst.env) # Should we expect the venv to be ready? with Status("Preparing shell virtual environment"): inst.py.create_venv(False) inst.prepare(env) pythonpath = inst.pythonpath if pythonpath: env["PYTHONPATH"] = (f"{pythonpath}:{env['PYTHONPATH']}" if "PYTHONPATH" in env else pythonpath) script_path = inst.scriptpath if script_path: env["PATH"] = ":".join( (script_path, env.get("PATH", os.environ["PATH"]))) with nspkgs(inst): pid = os.fork() if pid == 0: with tempfile.NamedTemporaryFile() as rcfile: rcfile.write( SHELL_RCFILE.format(venv_path=venv_path, name=inst.name).encode()) rcfile.flush() os.execvpe("bash", ["bash", "--rcfile", rcfile.name], env) os.wait() break else: logger.error( "No venv instance found for %s. Use 'riot list' to get a list of valid numbers.", ident, )
def pl_app(source_dir: str, script_path: str, name: str, overwrite: bool) -> None: source_dir = Path(source_dir).resolve() script_path = Path(script_path).resolve() if not source_dir.is_dir(): click.echo(f"The given source directory does not exist: {source_dir}", err=True) raise SystemExit(1) if not script_path.exists(): click.echo(f"The given script path does not exist: {script_path}", err=True) raise SystemExit(1) if not script_path.is_file(): click.echo( f"The given script path must be a file, you passed: {script_path}", err=True) raise SystemExit(1) if source_dir not in script_path.parents: click.echo( "The given script path must be a subpath of the source directory. Example:" " lightning init pl-app ./code ./code/scripts/train.py", err=True, ) raise SystemExit(1) rel_script_path = script_path.relative_to(source_dir) cwd = Path.cwd() destination = cwd / name if destination.exists(): if not overwrite: click.echo( f"There is already an app with the name {name} in the current working directory. Choose a different" f" name with `--name` or force to overwrite the existing folder by passing `--overwrite`.", err=True, ) raise SystemExit(1) else: shutil.rmtree(destination) template_dir = Path(lightning_app.cli.__file__).parent / "pl-app-template" with Status("[bold green]Copying app files"): shutil.copytree(template_dir, destination, ignore=shutil.ignore_patterns("node_modules", "build")) if (template_dir / "ui" / "build").exists(): shutil.copytree(template_dir / "ui" / "build", destination / "ui" / "build") else: download_frontend(destination / "ui" / "build") with Status("[bold green]Copying source files"): shutil.copytree(source_dir, destination / "source", ignore=shutil.ignore_patterns(name)) project_file_from_template(template_dir, destination, "app.py", script_path=str(rel_script_path)) project_file_from_template(template_dir, destination, "setup.py", app_name=name) with Status("[bold green]Installing"): subprocess.call(["pip", "install", "--quiet", "-e", str(destination)]) # TODO: download the ui files print_pretty_report( destination, ignore_patterns=_REPORT_IGNORE_PATTERNS, help_texts=_REPORT_HELP_TEXTS, )
def shell(self, ident, pass_env): for n, inst in enumerate(self.venv.instances()): if ident != f"#{n}" and not hex(hash(inst))[2:].startswith(ident): continue assert inst.py is not None, inst try: venv_path = inst.venv_path except FileNotFoundError: raise RuntimeError("%s not available" % inst.py) logger.info("Launching shell inside venv instance %s", inst) logger.debug("Setting venv path to %s", venv_path) # Generate the environment for the instance. if pass_env: env = os.environ.copy() env.update(dict(inst.env)) else: env = dict(inst.env) # Should we expect the venv to be ready? with Status("Preparing shell virtual environment"): inst.py.create_venv(False) inst.prepare(env) pythonpath = inst.pythonpath if pythonpath: env["PYTHONPATH"] = (f"{pythonpath}:{env['PYTHONPATH']}" if "PYTHONPATH" in env else pythonpath) script_path = inst.scriptpath if script_path: env["PATH"] = ":".join( (script_path, env.get("PATH", os.environ["PATH"]))) with nspkgs(inst): with tempfile.NamedTemporaryFile() as rcfile: rcfile.write( SHELL_RCFILE.format(venv_path=venv_path, name=inst.name).encode()) rcfile.flush() try: w, h = os.get_terminal_size() except OSError: w, h = 80, 24 c = pexpect.spawn(SHELL, ["-i"], dimensions=(h, w), env=env) c.setecho(False) c.sendline(f"source {rcfile.name}") try: c.interact() except Exception: pass c.close() sys.exit(c.exitstatus) else: logger.error( "No venv instance found for %s. Use 'riot list' to get a list of valid numbers.", ident, )
c = Contract.from_explorer('0xA39d1e9CBecdb17901bFa87a5B306D67f15A2391') def claim(r): d = DotMap() d.id = r['id'] d.account = r['account'] d.amount = int('0' + r['amount']) d.r = int('0' + r['r']) d.s = int('0' + r['s']) d.v = int('0' + r['v']) c.claim(d.id, d.account, d.amount, d.v, d.r, d.s) with Status('API not updated..'): while True: strategy = GasNowStrategy(speed='rapid') gas_price(strategy) url = f'https://cu3pxr9ydi.execute-api.us-east-1.amazonaws.com/prod/distributor' \ f'/{accounts.main}' r = requests.get(url).json()[0] if r['id'] != '': claim(r) for a in accounts.others: url = f'https://cu3pxr9ydi.execute-api.us-east-1.amazonaws.com/prod/distributor' \ f'/{a}' r = requests.get(url).json()[0] claim(r) time.sleep(1)