Skip to content
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

Fix mustache workaround only taking top level keys into account #84

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

peters-david
Copy link
Contributor

@peters-david peters-david commented Jan 22, 2025

Fix broken ids when project or registry names start with the same text.

@peters-david peters-david linked an issue Jan 22, 2025 that may be closed by this pull request
@peters-david peters-david requested review from a team and removed request for a team January 22, 2025 11:01
@peters-david peters-david requested review from seekermarcel and a team January 29, 2025 12:18
@seekermarcel
Copy link

seekermarcel commented Jan 29, 2025

maybe restructure the new fuction for better readability?
something like

def insert_into_dict(d: dict, parts: list) -> None:
    """Inserts nested keys and value into a dictionary."""
    *keys, last_key, value = parts
    for key in keys:
        d = d.setdefault(key, {})
    d[last_key] = value

@seekermarcel
Copy link

same for the original "fill_template" function. I don't want to criticize your programming but its very hard to read.

maybe something like, just as a possibility

import re
import chevron

async def fill_template(client, path: str, logger) -> str:
    """Reads a template file, replaces placeholders with fetched IDs, and returns the updated content."""
    with open(path, 'r') as file:
        config = file.read()

    placeholders = re.findall(r'{{\s*(?:project|registry):[\w.\-_]+\s*}}', config)
    logger.info("Found id templates", extra={"placeholders": placeholders})

    replacements = {}
    for placeholder in (p.strip(" {}") for p in placeholders):
        placeholder_type, placeholder_value = placeholder.split(':')
        replacement_value = await fetch_id(client, placeholder_type, placeholder_value)

        # Create nested dictionary structure for replacements
        insert_into_dict(replacements, placeholder.split('.') + [str(replacement_value)])

    return chevron.render(config, replacements)

@seekermarcel
Copy link

and maybe we could include the change from nuitka to pyinstaller in this. its a very small change that safes a lot of pipeline runtime

@peters-david peters-david linked an issue Jan 30, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve build time Mustache workaround causes ids to miss
2 participants