diff --git a/README.md b/README.md index 80752a8..c603271 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # package-build Run: + ```commandline poe run ``` diff --git a/app.py b/app.py index 7ca98a9..589fa94 100644 --- a/app.py +++ b/app.py @@ -11,15 +11,20 @@ column1, column2 = st.columns(2) +df_version_options = hook_metadata.df_version_options + with column1: - df_version: str = st.selectbox(label="DF version", options=hook_metadata.df_versions) - operating_systems: str = st.selectbox(label="Operating system/platform", options=hook_metadata.operating_systems) + df_version: str = st.selectbox(label="DF version", options=sorted(df_version_options, reverse=True)) + operating_systems: str = st.selectbox( + label="Operating system/platform", + options=df_version_options[df_version].operating_systems, + ) with column2: - df_variant: str = st.selectbox(label="DF variant", options=hook_metadata.variants) + df_variant: str = st.selectbox(label="DF variant", options=df_version_options[df_version].variants) dict_entry: DictInfoEntry = st.selectbox(label="Language", options=dict_metadata) -hook_info = hook_metadata.mapping.get((df_version, df_variant, operating_systems)) +hook_info = hook_metadata.hook_info.get((df_version, df_variant, operating_systems)) if not hook_info: st.write("Cannot create package for these parameters") diff --git a/package_build/parse_metadata.py b/package_build/parse_metadata.py index 5d8b09b..128b9eb 100644 --- a/package_build/parse_metadata.py +++ b/package_build/parse_metadata.py @@ -1,14 +1,19 @@ import re +from dataclasses import dataclass, field from typing import NamedTuple from .models import HookInfoEntry +@dataclass +class DFVersionOptions: + variants: set[str] = field(default_factory=set) + operating_systems: set[str] = field(default_factory=set) + + class MetadataParsingResult(NamedTuple): - df_versions: list[str] - variants: list[str] - operating_systems: list[str] - mapping: dict[tuple[str, str, str], HookInfoEntry] + df_version_options: dict[str, DFVersionOptions] + hook_info: dict[tuple[str, str, str], HookInfoEntry] def parse_url(url: str) -> tuple[str, str, str]: @@ -21,21 +26,18 @@ def parse_url(url: str) -> tuple[str, str, str]: def parse_metadata(metadata: list[HookInfoEntry]) -> MetadataParsingResult: - mapping = {} - df_versions = set() - variants = set() - operating_systems = set() + version_to_metadata_mapping: dict[str, DFVersionOptions] = {} + hook_info = {} for item in metadata: version, variant, os = parse_url(item.offsets) - mapping[(version, variant, os)] = item - df_versions.add(version) - variants.add(variant) - operating_systems.add(os) + hook_info[(version, variant, os)] = item + df_version_info = version_to_metadata_mapping.get(version, DFVersionOptions()) + df_version_info.variants.add(variant) + df_version_info.operating_systems.add(os) + version_to_metadata_mapping[version] = df_version_info return MetadataParsingResult( - sorted(df_versions, reverse=True), - sorted(variants), - sorted(operating_systems), - mapping, + version_to_metadata_mapping, + hook_info, )