Exemplo n.º 1
0
def setup_args(config_path=Path("pyproject.toml")):
    cfg = config.read_flit_config(config_path)
    module = common.Module(cfg.module, config_path.parent)
    metadata = common.make_metadata(module, cfg)
    kwargs = {}
    for st_field, metadata_field in field_map.items():
        val = getattr(metadata, metadata_field, None)
        if val is not None:
            kwargs[st_field] = val
        else:
            msg = f"{metadata_field} not found in {dir(metadata)}"
            assert metadata_field in {"license"}, msg
    kwargs["packages"] = setuptools.find_packages(
        include=[metadata.name + "*"])
    if metadata.requires_dist:
        kwargs["install_requires"] = [
            req for req in metadata.requires_dist if "extra ==" not in req
        ]
    if cfg.reqs_by_extra:
        kwargs["extras_require"] = cfg.reqs_by_extra
    scripts = cfg.entrypoints.get("console_scripts")
    if scripts is not None:
        kwargs["entry_points"] = dict(
            console_scipts=[" = ".join(ep) for ep in scripts.items()])
    kwargs["include_package_data"] = True
    kwargs["package_data"] = {
        module.name:
        [re.escape(f[len(module.name) + 1:]) for f in find_files(module.path)]
    }
    return kwargs
Exemplo n.º 2
0
def test_load_pep621_nodynamic():
    inf = config.read_flit_config(samples_dir / 'pep621_nodynamic' / 'pyproject.toml')
    assert inf.module == 'module1'
    assert inf.metadata['name'] == 'module1'
    assert inf.metadata['version'] == '0.3'
    assert inf.metadata['summary'] == 'Statically specified description'
    assert set(inf.dynamic_metadata) == set()
Exemplo n.º 3
0
def test_make_metadata():
    project_dir = samples_dir / 'pep621_nodynamic'
    ini_info = config.read_flit_config(project_dir / 'pyproject.toml')
    module = Module(ini_info.module, project_dir)
    print(module.file)
    md = make_metadata(module, ini_info)
    assert md.version == '0.3'
    assert md.summary == "Statically specified description"
Exemplo n.º 4
0
def test_extras():
    info = config.read_flit_config(samples_dir / 'extras.toml')
    requires_dist = set(info.metadata['requires_dist'])
    assert requires_dist == {
        'toml',
        'pytest ; extra == "test"',
        'requests ; extra == "custom"',
    }
    assert set(info.metadata['provides_extra']) == {'test', 'custom'}
Exemplo n.º 5
0
def test_load_pep621():
    inf = config.read_flit_config(samples_dir / 'pep621' / 'pyproject.toml')
    assert inf.module == 'module1a'
    assert inf.metadata['name'] == 'module1'
    assert inf.metadata['description_content_type'] == 'text/x-rst'
    assert inf.metadata['requires_dist'] == ["requests >= 2.18", "docutils"]
    assert inf.metadata['author_email'] == "Sir Röbin <*****@*****.**>"
    assert inf.entrypoints['flit_test_example']['foo'] == 'module1:main'
    assert set(inf.dynamic_metadata) == {'version', 'description'}
Exemplo n.º 6
0
def test_load_pep621_nodynamic():
    inf = config.read_flit_config(samples_dir / 'pep621_nodynamic' /
                                  'pyproject.toml')
    assert inf.module == 'module1'
    assert inf.metadata['name'] == 'module1'
    assert inf.metadata['version'] == '0.3'
    assert inf.metadata['summary'] == 'Statically specified description'
    assert set(inf.dynamic_metadata) == set()

    # Filling reqs_by_extra when dependencies were specified but no optional
    # dependencies was a bug.
    assert inf.reqs_by_extra == {'.none': ['requests >= 2.18', 'docutils']}
Exemplo n.º 7
0
def test_load_pep621():
    inf = config.read_flit_config(samples_dir / 'pep621' / 'pyproject.toml')
    assert inf.module == 'module1a'
    assert inf.metadata['name'] == 'module1'
    assert inf.metadata['description_content_type'] == 'text/x-rst'
    # Remove all whitespace from requirements so we don't check exact format:
    assert {r.replace(' ', '') for r in inf.metadata['requires_dist']} == {
        'docutils',
        'requests>=2.18',
        'pytest;extra=="test"',  # from [project.optional-dependencies]
        'mock;extra=="test"and(python_version<\'3.6\')',
    }
    assert inf.metadata['author_email'] == "Sir Röbin <*****@*****.**>"
    assert inf.entrypoints['flit_test_example']['foo'] == 'module1:main'
    assert set(inf.dynamic_metadata) == {'version', 'description'}
Exemplo n.º 8
0
def test_bad_description_extension(caplog):
    info = config.read_flit_config(samples_dir / 'bad-description-ext.toml')
    assert info.metadata['description_content_type'] is None
    assert any((r.levelno == logging.WARN and "Unknown extension" in r.msg)
               for r in caplog.records)
Exemplo n.º 9
0
def test_missing_description_file():
    with pytest.raises(config.ConfigError,
                       match=r"Description file .* does not exist"):
        config.read_flit_config(samples_dir / 'missing-description-file.toml')
Exemplo n.º 10
0
def test_description_file():
    info = config.read_flit_config(samples_dir / 'package1.toml')
    assert info.metadata['description'] == \
        "Sample description for test.\n"
    assert info.metadata['description_content_type'] == 'text/x-rst'
Exemplo n.º 11
0
def test_misspelled_key():
    with pytest.raises(config.ConfigError) as e_info:
        config.read_flit_config(samples_dir / 'misspelled-key.toml')

    assert 'description-file' in str(e_info.value)
Exemplo n.º 12
0
def test_load_toml():
    inf = config.read_flit_config(samples_dir / 'module1-pkg.toml')
    assert inf.module == 'module1'
    assert inf.metadata['home_page'] == 'http://github.com/sirrobin/module1'
Exemplo n.º 13
0
def test_requires_extra_env_marker():
    info = config.read_flit_config(samples_dir / 'requires-extra-envmark.toml')
    assert info.metadata['requires_dist'][0].startswith('pathlib2 ;')
Exemplo n.º 14
0
def test_extras_dev_warning(caplog):
    info = config.read_flit_config(samples_dir / 'requires-dev.toml')
    assert '"dev-requires = ..." is obsolete' in caplog.text
    assert set(info.metadata['requires_dist']) == {'apackage ; extra == "dev"'}
Exemplo n.º 15
0
def test_extras_dev_conflict():
    with pytest.raises(config.ConfigError, match=r'dev-requires'):
        config.read_flit_config(samples_dir / 'extras-dev-conflict.toml')
Exemplo n.º 16
0
def load_project():
    tp = Path('pyproject.toml')
    fc = read_flit_config(tp)
    pyp = toml.loads(tp.read_text())
    return pyp, fc