Exemple #1
0
def main() -> None:
    try:
        _enable_cli_mode()
        _parse_args()

        config = get_config()

        pyproject_path = _get_pyproject_path()
        if pyproject_path is None:
            raise RuntimeError("Unable to find pyproject.toml")

        version = _get_version(config)[1]
        print("Version: {}".format(version), file=sys.stderr)
        name = _apply_version(version, config, pyproject_path)
        if _state.project(name).substitutions:
            print("Files with substitutions:", file=sys.stderr)
            for file_name in _state.project(name).substitutions:
                print("  - {}".format(file_name), file=sys.stderr)
        else:
            print("Files with substitutions: none", file=sys.stderr)
    except Exception as e:
        print("Error: {}".format(e), file=sys.stderr)
        sys.exit(1)
Exemple #2
0
def test__get_version__format_jinja_imports_with_module_and_item(config):
    config["format-jinja"] = "{{ pow(2, 3) }}"
    config["format-jinja-imports"] = [{"module": "math", "item": "pow"}]
    _, v = plugin._get_version(config)
    assert v == "8.0"
Exemple #3
0
def test__get_version__format_jinja_imports_with_module_only(config):
    config["format-jinja"] = "{{ math.pow(2, 2) }}"
    config["format-jinja-imports"] = [{"module": "math"}]
    _, v = plugin._get_version(config)
    assert v == "4.0"
Exemple #4
0
def test__get_version__format_jinja_with_enforced_style(config):
    config["format-jinja"] = "{% if true %}1+jinja{% endif %}"
    config["style"] = "pvp"
    with pytest.raises(ValueError):
        plugin._get_version(config)
Exemple #5
0
def test__get_version__format_jinja(config):
    os.environ["FOO"] = "foo"
    config["format-jinja"] = "{% if true %}v1+{{ env['FOO'] }}{% endif %}"
    _, v = plugin._get_version(config)
    assert v == "v1+foo"
Exemple #6
0
def test__get_version__invalid_style(config):
    config["style"] = "invalid"
    with pytest.raises(ValueError):
        plugin._get_version(config)
Exemple #7
0
def test__get_version__defaults(config):
    v, s = plugin._get_version(config)
    assert v == Version.from_git()
    assert s == Version.from_git().serialize()