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)
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"
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"
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)
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"
def test__get_version__invalid_style(config): config["style"] = "invalid" with pytest.raises(ValueError): plugin._get_version(config)
def test__get_version__defaults(config): v, s = plugin._get_version(config) assert v == Version.from_git() assert s == Version.from_git().serialize()