Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add link config validation #3339

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Add link config validation #3339

wants to merge 4 commits into from

Conversation

therazix
Copy link
Collaborator

@therazix therazix commented Nov 2, 2024

This PR extracts the Config class from tmt.utils into its own file and also introduces config validation using Pydantic models. Currently, validation is applied only to the link configuration.

Resolves #84.

Pull Request Checklist

  • implement the feature
  • write the documentation
  • extend the test coverage
  • update the specification
  • adjust plugin docstring
  • modify the json schema
  • mention the version
  • include a release note

@martinhoyer
Copy link
Collaborator

Nice!
The '<2' limit for pydantic version won't work as Fedora only have v2.
Do you know why epel9 was never updated to v2?

What do you think about this settings for BaseModel?
https://docs.astral.sh/ruff/settings/#lint_flake8-type-checking_runtime-evaluated-base-classes

@therazix
Copy link
Collaborator Author

therazix commented Nov 5, 2024

I updated Pydantic to v2, but I'm not sure how to make it work on EPEL 9, which only supports v1.

Since Pydantic v2 supports backward compatibility with v1 through pydantic.v1, I downgraded to v1 and added Pydantic to tmt._compat. I'm not sure if this is the best solution, but it should work with both versions and ensure that we only use features from v1.

What do you think about this settings for BaseModel?
https://docs.astral.sh/ruff/settings/#lint_flake8-type-checking_runtime-evaluated-base-classes

It may be a good idea to add that. I didn't encounter any problems without it, but it may be needed in some scenarios. Added in 9481860

@therazix therazix force-pushed the fvagner-config branch 2 times, most recently from 58905c0 to 9481860 Compare November 5, 2024 17:31
from tmt._compat.pydantic import BaseModel, Extra


def create_alias(name: str) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like key_to_option, https://github.com/teemtee/tmt/blob/main/tmt/utils/__init__.py#L2926, can we re-use the existing function?

Copy link
Collaborator Author

@therazix therazix Nov 7, 2024

Choose a reason for hiding this comment

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

Replaced in 3fa4ddd.

@psss
Copy link
Collaborator

psss commented Nov 21, 2024

As this is a new approach, it would be good to get a few more reviews. Moving to 1.40.

@psss psss modified the milestones: 1.39, 1.40 Nov 21, 2024
@psss psss added area | config User configuration priority | must high priority, must be included in the next release labels Nov 21, 2024
Copy link
Collaborator

@skycastlelily skycastlelily left a comment

Choose a reason for hiding this comment

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

LGTM:)

@skycastlelily
Copy link
Collaborator

I followed the extended test ,and put the following ~/.config/link.fmf:

issue-tracker:
  - type: jira
    url: https://issues.redhat.com
    tmt-web-url: http://tmt.testing-farm.io/
    unkown: value

Then run tmt link command, got no warning, I guess we could warn users by printing the str(error.cause),
similar as how your test works? @therazix

@therazix
Copy link
Collaborator Author

I followed the extended test ,and put the following ~/.config/link.fmf:

issue-tracker:
  - type: jira
    url: https://issues.redhat.com
    tmt-web-url: http://tmt.testing-farm.io/
    unkown: value

Then run tmt link command, got no warning, I guess we could warn users by printing the str(error.cause), similar as how your test works? @therazix

You are right, thanks for the review. The issue was that SpecificationError was caught by except tmt.utils.MetadataError, so no exception was raised. It should be fixed in 0b7cd2b.

@skycastlelily
Copy link
Collaborator

It should be fixed in 0b7cd2b.

Confirmed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area | config User configuration priority | must high priority, must be included in the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement a user configuration
5 participants