Beispiel #1
0
def check(source_dir):
    pyproject = pjoin(source_dir, 'pyproject.toml')
    if isfile(pyproject):
        log.info('Found pyproject.toml')
    else:
        log.error('Missing pyproject.toml')
        return False

    try:
        with open(pyproject) as f:
            pyproject_data = toml_load(f)
        # Ensure the mandatory data can be loaded
        buildsys = pyproject_data['build-system']
        requires = buildsys['requires']
        backend = buildsys['build-backend']
        backend_path = buildsys.get('backend-path')
        log.info('Loaded pyproject.toml')
    except (TomlDecodeError, KeyError):
        log.error("Invalid pyproject.toml", exc_info=True)
        return False

    hooks = Pep517HookCaller(source_dir, backend, backend_path)

    sdist_ok = check_build_sdist(hooks, requires)
    wheel_ok = check_build_wheel(hooks, requires)

    if not sdist_ok:
        log.warning('Sdist checks failed; scroll up to see')
    if not wheel_ok:
        log.warning('Wheel checks failed')

    return sdist_ok
Beispiel #2
0
def get_hooks(pkg, backend=None, path=None):
    source_dir = pjoin(SAMPLES_DIR, pkg)
    with open(pjoin(source_dir, 'pyproject.toml')) as f:
        data = toml.load(f)
    if backend is None:
        backend = data['build-system']['build-backend']
    if path is None:
        path = data['build-system']['backend-path']
    return Pep517HookCaller(source_dir, backend, path)
Beispiel #3
0
def build(source_dir='.', dest=None, system=None):
    system = system or load_system(source_dir)
    dest = os.path.join(source_dir, dest or 'dist')
    mkdir_p(dest)
    validate_system(system)
    hooks = Pep517HookCaller(source_dir, system['build-backend'],
                             system.get('backend-path'))

    with hooks.subprocess_runner(quiet_subprocess_runner):
        with BuildEnvironment() as env:
            env.pip_install(system['requires'])
            _prep_meta(hooks, env, dest)
Beispiel #4
0
def build(source_dir, dist, dest=None, system=None):
    system = system or load_system(source_dir)
    dest = os.path.join(source_dir, dest or 'dist')
    mkdir_p(dest)

    validate_system(system)
    hooks = Pep517HookCaller(source_dir, system['build-backend'],
                             system.get('backend-path'))

    with BuildEnvironment() as env:
        env.pip_install(system['requires'])
        _do_build(hooks, env, dist, dest)
Beispiel #5
0
def test_backend_path_within_tree():
    source_dir = pjoin(SAMPLES_DIR, 'pkg1')
    assert Pep517HookCaller(source_dir, 'dummy', ['.', 'subdir'])
    assert Pep517HookCaller(source_dir, 'dummy', ['../pkg1', 'subdir/..'])
    # TODO: Do we want to insist on ValueError, or invent another exception?
    with pytest.raises(Exception):
        assert Pep517HookCaller(source_dir, 'dummy', [source_dir])
    with pytest.raises(Exception):
        Pep517HookCaller(source_dir, 'dummy', ['.', '..'])
    with pytest.raises(Exception):
        Pep517HookCaller(source_dir, 'dummy', ['subdir/../..'])
    with pytest.raises(Exception):
        Pep517HookCaller(source_dir, 'dummy', ['/'])
Beispiel #6
0
def build_sdist(source_dir, sdist_dir, config_settings=None):
    """Build an sdist from a source directory using PEP 517 hooks.

    :param str source_dir: Source directory containing pyproject.toml
    :param str sdist_dir: Target directory to place sdist in
    :param dict config_settings: Options to pass to build backend

    This is a blocking function which will run pip in a subprocess to install
    build requirements.
    """
    if config_settings is None:
        config_settings = {}
    requires, backend, backend_path = _load_pyproject(source_dir)
    hooks = Pep517HookCaller(source_dir, backend, backend_path)

    with BuildEnvironment() as env:
        env.pip_install(requires)
        reqs = hooks.get_requires_for_build_sdist(config_settings)
        env.pip_install(reqs)
        return hooks.build_sdist(sdist_dir, config_settings)
def get_hooks(pkg):
    source_dir = pjoin(SAMPLES_DIR, pkg)
    with open(pjoin(source_dir, 'pyproject.toml')) as f:
        data = toml.load(f)
    return Pep517HookCaller(source_dir, data['build-system']['build-backend'])