How to use the pykern.pkio function in pykern

To help you get started, we’ve selected a few pykern examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github radiasoft / sirepo / sirepo / runner_api.py View on Github external
),
        is_parallel=res.sim_data.is_parallel(req.req_data),
        jid=res.sim_data.parse_jid(req.req_data),
        job_status=_read_status(res.run_dir),
        model_name=res.sim_data.parse_model(req.req_data.report),
        req_hash=(
            req.req_data.get('computeJobHash')
            or res.sim_data.compute_job_hash(req.req_data)
        ),
    )
    if not res.run_dir.check():
        return res
    try:
        c = simulation_db.read_json(res.input_file)
    except Exception as e:
        if pykern.pkio.exception_is_not_found(e):
            return res
        raise
    res.cached_data = c
    # backwards compatibility for old runs that don't have computeJobCacheKey
    res.cached_hash = c.models.pksetdefault(
        computeJobCacheKey=lambda: PKDict(
            computeJobHash=res.sim_data.compute_job_hash(c),
            computeJobStart=int(res.input_file.mtime()),
        ),
    ).computeJobCacheKey.computeJobHash
    if res.req_hash == res.cached_hash:
        res.cache_hit = True
        return res
    res.parameters_changed = True
    return res
github radiasoft / sirepo / sirepo / pkcli / rcscon.py View on Github external
def _run_simulation():
    exec(pkio.read_text(template_common.PARAMETERS_PYTHON_FILE), locals(), locals())
github radiasoft / sirepo / sirepo / template / srw.py View on Github external
def index_file_name(zf):
        # Apparently pkio.has_file_extension will return true for any extension if fed a directory path ('some_dir/')
        text_files = [f for f in zf.namelist() if not f.endswith('/') and pkio.has_file_extension(f, 'txt')]
        if len(text_files) != 1:
            return None
        return text_files[0]
github radiasoft / sirepo / sirepo / pkcli / runner_agent.py View on Github external
async def _start_report_job(job_tracker, request):
    pkdp(f'Daemon requested start_report_job: {request}')

#TODO(robnagler) this lock should be encapsulated inside JobTracker
    async with job_tracker.locks[request.run_dir]:
        await job_tracker.start_report_job(
            pkio.py_path(request.run_dir), request.jhash,
            request.backend,
            request.cmd, pkio.py_path(request.tmp_dir),
        )
        return {}
github radiasoft / sirepo / sirepo / pkcli / srw.py View on Github external
def run_background(cfg_dir):
    """Run srw with mpi in ``cfg_dir``

    Args:
        cfg_dir (str): directory to run srw in
    """
    with pkio.save_chdir(cfg_dir):
        mpi.run_script(pkio.read_text(template_common.PARAMETERS_PYTHON_FILE))
        simulation_db.write_result({})
github radiasoft / sirepo / sirepo / pkcli / job_driver.py View on Github external
def _write_status(status, run_dir):
    fn = run_dir.join('result.json')
    if not fn.exists():
        pkjson.dump_pretty({'state': status.value}, filename=fn)
        pkio.write_text(run_dir.join('status'), status.value)