Python environ 模块,Path() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用environ.Path()

项目:django-remote-submission    作者:ornl-ndav    | 项目源码 | 文件源码
def env():
    import environ

    path = environ.Path(__file__) - 2
    env = environ.Env()
    environ.Env.read_env(path('.env'))

    try:
        return Env(
            server_hostname=env('TEST_SERVER_HOSTNAME'),
            server_port=env.int('TEST_SERVER_PORT'),
            remote_directory=env('TEST_REMOTE_DIRECTORY'),
            remote_filename=env('TEST_REMOTE_FILENAME'),
            remote_user=env('TEST_REMOTE_USER'),
            remote_password=env('TEST_REMOTE_PASSWORD'),
            python_path=env('TEST_PYTHON_PATH'),
            python_arguments=env.list('TEST_PYTHON_ARGUMENTS'),
        )
    except Exception as e:
        pytest.skip('Environment variables not set: {!r}'.format(e))
项目:pydoc.io    作者:rtfd    | 项目源码 | 文件源码
def update_body(app, pagename, templatename, context, doctree):
    outdir = environ.Path(app.config.html_context['output_directory'])
    project = app.config.project
    version = app.config.version
    if not os.path.exists(outdir.root):
        os.makedirs(outdir.root)
    directory_name = "{name}-{version}".format(name=project, version=version)
    json_dir = outdir.path(directory_name)
    if not os.path.exists(json_dir.root):
        os.makedirs(json_dir.root)
    try:
        out_dir = json_dir.path('/'.join(pagename.split('/')[:-1]))
        if not os.path.exists(out_dir()):
            os.makedirs(out_dir())
        out_file = json_dir.path(pagename + '.json')
        to_write = open(out_file(), 'w+')
        to_context = copy.copy(context)
        # Use list here so we don't get an error on changing dict during iteration
        for key in list(context):
            if key not in KEYS:
                del to_context[key]
        to_write.write(json.dumps(to_context, indent=4))
    except Exception:
        log.exception('Failure in JSON search dump')
项目:edd    作者:JBEI    | 项目源码 | 文件源码
def load_test_file(name):
    "Opens test files saved in the `files` directory."
    cwd = environ.Path(__file__) - 1
    filepath = cwd('files', name)
    return open(filepath, 'rb')