Skip to content

Commit

Permalink
Move .qubesbuilder file existence check earlier
Browse files Browse the repository at this point in the history
Raise NoQubesBuilderFileError earlier, before checking version.
Otherwise if neither version nor .qubesbuilder files is present, it
resulted in wrong exception (ComponentError "Cannot determine version"
instead of NoQubesBuilderFileError).
  • Loading branch information
marmarek committed Jan 23, 2025
1 parent b2c6bbb commit cef39db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 5 additions & 5 deletions qubesbuilder/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,16 @@ def get_parameters(self, placeholders: dict = None):
if self.is_plugin or not self.has_packages:
return {}

placeholders = placeholders or {}
placeholders.update(
{"@VERSION@": self.get_version(), "@REL@": self.get_release()}
)

if not build_file.exists():
raise NoQubesBuilderFileError(
f"Cannot find '.qubesbuilder' in {self.source_dir}."
)

placeholders = placeholders or {}
placeholders.update(
{"@VERSION@": self.get_version(), "@REL@": self.get_release()}
)

with open(build_file) as f:
data = f.read()

Expand Down
8 changes: 8 additions & 0 deletions tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def test_component_no_source():

def test_component_no_version():
with tempfile.TemporaryDirectory() as source_dir:
with open(f"{source_dir}/.qubesbuilder", "w"):
pass
with pytest.raises(ComponentError) as e:
QubesComponent(source_dir).get_parameters()
msg = f"Cannot determine version for {source_dir}."
Expand All @@ -125,6 +127,8 @@ def test_component_no_version():

def test_component_invalid_version():
with tempfile.TemporaryDirectory() as source_dir:
with open(f"{source_dir}/.qubesbuilder", "w"):
pass
with open(f"{source_dir}/version", "w") as f:
f.write("wrongversion")
with pytest.raises(ComponentError) as e:
Expand All @@ -147,6 +151,8 @@ def test_component_no_release():

def test_component_invalid_release():
with tempfile.TemporaryDirectory() as source_dir:
with open(f"{source_dir}/.qubesbuilder", "w"):
pass
with open(f"{source_dir}/version", "w") as f:
f.write("1.2.3")
with open(f"{source_dir}/rel", "w") as f:
Expand All @@ -159,6 +165,8 @@ def test_component_invalid_release():

def test_component_invalid_release2():
with tempfile.TemporaryDirectory() as source_dir:
with open(f"{source_dir}/.qubesbuilder", "w"):
pass
with open(f"{source_dir}/version", "w") as f:
f.write("1.2.3")
with open(f"{source_dir}/rel", "w") as f:
Expand Down

0 comments on commit cef39db

Please sign in to comment.