File tree Expand file tree Collapse file tree 3 files changed +72
-0
lines changed
variantlib/commands/plugins Expand file tree Collapse file tree 3 files changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ show = "variantlib.commands.config.show:show"
77
77
[project .entry-points ."variantlib .actions .plugins" ]
78
78
list = " variantlib.commands.plugins.list_plugins:list_plugins"
79
79
get-supported-configs = " variantlib.commands.plugins.get_supported_configs:get_supported_configs"
80
+ validate-property = " variantlib.commands.plugins.validate_property:validate_property"
80
81
81
82
[tool .pytest .ini_options ]
82
83
testpaths = [" tests/" ]
Original file line number Diff line number Diff line change @@ -66,3 +66,33 @@ def test_plugins_get_supported_configs_filter_feature(
66
66
test_namespace :: name1 :: val1b
67
67
"""
68
68
)
69
+
70
+
71
+ def test_plugins_validate_property (
72
+ capsys : pytest .CaptureFixture [str ], mocked_entry_points : None
73
+ ) -> None :
74
+ main (
75
+ [
76
+ "plugins" ,
77
+ "validate-property" ,
78
+ "test_namespace :: name1 :: val1a" ,
79
+ "test_namespace :: name1::val1b" ,
80
+ "test_namespace :: name2 :: val2a" ,
81
+ "second_namespace:: name1:: val1a" ,
82
+ "second_namespace::name3 :: val3a" ,
83
+ "test_namespace :: name3 :: val3a" ,
84
+ "unknown_namespace::foo::bar" ,
85
+ ]
86
+ )
87
+ assert (
88
+ capsys .readouterr ().out
89
+ == """\
90
+ test_namespace :: name1 :: val1a : valid
91
+ test_namespace :: name1 :: val1b : valid
92
+ test_namespace :: name2 :: val2a : valid
93
+ second_namespace :: name1 :: val1a : invalid
94
+ second_namespace :: name3 :: val3a : valid
95
+ test_namespace :: name3 :: val3a : invalid
96
+ unknown_namespace :: foo :: bar : no-plugin
97
+ """
98
+ )
Original file line number Diff line number Diff line change
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import logging
5
+ import sys
6
+ from typing import TYPE_CHECKING
7
+
8
+ from variantlib import __package_name__
9
+ from variantlib .models .variant import VariantProperty
10
+
11
+ if TYPE_CHECKING :
12
+ from variantlib .plugins .loader import BasePluginLoader
13
+
14
+
15
+ logger = logging .getLogger (__name__ )
16
+
17
+ res_map = {
18
+ False : "invalid" ,
19
+ True : "valid" ,
20
+ None : "no-plugin" ,
21
+ }
22
+
23
+
24
+ def validate_property (args : list [str ], plugin_loader : BasePluginLoader ) -> None :
25
+ parser = argparse .ArgumentParser (
26
+ prog = f"{ __package_name__ } plugins validate-property" ,
27
+ description = "CLI interface to validate properties" ,
28
+ )
29
+ parser .add_argument (
30
+ "property" ,
31
+ nargs = "+" ,
32
+ type = VariantProperty .from_str ,
33
+ help = "One or more properties to validate" ,
34
+ )
35
+
36
+ parsed_args = parser .parse_args (args )
37
+ validation_result = plugin_loader .validate_properties (parsed_args .property )
38
+ for vprop in parsed_args .property :
39
+ sys .stdout .write (
40
+ f"{ vprop .to_str ()} : { res_map [validation_result .results [vprop ]]} \n "
41
+ )
You can’t perform that action at this time.
0 commit comments