Skip to content

Commit

Permalink
Replace get() calls with direct data access in discover/shell plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
happz committed Oct 7, 2024
1 parent 14d60dc commit 0ca0354
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions tmt/steps/discover/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class DiscoverShellData(tmt.steps.discover.DiscoverStepData):
default=None,
help="Branch, tag or commit specifying the git revision.")

keep_git_metadata: Optional[bool] = field(
keep_git_metadata: bool = field(
option="--keep-git-metadata",
is_flag=True,
default=False,
Expand Down Expand Up @@ -267,11 +267,9 @@ class DiscoverShell(tmt.steps.discover.DiscoverPlugin[DiscoverShellData]):
def show(self, keys: Optional[list[str]] = None) -> None:
""" Show config details """
super().show([])
# FIXME: cast() - typeless "dispatcher" method
tests = cast(list[TestDescription], self.get('tests'))
if tests:
test_names = [test.name for test in tests]
click.echo(tmt.utils.format('tests', test_names))

if self.data.tests:
click.echo(tmt.utils.format('tests', [test.name for test in self.data.tests]))

def fetch_remote_repository(
self,
Expand Down Expand Up @@ -332,17 +330,15 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:

# dist-git related
sourcedir = self.workdir / 'source'
dist_git_source = self.get('dist-git-source', False)

# Fetch remote repository related
url = self.get('url', None)
ref = self.get('ref', None)

# Git metadata are necessary for dist_git_source
keep_git_metadata = True if dist_git_source else self.get('keep_git_metadata', False)
keep_git_metadata = True if self.data.dist_git_source \
else self.data.keep_git_metadata

if url:
self.fetch_remote_repository(url, ref, testdir, keep_git_metadata)
if self.data.url:
self.fetch_remote_repository(self.data.url, self.data.ref, testdir, keep_git_metadata)
else:
# Symlink tests directory to the plan work tree
assert self.step.plan.worktree # narrow type
Expand Down Expand Up @@ -382,7 +378,7 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
if not data.duration:
data.duration = tmt.base.DEFAULT_TEST_DURATION_L2
# Add source dir path variable
if dist_git_source:
if self.data.dist_git_source:
data.environment['TMT_SOURCE_DIR'] = EnvVarValue(sourcedir)

# Create a simple fmf node, with correct name. Emit only keys and values
Expand All @@ -397,14 +393,14 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
}
tests.child(data.name, test_fmf_keys)

if dist_git_source:
if self.data.dist_git_source:
assert self.step.plan.my_run is not None # narrow type
assert self.step.plan.my_run.tree is not None # narrow type
assert self.step.plan.my_run.tree.root is not None # narrow type
try:
run_result = self.run(
Command("git", "rev-parse", "--show-toplevel"),
cwd=testdir if url else self.step.plan.my_run.tree.root,
cwd=testdir if self.data.url else self.step.plan.my_run.tree.root,
ignore_dry=True)
assert run_result.stdout is not None
git_root = Path(run_result.stdout.strip('\n'))
Expand All @@ -415,17 +411,15 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
f"Directory '{self.step.plan.my_run.tree.root}' "
f"is not a git repository.")
try:
download_only: bool = self.get('dist-git-download-only')
self.download_distgit_source(
distgit_dir=git_root,
target_dir=sourcedir,
handler_name=self.get('dist-git-type'),
)
handler_name=self.data.dist_git_type)
# Copy rest of files so TMT_SOURCE_DIR has patches, sources and spec file
# FIXME 'worktree' could be used as sourcedir when 'url' is not set
shutil.copytree(git_root, sourcedir, symlinks=True, dirs_exist_ok=True)

if download_only:
if self.data.dist_git_download_only:
self.debug("Do not extract sources as 'download_only' is set.")
else:
# Check if prepare is enabled, warn user if not
Expand All @@ -449,7 +443,7 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
# Propagate `where` key and TMT_SOURCE_DIR
for test in self._tests:
test.where = cast(tmt.steps.discover.DiscoverStepData, self.data).where
if dist_git_source:
if self.data.dist_git_source:
test.environment['TMT_SOURCE_DIR'] = EnvVarValue(sourcedir)

def tests(
Expand Down

0 comments on commit 0ca0354

Please sign in to comment.