Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .packit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ _:
- &copr-under-packit
job: copr_build
additional_repos:
- copr://@teemtee/stable
- copr://packit/teemtee-fmf-293

# Copr jobs under the teemtee project
- &copr-under-teemtee
Expand Down
26 changes: 13 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,16 @@ repos:
- '--rst-directives'
- 'versionadded,versionchanged'

- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.10.9
hooks:
# Keep pyproject.toml and uv.lock in sync
- id: uv-lock
# Keep pylock.toml in sync
- id: uv-export
args:
- "--frozen"
- "--format=pylock.toml"
- "--output-file=pylock.toml"
- "--all-extras"
- "--quiet"
# - repo: https://github.com/astral-sh/uv-pre-commit
# rev: 0.10.9
# hooks:
# # Keep pyproject.toml and uv.lock in sync
# - id: uv-lock
# # Keep pylock.toml in sync
# - id: uv-export
# args:
# - "--frozen"
# - "--format=pylock.toml"
# - "--output-file=pylock.toml"
# - "--all-extras"
# - "--quiet"
Comment on lines +257 to +269
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The uv-pre-commit hooks are commented out. Revert this change or remove the lines if they are no longer needed for the final implementation.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies = [
"importlib-resources; python_version < '3.12'", # MultiplexedPath is broken on earlier versions
"click>=8.0.3",
"docutils>=0.16",
"fmf>=1.7.0",
"fmf>=1.8.0",
"jinja2>=2.11.3",
"packaging>=20.9",
"pint>=0.16.1",
Expand Down
8 changes: 3 additions & 5 deletions tmt/base/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import fmf
import fmf.base
import fmf.context
import fmf.utils
import jsonschema
from click import confirm, echo
Expand Down Expand Up @@ -60,6 +59,7 @@
container_fields,
field,
)
from tmt.context import TmtContext
from tmt.lint import LinterOutcome, LinterReturn
from tmt.result import ResultInterpret
from tmt.utils import (
Expand Down Expand Up @@ -2387,8 +2387,7 @@ def tree(self) -> fmf.Tree:
raise tmt.utils.GeneralError("Invalid yaml syntax.") from error
# Adjust metadata for current fmf context
self._tree.adjust(
fmf.context.Context(**self.fmf_context),
case_sensitive=False,
TmtContext(**self.fmf_context),
decision_callback=create_adjust_callback(self._logger),
additional_rules=self._additional_rules,
)
Expand Down Expand Up @@ -3532,8 +3531,7 @@ def resolve_dynamic_ref(
if not plan:
raise tmt.utils.FileError("Cannot get plan fmf context to evaluate dynamic ref.")
reference_tree.adjust(
fmf.context.Context(**plan.fmf_context),
case_sensitive=False,
TmtContext(**plan.fmf_context),
decision_callback=create_adjust_callback(logger),
)
# Also temporarily build a plan so that env and context variables are expanded
Expand Down
5 changes: 2 additions & 3 deletions tmt/base/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from typing import TYPE_CHECKING, Any, ClassVar, Optional, Union, cast

import fmf
import fmf.context
import fmf.utils
from click import echo
from fmf.utils import listed # pyright: ignore[reportUnknownVariableType]
Expand Down Expand Up @@ -47,6 +46,7 @@
)
from tmt.base.run import Run
from tmt.container import SpecBasedContainer, container, field
from tmt.context import TmtContext
from tmt.lint import LinterOutcome, LinterReturn
from tmt.utils import (
Command,
Expand Down Expand Up @@ -1530,8 +1530,7 @@ def _convert_node(node: fmf.Tree) -> 'Plan':
# Adjust the imported tree, to let any `adjust` rules defined in it take
# action, including the adjust-plans rules.
node.adjust(
fmf.context.Context(**alteration_fmf_context),
case_sensitive=False,
TmtContext(**alteration_fmf_context),
additional_rules=reference.adjust_plans,
)

Expand Down
1 change: 1 addition & 0 deletions tmt/cli/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def _render_plugins_list_rest(logger: tmt.log.Logger) -> str:
r'prepare.feature': 'prepare/feature plugins',
r'prepare.install': 'prepare/install plugins',
r'prepare.artifact.providers': 'prepare/artifact provider plugins',
r'context': 'Fmf context plugins',
r'step\.([a-z]+)': '{{ MATCH.group(1).capitalize() }} step plugins',
}

Expand Down
31 changes: 31 additions & 0 deletions tmt/context/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from typing import Generic, TypeVar

from fmf.context import Context, ContextDimension, DefaultContextDimension
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Import DistroContext from fmf.context to align with the pull request title and leverage the new distribution-aware context logic introduced in fmf 1.8.0.

Suggested change
from fmf.context import Context, ContextDimension, DefaultContextDimension
from fmf.context import Context, ContextDimension, DefaultContextDimension, DistroContext

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ this is the kind of stuff I have to cope with weekly wit Gemini


import tmt.utils
from tmt.plugins import PluginRegistry

T = TypeVar("T")


class ContextError(tmt.utils.GeneralError):
"""
Error trying to create a context
"""


class TmtDefaultContextDimension(DefaultContextDimension):
case_sensitive = False


class TmtContextDimension(ContextDimension[T], Generic[T]):
_default_dimension_cls = TmtDefaultContextDimension
_registrar = {}
Comment on lines +21 to +23
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Defining _registrar = {} in TmtContextDimension hides all standard dimensions (e.g., arch, distro, os) registered in the base fmf.context.ContextDimension. This will cause TmtContext to lose special matching logic for these dimensions. Remove the explicit registrar definition to inherit the standard one.

Suggested change
class TmtContextDimension(ContextDimension[T], Generic[T]):
_default_dimension_cls = TmtDefaultContextDimension
_registrar = {}
class TmtContextDimension(ContextDimension[T], Generic[T]):
_default_dimension_cls = TmtDefaultContextDimension



class TmtContext(Context):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Inherit TmtContext from DistroContext instead of Context to fulfill the pull request's objective of switching to the distribution-aware context.

Suggested change
class TmtContext(Context):
class TmtContext(DistroContext):

Copy link
Copy Markdown
Member Author

@LecrisUT LecrisUT May 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One typo in the title and it thinks cows grow on trees 🙄

_context_dimensions = TmtContextDimension


_CONTEXT_REGISTRY = PluginRegistry('context')
provides_context = _CONTEXT_REGISTRY.create_decorator()
Comment on lines +30 to +31
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The _CONTEXT_REGISTRY and provides_context decorator are defined but not integrated with TmtContextDimension. Without a mechanism to register these plugins into the fmf dimensions registrar, context plugins will not be recognized during context evaluation.

7 changes: 4 additions & 3 deletions tmt/export/nitrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
cast,
)

import fmf.context
import fmf.utils
from click import echo

import tmt.export
import tmt.utils
from tmt.context import TmtContext
from tmt.utils import ConvertError, Path
from tmt.utils.structured_field import StructuredField
from tmt.utils.themes import style
Expand Down Expand Up @@ -289,9 +290,9 @@ def enabled_for_environment(test: 'tmt.base.core.Test', tcms_notes: str) -> bool
return True

try:
context = fmf.context.Context(**context_dict)
context = TmtContext(**context_dict)
test_node = test.node.copy()
test_node.adjust(context, case_sensitive=False)
test_node.adjust(context)
return tmt.Test(node=test_node, logger=test._logger).enabled
except BaseException as exception:
log.debug(f"Failed to process adjust: {exception}")
Expand Down
1 change: 1 addition & 0 deletions tmt/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def _discover_packages() -> list[tuple[str, Path]]:
('tmt.steps.prepare.feature', Path('steps/prepare/feature')),
('tmt.steps.prepare.artifact.providers', Path('steps/prepare/artifact/providers')),
('tmt.plugins.plan_shapers', Path('plugins/plan_shapers')),
('tmt.context', Path('context')),
]


Expand Down
3 changes: 2 additions & 1 deletion tmt/steps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
option_to_key,
simple_field,
)
from tmt.context import TmtContext
from tmt.options import ClickOptionDecoratorType, option
from tmt.result import ResultOutcome
from tmt.utils import (
Expand Down Expand Up @@ -2305,7 +2306,7 @@ def enabled_by_when(self) -> bool:
Check if the plugin is enabled by 'when' keyword
"""

fmf_context = fmf.context.Context(**self.step.plan.fmf_context)
fmf_context = TmtContext(**self.step.plan.fmf_context)
when_rules = self.get('when', [])
if not when_rules:
# No 'when' -> enabled everywhere
Expand Down
5 changes: 2 additions & 3 deletions tmt/trying.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from typing import Any, Callable, ClassVar, Optional, Union, cast

import fmf
import fmf.context
import fmf.utils

import tmt
Expand All @@ -28,6 +27,7 @@
import tmt.utils
from tmt import Plan
from tmt.base.run import RunData
from tmt.context import TmtContext
from tmt.steps.prepare import PreparePlugin
from tmt.utils import Command, GeneralError, MetadataError, Path
from tmt.utils.themes import style
Expand Down Expand Up @@ -305,8 +305,7 @@ def get_default_plans(self, run: tmt.base.run.Run) -> list[Plan]:
# each user plan in separation and merge them to the main tree.
for user_plan in user_plans:
user_plan.adjust(
fmf.context.Context(**self.tree.fmf_context),
case_sensitive=False,
TmtContext(**self.tree.fmf_context),
decision_callback=tmt.base.core.create_adjust_callback(self._logger),
additional_rules=self.tree._additional_rules,
)
Expand Down
Loading