From 6ef6be52c1cd66245fc7f13a3c472024e10c3c1a Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Mon, 20 Apr 2020 20:30:17 +0900 Subject: Replace format-version with min-version * "min-version" is specified as a . point version and uses the installed BuildStream version instead of having a separate versioning number for the format. * The presence of "format-version" is now used to indicate that we might be loading a BuildStream 1 project. * For now, where parsing the version at startup is concerned, and also where `bst init` is concerned, we artificially bump the detected BuildStream version to 2.0 if we detect a version < 2.0, these exceptions can be removed once 2.0 is tagged and released. Summary of changes: _project.py: Now parse "min-version" and detect "format-version" to warn about loading a BuildStream 1 project _versions.py: Remove obsolete BST_FORMAT_VERSION numbers from here data/projectconfig.yaml: Remove old "format-version" from defaults utils.py: Added new private _parse_version() helper function, and another _get_bst_api_version() to get an adjusted API version. frontend/app.py, frontend/cli.py: Updated `bst init` implementation testing (buildstream.testing): Updated testing utilities to generate and use projects with min-version instead of format-version. tests and examples: Updated to use min-version across the board. --- tests/frontend/init.py | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'tests/frontend/init.py') diff --git a/tests/frontend/init.py b/tests/frontend/init.py index 78aa3eb19..db1b9c955 100644 --- a/tests/frontend/init.py +++ b/tests/frontend/init.py @@ -6,9 +6,24 @@ import pytest from buildstream.testing import cli # pylint: disable=unused-import from buildstream import _yaml +from buildstream import utils from buildstream._frontend.app import App from buildstream.exceptions import ErrorDomain, LoadErrorReason -from buildstream._versions import BST_FORMAT_VERSION + + +def get_default_min_version(): + bst_major, bst_minor = utils.get_bst_version() + + # For the version check, artificially set the version to at least + # version 2.0 + # + # TODO: Remove this code block after releasing 2.0 + # + if bst_major < 2: + bst_major = 2 + bst_minor = 0 + + return "{}.{}".format(bst_major, bst_minor) def test_defaults(cli, tmpdir): @@ -20,7 +35,7 @@ def test_defaults(cli, tmpdir): project_conf = _yaml.load(project_path) assert project_conf.get_str("name") == "foo" - assert project_conf.get_str("format-version") == str(BST_FORMAT_VERSION) + assert project_conf.get_str("min-version") == get_default_min_version() assert project_conf.get_str("element-path") == "elements" @@ -29,13 +44,13 @@ def test_all_options(cli, tmpdir): project_path = os.path.join(project, "project.conf") result = cli.run( - args=["init", "--project-name", "foo", "--format-version", "2", "--element-path", "ponies", project] + args=["init", "--project-name", "foo", "--min-version", "2.0", "--element-path", "ponies", project] ) result.assert_success() project_conf = _yaml.load(project_path) assert project_conf.get_str("name") == "foo" - assert project_conf.get_str("format-version") == str(2) + assert project_conf.get_str("min-version") == "2.0" assert project_conf.get_str("element-path") == "ponies" elements_dir = os.path.join(project, "ponies") @@ -68,7 +83,7 @@ def test_force_overwrite_project(cli, tmpdir): project_conf = _yaml.load(project_path) assert project_conf.get_str("name") == "foo" - assert project_conf.get_str("format-version") == str(BST_FORMAT_VERSION) + assert project_conf.get_str("min-version") == get_default_min_version() def test_relative_path_directory_as_argument(cli, tmpdir): @@ -82,7 +97,7 @@ def test_relative_path_directory_as_argument(cli, tmpdir): project_conf = _yaml.load(project_path) assert project_conf.get_str("name") == "foo" - assert project_conf.get_int("format-version") == BST_FORMAT_VERSION + assert project_conf.get_str("min-version") == get_default_min_version() assert project_conf.get_str("element-path") == "elements" @@ -97,10 +112,10 @@ def test_bad_project_name(cli, tmpdir, project_name): result.assert_main_error(ErrorDomain.LOAD, LoadErrorReason.INVALID_SYMBOL_NAME) -@pytest.mark.parametrize("format_version", [(str(-1)), (str(BST_FORMAT_VERSION + 1))]) -def test_bad_format_version(cli, tmpdir, format_version): - result = cli.run(args=["init", "--project-name", "foo", "--format-version", format_version, str(tmpdir)]) - result.assert_main_error(ErrorDomain.APP, "invalid-format-version") +@pytest.mark.parametrize("min_version", [("-1"), ("1.4"), ("2.900"), ("abc")]) +def test_bad_min_version(cli, tmpdir, min_version): + result = cli.run(args=["init", "--project-name", "foo", "--min-version", min_version, str(tmpdir)]) + result.assert_main_error(ErrorDomain.APP, "invalid-min-version") @pytest.mark.parametrize("element_path", [("/absolute/path"), ("../outside/of/project")]) @@ -124,7 +139,7 @@ def test_element_path_interactive(cli, tmp_path, monkeypatch, element_path): return DummyInteractiveApp(*args, **kwargs) def _init_project_interactive(self, *args, **kwargs): # pylint: disable=arguments-differ - return ("project_name", "0", element_path) + return ("project_name", "2.0", element_path) monkeypatch.setattr(App, "create", DummyInteractiveApp.create) @@ -136,5 +151,5 @@ def test_element_path_interactive(cli, tmp_path, monkeypatch, element_path): project_conf = _yaml.load(str(project_conf_path)) assert project_conf.get_str("name") == "project_name" - assert project_conf.get_str("format-version") == "0" + assert project_conf.get_str("min-version") == "2.0" assert project_conf.get_str("element-path") == element_path -- cgit v1.2.1