How to use the flit.sdist.SdistBuilder.from_ini_path function in flit

To help you get started, we’ve selected a few flit 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 takluyver / flit / tests / test_sdist.py View on Github external
def test_get_files_list_git(copy_sample):
    td = copy_sample('module1_toml')
    (td / '.git').mkdir()

    builder = sdist.SdistBuilder.from_ini_path(td / 'pyproject.toml')
    with MockCommand('git', LIST_FILES_GIT):
        files = builder.select_files()

    assert set(files) == {
        'foo', pjoin('dir1', 'bar'), pjoin('dir1', 'subdir', 'qux'),
        pjoin('dir2', 'abc')
    }
github takluyver / flit / tests / test_sdist.py View on Github external
def test_make_setup_py_reqs_extra_envmark():
    builder = sdist.SdistBuilder.from_ini_path(samples_dir / 'requires-extra-envmark' / 'pyproject.toml')
    ns = get_setup_assigns(builder.make_setup_py())
    assert ns['extras_require'] == {'test:python_version == "2.7"': ['pathlib2']}
github takluyver / flit / tests / test_sdist.py View on Github external
def test_get_files_list_hg(tmp_path):
    dir1 = tmp_path / 'dir1'
    copytree(str(samples_dir / 'module1_toml'), str(dir1))
    (tmp_path / '.hg').mkdir()
    builder = sdist.SdistBuilder.from_ini_path(dir1 / 'pyproject.toml')
    with MockCommand('hg', LIST_FILES_HG):
        files = builder.select_files()

    assert set(files) == {
        'bar', pjoin('subdir', 'qux')
    }
github takluyver / flit / tests / test_sdist.py View on Github external
def test_make_setup_py_reqs_envmark():
    builder = sdist.SdistBuilder.from_ini_path(samples_dir / 'requires-envmark' / 'pyproject.toml')
    ns = get_setup_assigns(builder.make_setup_py())
    assert ns['install_requires'] == ['requests']
    assert ns['extras_require'] == {":python_version == '2.7'": ['pathlib2']}
github takluyver / flit / tests / test_sdist.py View on Github external
def test_sdist_no_setup_py():
    # Smoke test of making a complete sdist
    if not which('git'):
        pytest.skip("requires git")
    builder = sdist.SdistBuilder.from_ini_path(samples_dir / 'package1' / 'pyproject.toml')
    with TemporaryDirectory() as td:
        td = Path(td)
        builder.build(td, gen_setup_py=False)
        sdist_file = td / 'package1-0.1.tar.gz'
        assert_isfile(sdist_file)

        with tarfile.open(str(sdist_file)) as tf:
            assert 'package1-0.1/setup.py' not in tf.getnames()
github takluyver / flit / tests / test_sdist.py View on Github external
def test_make_setup_py_reqs():
    builder = sdist.SdistBuilder.from_ini_path(samples_dir / 'extras' / 'pyproject.toml')
    ns = get_setup_assigns(builder.make_setup_py())
    assert ns['install_requires'] == ['toml']
    assert ns['extras_require'] == {'test': ['pytest'], 'custom': ['requests']}
github takluyver / flit / tests / test_sdist.py View on Github external
def test_make_sdist():
    # Smoke test of making a complete sdist
    if not which('git'):
        pytest.skip("requires git")
    builder = sdist.SdistBuilder.from_ini_path(samples_dir / 'package1' / 'pyproject.toml')
    with TemporaryDirectory() as td:
        td = Path(td)
        builder.build(td)
        sdist_file = td / 'package1-0.1.tar.gz'
        assert_isfile(sdist_file)

        with tarfile.open(str(sdist_file)) as tf:
            assert 'package1-0.1/setup.py' in tf.getnames()
github takluyver / flit / flit / build.py View on Github external
"""Build wheel and sdist"""
    if not formats:
        formats = ALL_FORMATS
    elif not formats.issubset(ALL_FORMATS):
        raise ValueError("Unknown package formats: {}".format(formats - ALL_FORMATS))

    sdist_info = wheel_info = None
    dist_dir = ini_file.parent / 'dist'
    dist_dir.mkdir(parents=True, exist_ok=True)

    try:
        # Load the config file to make sure it gets validated
        read_flit_config(ini_file)

        if 'sdist' in formats:
            sb = SdistBuilder.from_ini_path(ini_file)
            sdist_file = sb.build(dist_dir, gen_setup_py=gen_setup_py)
            sdist_info = SimpleNamespace(builder=sb, file=sdist_file)
            # When we're building both, build the wheel from the unpacked sdist.
            # This helps ensure that the sdist contains all the necessary files.
            if 'wheel' in formats:
                with unpacked_tarball(sdist_file) as tmpdir:
                    log.debug('Building wheel from unpacked sdist %s', tmpdir)
                    tmp_ini_file = Path(tmpdir, ini_file.name)
                    wheel_info = make_wheel_in(tmp_ini_file, dist_dir)
        elif 'wheel' in formats:
            wheel_info = make_wheel_in(ini_file, dist_dir)
    except ConfigError as e:
        sys.exit('Config error: {}'.format(e))

    return SimpleNamespace(wheel=wheel_info, sdist=sdist_info)