Skip to content

Commit

Permalink
Replace fmf_root property with anchor_path
Browse files Browse the repository at this point in the history
  • Loading branch information
Ismail Ibrahim Quwarah committed Sep 24, 2024
1 parent a778269 commit 9a397b7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
17 changes: 11 additions & 6 deletions tmt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,13 @@ class FmfId(
VALID_KEYS: ClassVar[list[str]] = ['url', 'ref', 'path', 'name']

#: Keys that are present, might be set, but shall not be exported.
NONEXPORTABLE_KEYS: ClassVar[list[str]] = ['fmf_root', 'git_root', 'default_branch']
NONEXPORTABLE_KEYS: ClassVar[list[str]] = [
'fmf_root', 'anchor_path', 'git_root', 'default_branch']

# Save context of the ID for later - there are places where it matters,
# e.g. to not display `ref` under some conditions.
fmf_root: Optional[Path] = None
anchor_path: Optional[Path] = None
git_root: Optional[Path] = None
default_branch: Optional[str] = None

Expand Down Expand Up @@ -771,17 +773,20 @@ def _fmf_id(self) -> None:

# TODO: cached_property candidates
@property
def fmf_root(self) -> Path:
def fmf_root(self) -> Optional[Path]:
# Check if fmf root exists
try:
return Path(self.node.root)
except TypeError:
raise tmt.utils.GeneralError(
"No fmf root found. Directory is not initialized with `tmt init`")
return None

@property
def anchor_path(self) -> Path:
return self.fmf_root or Path.cwd()

@property
def git_root(self) -> Optional[Path]:
return tmt.utils.git.git_root(fmf_root=self.fmf_root, logger=self._logger)
return tmt.utils.git.git_root(fmf_root=self.anchor_path, logger=self._logger)

# Caching properties does not play nicely with mypy and annotations,
# and constructing a workaround would be hard because of support of
Expand All @@ -799,7 +804,7 @@ def fmf_id(self) -> FmfId:

return tmt.utils.fmf_id(
name=self.name,
fmf_root=self.fmf_root,
fmf_root=self.anchor_path,
logger=self._logger)

@functools.cached_property
Expand Down
2 changes: 1 addition & 1 deletion tmt/steps/prepare/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def go(

guest.ansible(
playbook_path,
playbook_root=self.step.plan.fmf_root,
playbook_root=self.step.plan.anchor_path,
extra_args=self.data.extra_args)

return results
Expand Down
2 changes: 1 addition & 1 deletion tmt/utils/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def validate_git_status(test: 'tmt.base.Test') -> tuple[bool, str]:
"""
sources = [
*test.fmf_sources,
test.fmf_root / '.fmf' / 'version'
test.anchor_path / '.fmf' / 'version'
]

# Use tmt's run instead of subprocess.run
Expand Down

0 comments on commit 9a397b7

Please sign in to comment.