Skip to content

Commit

Permalink
feat: use mandatory adoptable fields list
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Matsuoka <claudio.matsuoka@canonical.com>
  • Loading branch information
cmatsuoka committed Feb 22, 2024
1 parent ea5f528 commit a454ec2
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion requirements-devel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions snapcraft/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)


Expand Down
4 changes: 3 additions & 1 deletion snapcraft/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/models/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down

0 comments on commit a454ec2

Please sign in to comment.