-
Notifications
You must be signed in to change notification settings - Fork 0
chore: center layout elements and align widths #15
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
Open
Yasansvr
wants to merge
3
commits into
dev
Choose a base branch
from
ui-layout
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ authors = [ | |
| ] | ||
| dependencies = [ | ||
| "textual", | ||
| "PyYAML", | ||
| ] | ||
|
|
||
| [project.scripts] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| merchant: | ||
| name: BitPolito Shop | ||
| headline: Custom terminal storefront | ||
| location: Torino , Italy | ||
| promise: We sell custom things | ||
| catalog: | ||
| - sku: item-01 | ||
| name: BitPolito T-shirt | ||
| tagline: A very custom item | ||
| description: Blue T-shirt | ||
| category: Tshirt | ||
| price_sats: 100000 | ||
| stock: 5 | ||
| features: | ||
| - Custom feature 1 | ||
| - Custom feature 2 | ||
|
|
||
| - sku: item-02 | ||
| name: BitPolito Cap | ||
| tagline: Cap hat with cow logo | ||
| description: White Cap | ||
| category: hat | ||
| price_sats: 50000 | ||
| stock: 15 | ||
| features: | ||
| - Custom feature 1 | ||
| - Custom feature 2 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| """YAML catalog loader for ShellShop.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import yaml | ||
| from typing import Any | ||
|
|
||
| from .catalog import MerchantProfile, Product | ||
|
|
||
|
|
||
| def load_yaml_catalog(path: str) -> tuple[MerchantProfile, list[Product]]: | ||
| """Load and validate a merchant profile and catalog from a YAML file.""" | ||
|
|
||
| with open(path, "r", encoding="utf-8") as f: | ||
| try: | ||
| data = yaml.safe_load(f) | ||
| except yaml.YAMLError as e: | ||
| raise ValueError(f"Failed to parse YAML configuration: {e}") | ||
|
|
||
| if not isinstance(data, dict): | ||
| raise ValueError("Root of YAML configuration must be a dictionary.") | ||
|
|
||
| merchant = _parse_merchant(data.get("merchant")) | ||
| products = _parse_catalog(data.get("catalog")) | ||
|
|
||
| return merchant, products | ||
|
|
||
|
|
||
| def _parse_merchant(data: Any) -> MerchantProfile: | ||
| if not isinstance(data, dict): | ||
| raise ValueError("Missing or invalid 'merchant' section in configuration.") | ||
|
|
||
| required_fields = ["name", "headline", "location", "promise"] | ||
| for field in required_fields: | ||
| if field not in data: | ||
| raise ValueError(f"Merchant profile missing required field: '{field}'") | ||
| if not isinstance(data[field], str): | ||
| raise ValueError(f"Merchant profile field '{field}' must be a string") | ||
|
|
||
| return MerchantProfile( | ||
| name=data["name"], | ||
| headline=data["headline"], | ||
| location=data["location"], | ||
| promise=data["promise"], | ||
| ) | ||
|
|
||
|
|
||
| def _parse_catalog(data: Any) -> list[Product]: | ||
| if not isinstance(data, list): | ||
| raise ValueError("Missing or invalid 'catalog' section, must be a list.") | ||
|
|
||
| products = [] | ||
| for i, prod_data in enumerate(data): | ||
| if not isinstance(prod_data, dict): | ||
| raise ValueError(f"Product at index {i} must be a dictionary.") | ||
|
|
||
| identifier = prod_data.get("sku") or f"index {i}" | ||
|
|
||
| # Required string fields | ||
| for field in ["sku", "name"]: | ||
| if field not in prod_data: | ||
| raise ValueError(f"Product '{identifier}' missing required field: '{field}'") | ||
| if not isinstance(prod_data[field], str): | ||
| raise ValueError(f"Product '{identifier}' field '{field}' must be a string") | ||
|
|
||
| # Optional string fields | ||
| for field in ["tagline", "description", "category"]: | ||
| val = prod_data.get(field) | ||
| if val is None: | ||
| prod_data[field] = "" | ||
| elif not isinstance(val, str): | ||
| raise ValueError(f"Product '{identifier}' field '{field}' must be a string or null") | ||
|
|
||
| # Integer fields | ||
| for field in ["price_sats", "stock"]: | ||
| if field not in prod_data: | ||
| raise ValueError(f"Product '{identifier}' missing required field: '{field}'") | ||
| if not isinstance(prod_data[field], int): | ||
| raise ValueError(f"Product '{identifier}' field '{field}' must be an integer") | ||
|
|
||
| # List of strings field (optional) | ||
| features_data = prod_data.get("features") | ||
| if features_data is None: | ||
| features_data = [] | ||
| elif not isinstance(features_data, list): | ||
| raise ValueError(f"Product '{identifier}' field 'features' must be a list of strings") | ||
| for j, feature in enumerate(features_data): | ||
| if not isinstance(feature, str): | ||
| raise ValueError(f"Product '{identifier}' feature at index {j} must be a string") | ||
|
|
||
| products.append( | ||
| Product( | ||
| sku=prod_data["sku"], | ||
| name=prod_data["name"], | ||
| tagline=prod_data["tagline"], | ||
| description=prod_data["description"], | ||
| category=prod_data["category"], | ||
| price_sats=prod_data["price_sats"], | ||
| stock=prod_data["stock"], | ||
| features=tuple(features_data), | ||
| ) | ||
| ) | ||
|
|
||
| return products |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicking here, but keep whitespaces consistent