### Fetching Context with MCP Tool 'context7' Source: https://github.com/tonkintaylor/ruru/blob/develop/AGENTS.md Demonstrates how to use the 'context7' tool to fetch relevant documentation for packages and Python versions. Examples show querying for package installation, quickstart guides, API details, and Python typing features. ```shell context7: docs package=requests topics=install,quickstart,api,examples context7: python version=3.12 topic=typing changes summary for "" context7: python version=3.12 topic="pattern matching" examples minimal ``` -------------------------------- ### Setup Pre-commit Hooks with uv Source: https://github.com/tonkintaylor/ruru/blob/develop/AGENTS.md Installs the git hook for the pre-commit framework using the 'uv' package manager. Ensures the project's dependencies are synchronized before installing the hook. ```shell uv sync uv run pre-commit install ``` -------------------------------- ### Ruru CLI Text Styling with Python Source: https://context7.com/tonkintaylor/ruru/llms.txt Demonstrates how to apply ANSI styling (bold, italic, underline, dim) to text using the ruru.cli module. It includes examples of basic styling, combining styles, and controlling color support via environment variables. ```python from ruru.cli import bold, italic, underline, dim import os # Basic text styling print(bold("Important message")) print(italic("Emphasis text")) print(underline("Underlined text")) print(dim("Secondary information")) # Combine styles by nesting print(bold(underline("Critical Warning"))) print(dim(italic("Optional note"))) # Control color support with environment variables os.environ["FORCE_COLOR"] = "1" # Force enable colors print(bold("Always styled")) os.environ["NO_COLOR"] = "1" # Disable colors print(bold("Plain text")) # Styling disabled, returns plain text del os.environ["NO_COLOR"] # Example usage in formatted output from ruru import cli cli.h2("System Information") print(f"Status: {bold('Active')}") print(f"Mode: {italic('Production')}") print(f"Note: {dim('Last updated 5 minutes ago')}") # Error message with styling error_code = "ERR_404" print(f"{bold('Error')}: {error_code} - {underline('Resource not found')}") ``` -------------------------------- ### Ruru CLI Colors with Python Source: https://context7.com/tonkintaylor/ruru/llms.txt Shows how to apply foreground colors to text using predefined color functions (red, green, etc.) and a generic `color` function. It covers basic coloring, combining colors with styles, and examples for status indicators and log levels. ```python from ruru.cli import red, green, yellow, blue, magenta, cyan, color from ruru.cli.styles import orange # Basic color functions print(red("Error message")) print(green("Success message")) print(yellow("Warning message")) print(blue("Information")) print(magenta("Debug output")) print(cyan("Highlight")) # Orange is an alias for yellow print(orange("Alert")) # Generic color function with color names print(color("Text in red", "red")) print(color("Bright green text", "bright_green")) print(color("Cyan text", "cyan")) # Combine colors with styles from ruru.cli import bold print(bold(red("Critical Error"))) print(bold(green("✓ Success"))) # Example status indicators status = "running" if status == "running": print(green("● Service is running")) elif status == "stopped": print(red("● Service is stopped")) else: print(yellow("● Service status unknown")) # Color-coded log levels def log(level, message): if level == "ERROR": print(f"{red('[ERROR]')} {message}") elif level == "WARNING": print(f"{yellow('[WARNING]')} {message}") elif level == "INFO": print(f"{blue('[INFO]')} {message}") elif level == "SUCCESS": print(f"{green('[SUCCESS]')} {message}") log("ERROR", "Connection timeout") log("WARNING", "Deprecated function used") log("INFO", "Processing started") log("SUCCESS", "Task completed") # All available color names colors = ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "bright_black", "bright_red", "bright_green", "bright_yellow", "bright_blue", "bright_magenta", "bright_cyan", "bright_white"] for c in colors: print(color(f"Sample text in {c}", c)) ``` -------------------------------- ### Ruru CLI Symbols with Python Source: https://context7.com/tonkintaylor/ruru/llms.txt Illustrates the use of Unicode symbols with automatic ASCII fallbacks for terminals. It covers individual symbol functions (tick, cross, etc.), a generic `symbol` function, and examples for status indicators, tree structures, and progress lists. ```python from ruru.cli import symbols import os # Individual symbol functions print(symbols.tick()) print(symbols.cross()) print(symbols.warning()) print(symbols.info()) print(symbols.arrow_right()) print(symbols.bullet()) print(symbols.line()) print(symbols.corner()) print(symbols.tree_mid()) print(symbols.tree_end()) # Generic symbol function print(symbols.symbol("tick")) print(symbols.symbol("cross")) # Force ASCII mode os.environ["ASCII_ONLY"] = "1" print(symbols.tick()) # v (ASCII fallback) del os.environ["ASCII_ONLY"] # Custom status indicators def show_status(success, message): if success: print(f"{symbols.tick()} {message}") else: print(f"{symbols.cross()} {message}") show_status(True, "Database connected") show_status(False, "API unavailable") # Tree structure example print("project/") print(f"{symbols.tree_mid()}{symbols.line()} src/") print(f"{symbols.tree_mid()}{symbols.line()} tests/") print(f"{symbols.tree_end()}{symbols.line()} README.md") # Progress indicators tasks = [ ("Install packages", True), ("Run tests", True), ("Deploy app", False) ] for task, completed in tasks: symbol = symbols.tick() if completed else symbols.cross() print(f"{symbol} {task}") # Info bullets with arrows print(f"{symbols.arrow_right()} Step 1: Initialize") print(f"{symbols.arrow_right()} Step 2: Configure") print(f"{symbols.arrow_right()} Step 3: Execute") ``` -------------------------------- ### Running Pre-commit Hooks Source: https://github.com/tonkintaylor/ruru/blob/develop/AGENTS.md Executes all pre-commit hooks for all files in the repository, applying fixes. If hooks modify files, they must be re-run until no further modifications occur. ```shell uv run pre-commit run --all-files git add -A uv run pre-commit run --all-files ``` -------------------------------- ### Python: Load configuration from YAML using ruru.config Source: https://github.com/tonkintaylor/ruru/blob/develop/README.md Shows how to load application configuration settings from a YAML file using the `ruru.config` module. It utilizes `importlib.resources` to locate the configuration file and then `config.get` to parse it into a Python dictionary. This approach is inspired by R's `config` package. ```python from importlib.resources import files from ruru import config config_path = files(".cli").joinpath("config.yml") config_dict = config.get(file = config_path) ``` -------------------------------- ### Auto-formatting Code with Ruff Source: https://github.com/tonkintaylor/ruru/blob/develop/AGENTS.md Applies automatic code formatting to the current directory using the 'ruff format' command, managed by 'uv'. This is an optional step to speed up the commit process. ```shell uv run ruff format . ``` -------------------------------- ### Error Handling with Ruru Config Source: https://context7.com/tonkintaylor/ruru/llms.txt Demonstrates how to catch specific exceptions like FileNotFoundError and MissingDefaultConfigError when using the ruru.config module. ```python try: config.get(file="missing.yml", use_parent=False) except FileNotFoundError as e: print(f"Config not found: {e}") try: config.get(file="invalid_config.yml") except config.MissingDefaultConfigError as e: print(f"Invalid config: {e}") ``` -------------------------------- ### Checking for 'TODO' Comments Source: https://github.com/tonkintaylor/ruru/blob/develop/AGENTS.md Provides a command to search the repository for 'TODO' comments (and its variants) using 'git grep'. This is part of the comment policy to avoid using 'TODO' in favor of GitHub issue references. ```shell git grep -n -E '\bT[O0]\s?DO\b|@todo' || true ``` -------------------------------- ### Python: Enhance CLI output with ruru.cli Source: https://github.com/tonkintaylor/ruru/blob/develop/README.md Illustrates using the `ruru.cli` module to create visually appealing command-line interfaces. It provides functions for formatting headings (`h1`), displaying alerts (`alert`), and other styled text elements. This module is designed to mimic the functionality of R's `cli` package. ```python from ruru import cli cli.h1("Heading") cli.alert("This is an alert message") ``` -------------------------------- ### YAML Configuration Management with Environment Overrides in Python Source: https://context7.com/tonkintaylor/ruru/llms.txt The `ruru.config` module facilitates loading and merging YAML configuration files. It supports environment-specific overrides (e.g., `development`, `production`) and can expand environment variables within configuration values. The `config.get()` function is used for loading configurations, allowing specification of the file, environment, and specific values. ```python from pathlib import Path from ruru import config import os # Basic configuration loading # config.yml: # default: # database: sqlite # debug: false # development: # database: postgres # debug: true config_data = config.get(file="config.yml") # Returns: {"database": "sqlite", "debug": False} # Environment-specific configuration os.environ["CONFIG_ACTIVE"] = "development" config_data = config.get(file="config.yml") # Returns: {"database": "postgres", "debug": True} # Get specific value debug_mode = config.get(value="debug", config="development", file="config.yml") # Returns: True # Environment variable expansion # config.yml: # default: # api_url: https://$API_HOST.$DOMAIN # db_connection: postgresql://$DB_USER:$DB_PASS@$DB_HOST:5432 os.environ["API_HOST"] = "api" os.environ["DOMAIN"] = "example.com" os.environ["DB_USER"] = "admin" os.environ["DB_PASS"] = "secret" os.environ["DB_HOST"] = "localhost" config_data = config.get(file="config.yml") # Returns: { # "api_url": "https://api.example.com", # "db_connection": "postgresql://admin:secret@localhost:5432" # } # Recommended usage with package resources from importlib.resources import files config_path = files("mypackage.cli").joinpath("config.yml") settings = config.get(file=config_path) ``` -------------------------------- ### Argument Matching with Partial String Matching in Python Source: https://context7.com/tonkintaylor/ruru/llms.txt The `match_arg` function from `ruru.base` allows for flexible matching of user input against a list of choices. It supports exact matching, unique prefix matching, and can handle ambiguous matches by returning multiple results when `several_ok=True`. It also supports batch processing of multiple inputs and includes error handling for invalid arguments. ```python from ruru.base import match_arg # Basic exact and partial matching choices = ["apple", "banana", "cherry"] result = match_arg("ban", choices) # Returns: "banana" result = match_arg("banana", choices) # Returns: "banana" # Handle ambiguous partial matches by allowing multiple results choices = ["apple", "apricot", "avocado"] try: match_arg("ap", choices) # Raises ValueError: matches multiple choices except ValueError as e: print(f"Error: {e}") # Allow multiple matches with several_ok=True results = match_arg("ap", choices, several_ok=True) # Returns: ["apple", "apricot"] # Batch processing with list input user_inputs = ["app", "ban", "cher"] results = match_arg(user_inputs, ["apple", "banana", "cherry"], several_ok=True) # Returns: ["apple", "banana", "cherry"] # Recommended pattern for normalizing user input user_choice = "APPLE" available = ["Apple", "Banana", "Cherry"] normalized = match_arg(user_choice.title(), available) # Returns: "Apple" # Error handling for invalid input try: match_arg("orange", ["apple", "banana"]) except ValueError as e: print(e) # "The provided argument 'orange' is not valid. Available choices are: apple, banana." ``` -------------------------------- ### Export Dependencies with uv Source: https://github.com/tonkintaylor/ruru/blob/develop/requirements.txt Exports project dependencies to a requirements.txt file using the 'uv export' command. It specifies frozen versions, offline mode, and excludes default groups, ensuring reproducible builds. ```shell uv export --frozen --offline --no-default-groups -o=requirements.txt -e . annotated-types==0.7.0 \ --hash=sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53 \ --hash=sha256:aff07c09a53a08bc8cfccb9c85b05f1aa9a2a6f23728d790723543408344ce89 # via pydantic pydantic==2.11.7 \ --hash=sha256:d989c3c6cb79469287b1569f7447a17848c998458d49ebe294e975b9baf0f0db \ --hash=sha256:dde5df002701f6de26248661f6835bbe296a47bf73990135c7d07ce741b9623b # via ruru pydantic-core==2.33.2 \ --hash=sha256:0069c9acc3f3981b9ff4cdfaf088e98d83440a4c7ea1bc07460af3d4dc22e72d \ --hash=sha256:031c57d67ca86902726e0fae2214ce6770bbe2f710dc33063187a68744a5ecac \ --hash=sha256:0405262705a123b7ce9f0b92f123334d67b70fd1f20a9372b907ce1080c7ba02 \ --hash=sha256:04a1a413977ab517154eebb2d326da71638271477d6ad87a769102f7c2488c56 \ --hash=sha256:0a39979dcbb70998b0e505fb1556a1d550a0781463ce84ebf915ba293ccb7e22 \ --hash=sha256:0a9f2c9dd19656823cb8250b0724ee9c60a82f3cdf68a080979d13092a3b0fef \ --hash=sha256:0e03262ab796d986f978f79c943fc5f620381be7287148b8010b4097f79a39ec \ --hash=sha256:0e5b2671f05ba48b94cb90ce55d8bdcaaedb8ba00cc5359f6810fc918713983d \ --hash=sha256:0fb2d542b4d66f9470e8065c5469ec676978d625a8b7a363f07d9a501a9cb36a \ --hash=sha256:1082dd3e2d7109ad8b7da48e1d4710c8d06c253cbc4a27c1cff4fbcaa97a9e3f \ --hash=sha256:1a8695a8d00c73e50bff9dfda4d540b7dee29ff9b8053e38380426a85ef10052 \ --hash=sha256:1e063337ef9e9820c77acc768546325ebe04ee38b08703244c1309cccc4f1bab \ --hash=sha256:1ea40a64d23faa25e62a70ad163571c0b342b8bf66d5fa612ac0dec4f069d916 \ --hash=sha256:2058a32994f1fde4ca0480ab9d1e75a0e8c87c22b53a3ae66554f9af78f2fe8c \ --hash=sha256:235f45e5dbcccf6bd99f9f472858849f73d11120d76ea8707115415f8e5ebebf \ --hash=sha256:2b0a451c263b01acebe51895bfb0e1cc842a5c666efe06cdf13846c7418caa9a \ --hash=sha256:2b3d326aaef0c0399d9afffeb6367d5e26ddc24d351dbc9c636840ac355dc5d8 \ --hash=sha256:2bfb5112df54209d820d7bf9317c7a6c9025ea52e49f46b6a2060104bba37de7 \ --hash=sha256:2f82865531efd18d6e07a04a17331af02cb7a651583c418df8266f17a63c6612 \ --hash=sha256:329467cecfb529c925cf2bbd4d60d2c509bc2fb52a20c1045bf09bb70971a9c1 \ --hash=sha256:3c6db6e52c6d70aa0d00d45cdb9b40f0433b96380071ea80b09277dba021ddf7 \ --hash=sha256:3dc625f4aa79713512d1976fe9f0bc99f706a9dee21dfd1810b4bbbf228d0e8a \ --hash=sha256:4b25d91e288e2c4e0662b8038a28c6a07eaac3e196cfc4ff69de4ea3db992a1b \ --hash=sha256:4c5b0a576fb381edd6d27f0a85915c6daf2f8138dc5c267a57c08a62900758c7 \ --hash=sha256:4e61206137cbc65e6d5256e1166f88331d3b6238e082d9f74613b9b765fb9025 \ --hash=sha256:52fb90784e0a242bb96ec53f42196a17278855b0f31ac7c3cc6f5c1ec4811849 \ --hash=sha256:572c7e6c8bb4774d2ac88929e3d1f12bc45714ae5ee6d9a788a9fb35e60bb04b \ --hash=sha256:5c4aa4e82353f65e548c476b37e64189783aa5384903bfea4f41580f255fddfa \ --hash=sha256:5c92edd15cd58b3c2d34873597a1e20f13094f59cf88068adb18947df5455b4e \ --hash=sha256:5f483cfb75ff703095c59e365360cb73e00185e01aaea067cd19acffd2ab20ea \ --hash=sha256:61c18fba8e5e9db3ab908620af374db0ac1baa69f0f32df4f61ae23f15e586ac \ --hash=sha256:6368900c2d3ef09b69cb0b913f9f8263b03786e5b2a387706c5afb66800efd51 \ --hash=sha256:64632ff9d614e5eecfb495796ad51b0ed98c453e447a76bcbeeb69615079fc7e \ --hash=sha256:65132b7b4a1c0beded5e057324b7e16e10910c106d43675d9bd87d4f38dde162 \ --hash=sha256:6b99022f1d19bc32a4c2a0d544fc9a76e3be90f0b3f4af413f87d38749300e65 \ --hash=sha256:6bdfe4b3789761f3bcb4b1ddf33355a71079858958e3a552f16d5af19768fef2 \ --hash=sha256:73662edf539e72a9440129f231ed3757faab89630d291b784ca99237fb94db2b \ --hash=sha256:73cf6373c21bc80b2e0dc88444f41ae60b2f070ed02095754eb5a01df12256de \ --hash=sha256:7cb8bc3605c29176e1b105350d2e6474142d7c1bd1d9327c4a9bdb46bf827acc \ --hash=sha256:82f68293f055f51b51ea42fafc74b6aad03e70e191799430b90c13d643059ebb \ --hash=sha256:87b31b6846e361ef83fedb187bb5b4372d0da3f7e28d85415efa92d6125d6e6d \ --hash=sha256:881b21b5549499972441da4758d662aeea93f1923f953e9cbaff14b8b9565aef \ --hash=sha256:8f57a69461af2a5fa6e6bbd7a5f60d3b7e6cebb687f55106933188e79ad155c1 \ --hash=sha256:95237e53bb015f67b63c91af7518a62a8660376a6a0db19b89acc77a4d6199f5 \ --hash=sha256:96081f1605125ba0855dfda83f6f3df5ec90c61195421ba72223de35ccfb2f88 \ --hash=sha256:9cb1da0f5a471435a7bc7e439b8a728e8b61e59784b2af70d7c169f8dd8ae290 \ --hash=sha256:9fdac5d6ffa1b5a83bca06ffe7583f5576555e6c8b3a91fbd25ea7780f825f7d \ --hash=sha256:a11c8d26a50bfab49002947d3d237abe4d9e4b5bdc8846a63537b6488e197808 \ --hash=sha256:a144d4f717285c6d9234a66778059f33a89096dfb9b39117663fd8413d582dcc \ --hash=sha256:a7ec89dc587667f22b6a0b6579c249fca9026ce7c333fc142ba42411fa243cdc \ --hash=sha256:aa9d91b338f2df0508606f7009fde642391425189bba6d8c653afd80fd6bb64e \ --hash=sha256:b0379a2b24882fef529ec3b4987cb5d003b9cda32256024e6fe1586ac45fc640 ``` -------------------------------- ### Package Dependencies and Hashes Source: https://github.com/tonkintaylor/ruru/blob/develop/requirements.txt This snippet lists Python package dependencies and their corresponding SHA256 hashes. These hashes ensure the integrity and authenticity of the downloaded packages. ```text --hash=sha256:ec031d5d2feb36d1d1a24380e4db6d43695f3748343d99434e6f5f9156aaa2ed \ --hash=sha256:ef6107725bd54b262d6dedcc2af448a266975032bc85ef0172c5f059da6325b4 \ --hash=sha256:efdca5630322a10774e8e98e1af481aad470dd62c3170801852d752aa7a783ba \ --hash=sha256:ff3824dc5261f50c9b0dfb3be22b4567a6f938ccce4587b38952d85fd9e9afe4 # via ruru typing-extensions==4.14.1 \ --hash=sha256:38b39f4aeeab64884ce9f74c94263ef78f3c22467c8724005483154c26648d36 \ --hash=sha256:d1e1e3b58374dc93031d6eda2420a48ea44a36c2b4766a4fdeb3710755731d76 # via # pydantic # pydantic-core # typing-inspection typing-inspection==0.4.1 \ --hash=sha256:389055682238f53b04f7badcb49b989835495a96700ced5dab2d8feae4b26f51 \ --hash=sha256:6ae134cc0203c33377d43188d4064e9b357dba58cff3185f22924610e70a9d28 # via pydantic ``` -------------------------------- ### CLI Alert Messages with Semantic Icons in Python Source: https://context7.com/tonkintaylor/ruru/llms.txt Offers functions (`alert_success`, `alert_danger`, `alert_warning`, `alert_info`, `alert_note`) in `ruru.cli` to display colored alert messages with semantic icons (checkmark, cross, warning, info) for different states, aiding in user feedback. ```python from ruru import cli # Success message (green with checkmark) cli.alert_success("Database connection established successfully") # Output: ✔ Database connection established successfully # Error/danger message (red with cross) cli.alert_danger("Failed to connect to API endpoint") # Output: ✖ Failed to connect to API endpoint # Warning message (yellow with warning symbol) cli.alert_warning("Configuration file not found, using defaults") # Output: ⚠ Configuration file not found, using defaults # Information message (blue with info symbol) cli.alert_info("Processing 1,234 records...") # Output: ℹ Processing 1,234 records... # Note message (default color with info symbol) cli.alert_note("Remember to backup your data before proceeding") # Output: ℹ Remember to backup your data before proceeding # Example error handling pattern try: result = process_data() cli.alert_success(f"Processed {result['count']} records") except ConnectionError as e: cli.alert_danger(f"Connection failed: {e}") except Exception as e: cli.alert_warning(f"Non-critical error: {e}") finally: cli.alert_info("Operation completed") ``` -------------------------------- ### Low-Level Partial String Matching (Indices) in Python Source: https://context7.com/tonkintaylor/ruru/llms.txt The `pmatch` function from `ruru.base.matching` provides a lower-level string matching utility. It returns the index of the matched item in the provided list for exact matches or unique prefix matches. It returns -1 for ambiguous matches, None for no match, and None for an empty query string. This function is useful for custom matching logic. ```python from ruru.base.matching import pmatch # Exact match returns index table = ["apple", "apricot", "banana"] result = pmatch("banana", table) # Returns: 2 # Unique prefix match returns index result = pmatch("ban", table) # Returns: 2 # Ambiguous match returns -1 result = pmatch("ap", table) # Returns: -1 # No match returns None result = pmatch("cherry", table) # Returns: None # Empty string returns None result = pmatch("", table) # Returns: None # Use pmatch for custom matching logic query = "med" choices = ["mean", "median", "mode"] idx = pmatch(query, choices) if idx is None: print("No match found") elif idx == -1: print("Ambiguous match") else: print(f"Matched: {choices[idx]}") # Output: "Matched: median" ``` -------------------------------- ### Python: Match function arguments using ruru.base.match_arg Source: https://github.com/tonkintaylor/ruru/blob/develop/README.md Demonstrates how to use the `match_arg` function from the `ruru.base` module to validate user-provided arguments against a list of allowed choices. It handles case-insensitivity by converting the user input to title case before matching. This function is a Python equivalent of R's `match.arg`. ```python from ruru.base import match_arg user_choice = "apple" available_choices = ["Apple", "Banana", "Cherry"] # Normalize user input before passing it to match_arg. # Which transformation to use depends on the style of available_choices: # - .title() if choices look like "Apple" # - .upper() if choices look like "APPLE" # - .lower() if choices look like "apple" user_choice = match_arg(user_choice.title(), available_choices) ``` -------------------------------- ### CLI Hierarchical Headings in Python Source: https://context7.com/tonkintaylor/ruru/llms.txt Provides functions (`h1`, `h2`, `h3`) within the `ruru.cli` module to display hierarchical headings with customizable separators for improved command-line output readability. ```python from ruru import cli # Level 1 heading with full-width separator cli.h1("Application Setup") # Output: # ──────────────────────── Application Setup ──────────────────────── # Level 2 heading with medium separator cli.h2("Database Configuration") # Output: # ── Database Configuration ── # Level 3 heading with minimal separator cli.h3("Connection Settings") # Output: # ── Connection Settings # Example usage in application flow cli.h1("Data Processing Pipeline") cli.h2("Step 1: Data Ingestion") print("Loading data from source...") cli.h2("Step 2: Transformation") print("Applying transformations...") cli.h2("Step 3: Export") print("Exporting results...") ``` -------------------------------- ### CLI Bullet Lists in Python Source: https://context7.com/tonkintaylor/ruru/llms.txt The `bullets` function in `ruru.cli` allows for the display of lists with bullet points. It supports lists of strings, mixed data types, key-value dictionaries, and automatically formats dictionary values that are lists. ```python from ruru import cli # Simple list of strings items = ["Install dependencies", "Configure settings", "Run tests"] cli.bullets(items) # Output: # • Install dependencies # • Configure settings # • Run tests # List with mixed types data = ["Task completed", 42, 3.14159, True] cli.bullets(data) # Output: # • Task completed # • 42 # • 3.14159 # • True # Dictionary with key-value pairs config = { "name": "MyApplication", "version": "1.2.3", "author": "Development Team", "enabled": True } cli.bullets(config) # Output: # • name: MyApplication # • version: 1.2.3 # • author: Development Team # • enabled: True # Dictionary with list values (automatically formatted) project_info = { "languages": ["Python", "JavaScript", "Go"], "frameworks": ["Django", "React"], "status": "active" } cli.bullets(project_info) # Output: # • languages: Python, JavaScript, Go # • frameworks: Django, React # • status: active ``` -------------------------------- ### Environment Variable Replacement in Python Source: https://context7.com/tonkintaylor/ruru/llms.txt Utilizes the `replace_env_vars` function from `ruru.config` to substitute environment variables within dictionaries and lists. It supports simple replacements, mixed strings, nested structures, and handles missing variables by either leaving them unchanged or replacing them with empty strings. ```python from ruru.config import replace_env_vars import os # Simple replacement os.environ["DB_HOST"] = "localhost" data = {"url": "$DB_HOST"} result = replace_env_vars(data) # Returns: {"url": "localhost"} # Mixed strings with multiple variables os.environ["APP_NAME"] = "myapp" os.environ["DOMAIN"] = "eastus.azurecontainer.io" data = {"endpoint": "https://$APP_NAME.$DOMAIN"} result = replace_env_vars(data) # Returns: {"endpoint": "https://myapp.eastus.azurecontainer.io"} # Nested structures os.environ["API_HOST"] = "api" os.environ["DOMAIN"] = "example.com" config = { "api_url": "https://$API_HOST.$DOMAIN/v1", "nested": {"endpoint": "$API_HOST/users"}, "services": ["$API_HOST", "https://$DOMAIN"] } result = replace_env_vars(config) # Returns: { # "api_url": "https://api.example.com/v1", # "nested": {"endpoint": "api/users"}, # "services": ["api", "https://example.com"] # } # Missing variables become empty strings in mixed strings data = {"url": "https://$MISSING_VAR.com"} result = replace_env_vars(data) # Returns: {"url": "https://.com"} # Pure missing variables remain unchanged (backward compatibility) data = {"var": "$MISSING_VAR"} result = replace_env_vars(data) # Returns: {"var": "$MISSING_VAR"} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.