Skip to content

Commit 5ba353d

Browse files
Commands Cleanup
1 parent 34cdf09 commit 5ba353d

13 files changed

+43
-41
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<img src="https://img.shields.io/github/license/wheelnext/variantlib?style=for-the-badge">
1010
</a>
1111
<a href="https://discord.com/channels/803025117553754132/1279204588196597811">
12-
<img src="https://img.shields.io/badge/Discord_PyPA-WheelNext-blueviolet?style=for-the-badge" />
12+
<img src="https://img.shields.io/badge/Discord_PyPA-WheelNext-blueviolet?style=for-the-badge" />
1313
</a>
1414
<a href="https://wheelnext.dev">
1515
<img src="https://img.shields.io/badge/WheelNext.dev-lightblue?style=for-the-badge" />
@@ -18,6 +18,6 @@
1818

1919
<p align="center">
2020
<a href="https://deepwiki.com/wheelnext/variantlib">
21-
<img src="https://img.shields.io/badge/Deep_Wiki-VariantLib-lightblue?style=for-the-badge" />
21+
<img src="https://img.shields.io/badge/Deep_Wiki-VariantLib-lightblue?style=for-the-badge" />
2222
</a>
23-
</p>
23+
</p>

variantlib/commands/analyze_platform.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import argparse
44
import logging
5+
import sys
56

67
from variantlib.loader import PluginLoader
78

89
logger = logging.getLogger(__name__)
9-
logger.setLevel(logging.INFO)
1010

1111

1212
def analyze_platform(args: list[str]) -> None:
@@ -16,13 +16,13 @@ def analyze_platform(args: list[str]) -> None:
1616
)
1717
_ = parser.parse_args(args)
1818

19-
logger.info("Analyzing the platform ... \n")
19+
logger.info("Analyzing the platform ...\n")
2020
variant_cfgs = PluginLoader.get_supported_configs().values()
2121

22-
for variant_cfg in variant_cfgs:
23-
logger.info(variant_cfg.pretty_print())
24-
print() # visual spacing # noqa: T201
22+
# We have to flush the logger handlers to ensure that all logs are printed
23+
for handler in logger.handlers:
24+
handler.flush()
2525

26-
logger.info(
27-
f"Total Variant Hashes: {2 ** sum(len(variant_cfg.configs) for variant_cfg in variant_cfgs):,}" # noqa: G004, E501
28-
)
26+
for variant_cfg in variant_cfgs:
27+
for line in variant_cfg.pretty_print().splitlines():
28+
sys.stdout.write(f"{line}\n")

variantlib/commands/analyze_wheel.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from variantlib.models.variant import VariantProperty
1717

1818
logger = logging.getLogger(__name__)
19-
logger.setLevel(logging.INFO)
2019

2120

2221
def pretty_print(vdesc: VariantDescription, providers: list[ProviderPackage]) -> str:
@@ -101,5 +100,9 @@ def analyze_wheel(args: list[str]) -> None:
101100
)
102101
]
103102

103+
# We have to flush the logger handlers to ensure that all logs are printed
104+
for handler in logger.handlers:
105+
handler.flush()
106+
104107
for line in pretty_print(vdesc=vdesc, providers=providers).splitlines():
105108
sys.stdout.write(f"{line}\n")

variantlib/commands/config/list_paths.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def get_localzone() -> None:
1616

1717

1818
logger = logging.getLogger(__name__)
19-
logger.setLevel(logging.INFO)
2019

2120

2221
def list_paths(args: list[str]) -> None:

variantlib/commands/config/setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from variantlib.models.variant import VariantProperty
1818

1919
logger = logging.getLogger(__name__)
20-
logger.setLevel(logging.INFO)
2120

2221
INSTRUCTIONS = """
2322
----------------------------------------------------------------------------#

variantlib/commands/generate_index_json.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from variantlib.models.variant import VariantProperty
2222

2323
logger = logging.getLogger(__name__)
24-
logger.setLevel(logging.INFO)
2524

2625

2726
def generate_index_json(args: list[str]) -> None:
@@ -66,10 +65,6 @@ def generate_index_json(args: list[str]) -> None:
6665
)
6766
continue
6867

69-
# if vhash == "0" * VARIANT_HASH_LEN:
70-
# known_variants[vhash] = VariantDescription()
71-
# continue
72-
7368
with zipfile.ZipFile(wheel, "r") as zip_file:
7469
# Find the METADATA file
7570
for name in zip_file.namelist():

variantlib/commands/make_variant.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from variantlib.errors import ValidationError
1919

2020
logger = logging.getLogger(__name__)
21-
logger.setLevel(logging.INFO)
2221

2322
METADATA_POLICY = email.policy.EmailPolicy(
2423
utf8=True,
@@ -72,6 +71,12 @@ def make_variant(args: list[str]) -> None:
7271
help="make the variant a `null variant` - no variant property.",
7372
)
7473

74+
parser.add_argument(
75+
"--skip-plugin-validation",
76+
action="store_true",
77+
help="allow to register invalid or unknown variant properties",
78+
)
79+
7580
parsed_args = parser.parse_args(args)
7681

7782
input_filepath: pathlib.Path = parsed_args.input_filepath
@@ -82,6 +87,7 @@ def make_variant(args: list[str]) -> None:
8287
output_directory,
8388
is_null_variant=parsed_args.null_variant,
8489
properties=parsed_args.properties,
90+
validate_properties=not parsed_args.skip_plugin_validation,
8591
)
8692

8793

@@ -90,6 +96,7 @@ def _make_variant(
9096
output_directory: pathlib.Path,
9197
is_null_variant: bool,
9298
properties: list[VariantProperty],
99+
validate_properties: bool = True,
93100
) -> None:
94101
# Input Validation
95102
if not input_filepath.is_file():
@@ -109,20 +116,21 @@ def _make_variant(
109116
# Transform properties into a VariantDescription
110117
vdesc = VariantDescription(properties=properties)
111118

112-
# Verify whether the variant properties are valid
113-
vdesc_valid = validate_variant(vdesc)
114-
if vdesc_valid.invalid_properties:
115-
raise ValidationError(
116-
"The following variant properties are invalid according to the "
117-
"plugins: "
118-
f"{', '.join(x.to_str() for x in vdesc_valid.invalid_properties)}"
119-
)
120-
if vdesc_valid.unknown_properties:
121-
raise ValidationError(
122-
"The following variant properties use namespaces that are not provided "
123-
"by any installed plugin: "
124-
f"{', '.join(x.to_str() for x in vdesc_valid.unknown_properties)}"
125-
)
119+
if validate_properties:
120+
# Verify whether the variant properties are valid
121+
vdesc_valid = validate_variant(vdesc)
122+
if vdesc_valid.invalid_properties:
123+
raise ValidationError(
124+
"The following variant properties are invalid according to the "
125+
"plugins: "
126+
f"{', '.join(x.to_str() for x in vdesc_valid.invalid_properties)}"
127+
)
128+
if vdesc_valid.unknown_properties:
129+
raise ValidationError(
130+
"The following variant properties use namespaces that are not "
131+
"provided by any installed plugin: "
132+
f"{', '.join(x.to_str() for x in vdesc_valid.unknown_properties)}"
133+
)
126134
else:
127135
# Create a null variant
128136
vdesc = VariantDescription()

variantlib/commands/plugins/_display_configs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from variantlib.models.provider import ProviderConfig
1111

1212
logger = logging.getLogger(__name__)
13-
logger.setLevel(logging.INFO)
1413

1514

1615
def display_configs(

variantlib/commands/plugins/get_all_configs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from variantlib.loader import PluginLoader
88

99
logger = logging.getLogger(__name__)
10-
logger.setLevel(logging.INFO)
1110

1211

1312
def get_all_configs(args: list[str]) -> None:

variantlib/commands/plugins/get_supported_configs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from variantlib.loader import PluginLoader
88

99
logger = logging.getLogger(__name__)
10-
logger.setLevel(logging.INFO)
1110

1211

1312
def get_supported_configs(args: list[str]) -> None:

variantlib/commands/plugins/list_plugins.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from variantlib.loader import PluginLoader
88

99
logger = logging.getLogger(__name__)
10-
logger.setLevel(logging.INFO)
1110

1211

1312
def list_plugins(args: list[str]) -> None:

variantlib/commands/unmake_variant.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from variantlib.constants import VALIDATION_WHEEL_NAME_REGEX
1717

1818
logger = logging.getLogger(__name__)
19-
logger.setLevel(logging.INFO)
2019

2120
METADATA_POLICY = email.policy.EmailPolicy(
2221
utf8=True,

variantlib/models/provider.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,16 @@ class ProviderConfig(BaseModel):
8787
)
8888

8989
def pretty_print(self) -> str:
90-
result_str = f"{'#' * 20} Provider Config: `{self.namespace}` {'#' * 20}"
90+
result_str = f"\n{'#' * 20} Provider Config: `{self.namespace}` {'#' * 20}"
91+
header_length = len(result_str) - 1
92+
9193
for kid, vconfig in enumerate(self.configs):
9294
result_str += (
9395
f"\n\t- Variant Config [{kid + 1:03d}]: "
9496
f"{vconfig.name} :: {vconfig.values}"
9597
)
96-
result_str += f"\n{'#' * 80}\n"
98+
99+
result_str += f"\n{'#' * header_length}\n"
97100
return result_str
98101

99102
def to_list_of_properties(self) -> Generator[VariantProperty]:

0 commit comments

Comments
 (0)