Example #1
0
def make_project(tmpdir, requires=[], backend=None, backend_path=None):
    project_dir = tmpdir / 'project'
    project_dir.mkdir()
    buildsys = {'requires': requires}
    if backend:
        buildsys['build-backend'] = backend
    if backend_path:
        buildsys['backend-path'] = backend_path
    data = toml.dumps({'build-system': buildsys})
    project_dir.joinpath('pyproject.toml').write_text(data)
    return project_dir
Example #2
0
def make_pyproject_with_setup(tmpdir, build_system=True, set_backend=True):
    project_dir = tmpdir / 'project'
    project_dir.mkdir()
    setup_script = (
        'from setuptools import setup\n'
    )
    expect_script_dir_on_path = True
    if build_system:
        buildsys = {
            'requires': ['setuptools', 'wheel'],
        }
        if set_backend:
            buildsys['build-backend'] = 'setuptools.build_meta'
            expect_script_dir_on_path = False
        project_data = toml.dumps({'build-system': buildsys})
    else:
        project_data = ''

    if expect_script_dir_on_path:
        setup_script += (
            'from pep517_test import __version__\n'
        )
    else:
        setup_script += (
            'try:\n'
            '    import pep517_test\n'
            'except ImportError:\n'
            '    pass\n'
            'else:\n'
            '    raise RuntimeError("Source dir incorrectly on sys.path")\n'
        )

    setup_script += (
        'setup(name="pep517_test", version="0.1", packages=["pep517_test"])'
    )

    project_dir.joinpath('pyproject.toml').write_text(project_data)
    project_dir.joinpath('setup.py').write_text(setup_script)
    package_dir = project_dir / "pep517_test"
    package_dir.mkdir()
    package_dir.joinpath('__init__.py').write_text('__version__ = "0.1"')
    return project_dir, "pep517_test"