How to use the pykern.pkio.py_path 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 / srdb.py View on Github external
global cfg, _root
    cfg = pkconfig.init(
        root=(None, _cfg_root, 'where database resides'),
    )
    v = cfg.root
    if v:
        assert os.path.isabs(v), \
            '{}: SIREPO_SRDB_ROOT must be absolute'.format(v)
        assert os.path.isdir(v), \
            '{}: SIREPO_SRDB_ROOT must be a directory and exist'.format(v)
        v = pkio.py_path(v)
    else:
        assert pkconfig.channel_in('dev'), \
            'SIREPO_SRDB_ROOT must be configured except in DEV'
        fn = sys.modules[pkinspect.root_package(_init_root)].__file__
        root = pkio.py_path(pkio.py_path(pkio.py_path(fn).dirname).dirname)
        # Check to see if we are in our dev directory. This is a hack,
        # but should be reliable.
        if not root.join('requirements.txt').check():
            # Don't run from an install directory
            root = pkio.py_path('.')
        v = pkio.mkdir_parent(root.join(_DEFAULT_ROOT))
    _root = v
    return v
github radiasoft / sirepo / sirepo / pkcli / rs4pi.py View on Github external
def _parent_file(cfg_dir, filename):
    return str(pkio.py_path(cfg_dir.dirname).join(filename))
github radiasoft / sirepo / sirepo / pkcli / job_agent.py View on Github external
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.run_dir = pkio.py_path(self.msg.runDir)
        self._is_compute = self.msg.jobCmd == 'compute'
        if self._is_compute:
            pkio.unchecked_remove(self.run_dir)
            pkio.mkdir_parent(self.run_dir)
        self._in_file = self._create_in_file()
        self._process = _Process(self)
        self._terminating = False
        self._start_time = int(time.time())
        self.jid = self.msg.computeJid
github radiasoft / sirepo / sirepo / template / srw.py View on Github external
s = srwl_uti_smp.SRWLUtiSmp(
            file_path=path,
            area=None if not int(m['cropArea']) else (m['areaXStart'], m['areaXEnd'], m['areaYStart'], m['areaYEnd']),
            rotate_angle=float(m['rotateAngle']),
            rotate_reshape=int(m['rotateReshape']),
            cutoff_background_noise=float(m['cutoffBackgroundNoise']),
            background_color=int(m['backgroundColor']),
            invert=int(m['invert']),
            tile=None if not int(m['tileImage']) else (m['tileRows'], m['tileColumns']),
            shift_x=m['shiftX'],
            shift_y=m['shiftY'],
            is_save_images=True,
            prefix=str(tmp_dir),
            output_image_format=m['outputImageFormat'],
        )
        return pkio.py_path(s.processed_image_name)
github radiasoft / sirepo / sirepo / pkcli / job_driver.py View on Github external
def _report_job_status(job_tracker, request):
    pkdc('report_job_status: {}', request)
    status =  job_tracker.report_job_status(
        #TODO(e-carlin): Find a common place to do pkio.py_path() these are littered around
        pkio.py_path(request.run_dir), request.jhash
    ).value
    return pkcollections.Dict({
        'action': 'status_of_report_job',
        'request_id': request.request_id,
        'uid': request.uid,
        'status': status,
    })
github radiasoft / sirepo / sirepo / exporter.py View on Github external
def _python(data):
    """Generate python in current directory

    Args:
        data (dict): simulation

    Returns:
        py.path.Local: file to append
    """
    import sirepo.template
    import copy

    template = sirepo.template.import_module(data)
    res = pkio.py_path('run.py')
    res.write(template.python_source_for_model(copy.deepcopy(data), None))
    return res
github radiasoft / sirepo / sirepo / pkcli / job_driver.py View on Github external
async def _run_extract_job(job_tracker, request, io_loop):
    pkdc('run_extrac_job: {}', request)
    result = await job_tracker.run_extract_job(
        io_loop,
        pkio.py_path(request.run_dir),
        request.jhash,
        request.subcmd,
        request.arg,
    )
    return pkcollections.Dict({
        'action' : 'result_of_run_extract_job',
        'request_id': request.request_id,
        'uid': request.uid,
        'result': result,
    })
github radiasoft / sirepo / sirepo / runner.py View on Github external
def __volumes(self):
        res = []

        def _res(src, tgt):
            res.append('--volume={}:{}'.format(src, tgt))

        if pkconfig.channel_in('dev'):
            for v in '~/src', '~/.pyenv':
                v = pkio.py_path('~/src')
                # pyenv and src shouldn't be writable, only rundir
                _res(v, v + ':ro')
        _res(self.run_dir, self.run_dir)
        return res