Code Monkey home page Code Monkey logo

Comments (5)

gregneagle avatar gregneagle commented on June 29, 2024

I understand the idea and the usefulness; not sure how you would implement it without making the (already somewhat complicated) recipe format even more complicated. Any ideas?

from autopkg.

jessepeterson avatar jessepeterson commented on June 29, 2024

Perhaps too simplistic but just a "MergeInputVariables" boolean key in the top level? If on it would use the merging algorithm for all keys in the Input section merging with the Input section of the parent receipt. If off the behavior is as it is now.

Or maybe a "multiple" type. If it's a boolean everything is merged. If it's an array then only the variables listed are merged, others are overwritten as usual. If it's a dictionary then only the subtrees of the variables are merged (but that just might be too much complication).

from autopkg.

timsutton avatar timsutton commented on June 29, 2024

I can see the value of being able to have this control, although I'm not sure it's worth the syntax and usage complications, at least not now.

I'm not sure I understand the idea of the MergeInputVariables key, unless you mean something like a "deep" or recursive merge of dict keys?

Probably 90% of recipes don't need to have their Munki pkginfo contents changing in between minor version updates. And when it does happen, you would still need to react and do something manually to your override in order to control which of your keys will persist.

At this point, the simplest way to have total control is to fork the recipe and maintain your own copy merging from upstream changes, and Git makes this trivial.

I could also see the idea being servicable for top-level pkginfo keys, but then you may want to also override things like installs items, and this could just create more user confusion about at what step this can actually be handled.

from autopkg.

jessepeterson avatar jessepeterson commented on June 29, 2024

I hear your points. I still feel it's a useful feature. :)

Something like this:

<key>MergeInputVariablesFromParent</key>
<array>
    <string>pkginfo</string>
</array>

If this is present then keys inside the local pkginfo are merged with the parent overriding any that existing in the parent.

The more complicated example could be like this:

<key>MergeInputVariablesFromParent</key>
<dict>
    <key>pkginfo</key>
    <array>
        <string>display_name</string>
        <string>catalogs</string>
    </array>
</dict>

So that only the display_name and catalogs variables are merged.

Speaking more generally, though, avoiding forking would be ideal here. E.g. making less changes in Overrides and not having to fork. For the more complicated packages that have uninstall_scripts, involved installs keys, etc. just like to avoid the duplication, hard-coding, and having to manually track the upstream seems ideal.

from autopkg.

jessepeterson avatar jessepeterson commented on June 29, 2024

Just to put a more concrete example of what I'm proposing it looks like this in the autopkg code:

diff --git a/Code/autopkg b/Code/autopkg
index a1fbea5..058a3ff 100755
--- a/Code/autopkg
+++ b/Code/autopkg
@@ -336,8 +336,12 @@ def load_recipe(name, override_dirs, recipe_dirs,
                 recipe["Identifier"] = get_identifier(child_recipe)
                 recipe["Description"] = child_recipe.get(
                     "Description", recipe.get("Description", ""))
+                from Foundation import NSMutableDictionary
                 for key in child_recipe["Input"].keys():
-                    recipe["Input"][key] = child_recipe["Input"][key]
+                    if child_recipe.get("MergeChildInputVariables") and isinstance(child_recipe["Input"][key], NSMutableDictionary):
+                        recipe["Input"][key].update(child_recipe["Input"][key])
+                    else:
+                        recipe["Input"][key] = child_recipe["Input"][key]

                 # take the highest of the two MinimumVersion keys, if they exist
                 for candidate_recipe in [recipe, child_recipe]:

This makes it such that you add a boolean key to your override recipe called MergeChildInputVariables and then your dictionary Input variables from your override are merged (Python update() method called - which apparently is actually PyObjC over an NSMutableDictionary) into the child "real" recipe.

My practical use of this is to change (and change only) the catalogs in the pkginfo of most munki recipes. Another would be overriding Munki 2 categories in pkginfos. However I'd like to keep the descriptions, and display_names, preinstall_scripts, and all other keys of recipes in case other people change those and I don't notice.

An example override file might look like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Identifier</key>
    <string>local.munki.VMwareTools</string>
    <key>MergeChildInputVariables</key>
    <true/>
    <key>Input</key>
    <dict>
        <key>MUNKI_REPO_SUBDIR</key>
        <string>my/special/place</string>
        <key>NAME</key>
        <string>VMwareTools</string>
        <key>pkginfo</key>
        <dict>
            <key>catalogs</key>
            <array>
                <string>testing</string>
                <string>development</string>
            </array>
        </dict>
    </dict>
    <key>ParentRecipe</key>
    <string>com.github.jessepeterson.munki.VMwareTools</string>
</dict>
</plist>

... and because I have the MergeChildInputVariables in this example override I get to keep all the keys in the "real" child recipe rather than duplicate and risk being possibly out of sync if the recipe ever gets changed.

from autopkg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.