def _load_argparse_flags_data(self, mod_path, sys_path): env = dict(os.environ) env.update({ "PYTHONPATH": os.path.pathsep.join([sys_path] + sys.path), "LOG_LEVEL": str(self.log.getEffectiveLevel()), "PYTHONDONTWRITEBYTECODE": "1", }) with util.TempFile() as tmp: data_path = tmp.path cmd = [ sys.executable, "-m", "guild.plugins.import_argparse_flags_main", mod_path, data_path ] self.log.debug("import_argparse_flags_main env: %s", env) self.log.debug("import_argparse_flags_main cmd: %s", cmd) try: out = subprocess.check_output(cmd, stderr=subprocess.STDOUT, env=env) except subprocess.CalledProcessError as e: self.log.warning("cannot import flags from %s: %s", mod_path, e.output.decode().strip()) raise DataLoadError() else: self.log.debug("import_argparse_flags_main output: %s", out) return self._load_data(data_path)
def _op_pidfile(args): if args.pidfile: return args.pidfile elif args.background: return util.TempFile("guild-pid-").path else: return None
def flags_for_script(self, script, log): env = dict(os.environ) env.update( { "PYTHONPATH": os.path.pathsep.join([script.sys_path or ''] + sys.path), "LOG_LEVEL": str(log.getEffectiveLevel()), "PYTHONDONTWRITEBYTECODE": "1", } ) with util.TempFile() as tmp: cmd = [ sys.executable, "-m", "guild.plugins.click_flags", script.src, script.mod_package or '', tmp.path, ] log.debug("click_flags env: %s", env) log.debug("click_flags cmd: %s", cmd) try: out = subprocess.check_output(cmd, stderr=subprocess.STDOUT, env=env) except subprocess.CalledProcessError as e: log.warning( "cannot import flags from %s: %s", script.src, e.output.decode().strip(), ) raise python_script.DataLoadError() else: out = out.decode() log.debug("click_flags output: %s", out) python_script._log_warnings(out, log) return python_script._load_data(tmp.path)
def _new_meta_id(self): meta_id = uuid.uuid4().hex with util.TempFile("guild-azure-blob-") as tmp: with open(tmp.path, "w") as f: f.write(meta_id) args = [tmp.path, self._container_path("meta-id")] self._azcopy("copy", args)
def _op_pidfile(args): if args.pidfile: return args.pidfile elif args.background: with util.TempFile("guild-pid-", keep=True) as pidfile: return pidfile else: return None
def _remote_meta_id(self): with util.TempFile("guild-s3-") as tmp: args = [ "--bucket", self.bucket, "--key", _join_path(self.root, "meta-id"), tmp.path, ] self._s3api_output("get-object", args) return open(tmp.path, "r").read().strip()
def _new_meta_id(self): meta_id = _uuid() with util.TempFile("guild-s3-") as tmp: with open(tmp, "w") as f: f.write(meta_id) args = [ "--bucket", self.bucket, "--key", _join_path(self.root, "meta-id"), "--body", tmp ] self._s3api_output("put-object", args)
def _argparse_flags_data(script, base_args, log): env = dict(os.environ) env.update({ "PYTHONPATH": os.path.pathsep.join([script.sys_path or ''] + sys.path), "LOG_LEVEL": str(log.getEffectiveLevel()), "PYTHONDONTWRITEBYTECODE": "1", }) with util.TempFile() as tmp: cmd = [ sys.executable, "-m", "guild.plugins.import_argparse_flags_main", script.src, script.mod_package or '', util.shlex_join(base_args), tmp.path, ] log.debug("import_argparse_flags_main env: %s", env) log.debug("import_argparse_flags_main cmd: %s", cmd) try: out = subprocess.check_output(cmd, stderr=subprocess.STDOUT, env=env) except subprocess.CalledProcessError as e: error, details = _split_argparse_flags_error( e.output.decode().strip()) if details and log.getEffectiveLevel() > logging.DEBUG: error += " (run with guild --debug for details)" if os.getenv("NO_WARN_FLAGS_IMPORT") != "1": log.warning("cannot import flags from %s: %s", script.src, error) if details and log.getEffectiveLevel() <= logging.DEBUG: log.error(details) raise DataLoadError() else: out = out.decode() log.debug("import_argparse_flags_main output: %s", out) _log_warnings(out, log) return _load_data(tmp.path)
def _remote_meta_id(self): with util.TempFile("guild-azure-blob-") as tmp: args = [self._container_path("meta-id"), tmp.path] self._azcopy("copy", args, quiet=True) return open(tmp.path, "r").read().strip()