Last active
November 12, 2020 21:17
-
-
Save yaythomas/4b598f804a603f759af6310985fc6ce4 to your computer and use it in GitHub Desktop.
This file contains 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
steps: | |
- name: pypyr.steps.echo | |
comment: if you want to see the echo output, remember to set loglevel <=25 | |
foreach: '{input_collection}' | |
in: | |
echoMe: just an echo with {i.arbfield} | |
- name: pypyr.steps.contextsetf | |
in: | |
contextSetf: | |
newkey: arbitrary value set in pipeline | |
more_complex_obj: | |
- one | |
- two | |
- a: b | |
c: d | |
e: | |
- e.1 | |
- e.2 |
This file contains 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
# optional. if you want to see logging output from pypyr, set log level <=25. | |
# import logging | |
# logging.basicConfig(level=25) | |
import pypyr.pipelinerunner | |
# this will load ./arb-pipe.yaml | |
pipeline_name = 'arb-pipe' | |
# you prob will have some code to get your queryset here like this: | |
# django_queryset_results = Entry.objects.filter(pub_date__year=2006) | |
# instead, just giving it a arbitrary hand-coded collection | |
class MyModelEntity: | |
def __init__(self, arb_field): | |
self.arbfield = arb_field | |
django_queryset_results = [ | |
MyModelEntity('value 1'), | |
MyModelEntity('value 2'), | |
MyModelEntity('value 3')] | |
# prepare a dict to initialize context | |
input_dict = { | |
'arbkey': 'arb value', | |
'input_collection': django_queryset_results | |
} | |
context_out = pypyr.pipelinerunner.main_with_context( | |
pipeline_name=pipeline_name, | |
dict_in=input_dict) | |
# context_out contains context + any mutations to it after pipeline completes | |
assert context_out['arbkey'] == 'arb value' | |
print(context_out['newkey']) | |
print(context_out['more_complex_obj']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment