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

Support deep evaluation in evaluate_keyed_by #310

Open
hneiva opened this issue Jul 24, 2023 · 2 comments
Open

Support deep evaluation in evaluate_keyed_by #310

hneiva opened this issue Jul 24, 2023 · 2 comments
Assignees
Labels
feature A feature request good first issue Good for newcomers

Comments

@hneiva
Copy link
Contributor

hneiva commented Jul 24, 2023

Add deep=False argument to evaluate_keyed_by, and if deep is true, then try to evaluate all attributes of provided value, traversing objects and lists.

As an alternative, a "wrapper" function (ie deep_evaluate_keyed_by) that traverses an object/list and calls the original evaluate_keyed_by.

@hneiva hneiva added good first issue Good for newcomers feature A feature request labels Jul 24, 2023
@RamitPandey22
Copy link

hey I am interested to contribute on this if no one is already maintaining this?

@hneiva
Copy link
Contributor Author

hneiva commented Jul 25, 2023

Hello @RamitPandey22 !
I checked with the team and no one is currently working on this.

Here is a quick code example of this request:

from taskgraph.util.keyed_by import evaluate_keyed_by
import json

data = {
    "list-type": [
        {
            "name": {
                "by-foo": {
                    "bar": "name is foobar0",
                    "baz": "name is foobaz0",
                }
            }
        },
        {
            "name": {
                "by-foo": {
                    "bar": "name is foobar1",
                    "baz": "name is foobaz1",
                }
            }
        },
    ],
    "dict-type": {
        "one": {
            "name": {
                "by-foo": {
                    "bar": "name is foobar0",
                    "baz": "name is foobaz0",
                }
            }
        },
        "two": {
            "name": {
                "by-foo": {
                    "bar": "name is foobar1",
                    "baz": "name is foobaz1",
                }
            }
        },
    },
}

# Evaluating a value as expected
evaluated_value = evaluate_keyed_by(data["dict-type"]["one"]["name"], "example", {"foo": "bar"})
print(evaluated_value)
assert evaluated_value == "name is foobar0"

# This would be nice to have (passing in the entire data structure)
evaluated_structure = evaluate_keyed_by(data, "example", {"foo": "bar"})
print(json.dumps(evaluated_structure, indent=4))
assert evaluated_structure["dict-type"]["one"]["name"] == "name is foobar0"

If you have any questions on how to get started, feel free to ask here or in the Matrix Firefox CI room. (My handle is @hneiva there as well)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants