From a454ec2082dfe86156a16d4f1e3e8892dd11b2ee Mon Sep 17 00:00:00 2001 From: Claudio Matsuoka Date: Tue, 20 Feb 2024 17:26:47 -0300 Subject: [PATCH] feat: use mandatory adoptable fields list Signed-off-by: Claudio Matsuoka --- requirements-devel.txt | 2 +- requirements.txt | 2 +- setup.py | 2 +- snapcraft/application.py | 1 + snapcraft/models/project.py | 4 +++- tests/unit/models/test_projects.py | 3 ++- 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/requirements-devel.txt b/requirements-devel.txt index 1d4f86410bb..7e1a3f97b61 100644 --- a/requirements-devel.txt +++ b/requirements-devel.txt @@ -11,7 +11,7 @@ click==8.1.7 codespell==2.2.6 colorama==0.4.6 coverage==7.4.0 -craft-application @ git+https://github.com/canonical/craft-application@main +craft-application @ git+https://github.com/cmatsuoka/craft-application@set-adoptable-fields craft-archives==1.1.3 craft-cli==2.5.1 craft-grammar==1.1.2 diff --git a/requirements.txt b/requirements.txt index 241409a334c..8238cce847c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ cffi==1.16.0 chardet==5.2.0 charset-normalizer==3.3.2 click==8.1.7 -craft-application @ git+https://github.com/canonical/craft-application@main +craft-application @ git+https://github.com/cmatsuoka/craft-application@set-adoptable-fields craft-archives==1.1.3 craft-cli==2.5.1 craft-grammar==1.1.2 diff --git a/setup.py b/setup.py index 59bf1538d19..aff890be337 100755 --- a/setup.py +++ b/setup.py @@ -97,7 +97,7 @@ def recursive_data_files(directory, install_directory): "attrs", "catkin-pkg; sys_platform == 'linux'", "click", - "craft-application @ git+https://github.com/canonical/craft-application@main", + "craft-application @ git+https://github.com/cmatsuoka/craft-application@set-adoptable-fields", "craft-archives", "craft-cli", "craft-grammar", diff --git a/snapcraft/application.py b/snapcraft/application.py index d31b939ea41..43f907bee7b 100644 --- a/snapcraft/application.py +++ b/snapcraft/application.py @@ -111,6 +111,7 @@ def get_build_plan(self) -> List[BuildInfo]: BuildPlannerClass=SnapcraftBuildPlanner, source_ignore_patterns=["*.snap"], project_variables=["version", "grade"], + mandatory_adoptable_fields=["version", "summary", "description"], ) diff --git a/snapcraft/models/project.py b/snapcraft/models/project.py index 5d323a60a6f..79b207443e6 100644 --- a/snapcraft/models/project.py +++ b/snapcraft/models/project.py @@ -500,7 +500,9 @@ def _validate_slots(cls, slots): def _validate_adoptable_fields(cls, values): for field in MANDATORY_ADOPTABLE_FIELDS: if field not in values and "adopt-info" not in values: - raise ValueError(f"Snap {field} is required if not using adopt-info") + raise ValueError( + f"Required field '{field}' is not set and 'adopt-info' not used." + ) return values @pydantic.root_validator(pre=True) diff --git a/tests/unit/models/test_projects.py b/tests/unit/models/test_projects.py index ad0ee494f7d..7787822a5ee 100644 --- a/tests/unit/models/test_projects.py +++ b/tests/unit/models/test_projects.py @@ -188,7 +188,7 @@ def test_mandatory_adoptable_fields_definition(self): def test_adoptable_fields(self, field, project_yaml_data): data = project_yaml_data() data.pop(field) - error = f"Snap {field} is required if not using adopt-info" + error = f"Required field '{field}' is not set and 'adopt-info' not used." with pytest.raises(errors.ProjectValidationError, match=error): Project.unmarshal(data) @@ -203,6 +203,7 @@ def test_adoptable_field_not_required(self, field, project_yaml_data): @pytest.mark.parametrize("field", MANDATORY_ADOPTABLE_FIELDS) def test_adoptable_field_assignment(self, field, project_yaml_data): data = project_yaml_data() + data["adopt-info"] = "part1" project = Project.unmarshal(data) setattr(project, field, None)