1

I need a good approach to declare a lot of variables over a context. For exmaple in kubeflow, I need declare a pipeline with a lot components in order to do that, I use the following code:

component_1_op = comp.load_component(
    'path/to/component/1')
...
component_n_op = comp.load_component(
    'path/to/component/n')

Because of our line length rules I need to use two lines to do that. Another option is the following:

components = [
    ["component_op", 'path/to/component/1'],
    ...,
    ["component_n_op", 'path/to/component/n']
]

components = {component: comp.load_component(path) for component, path in components}

candied_orange
  • 108,538
Tlaloc-ES
  • 387
  • 1
  • 12

1 Answers1

6

Your second option is a good one. you are defining all your components up front, this is potentially reusable across pipelines, or makes testing easier as you can redefine what components to load to testing friendly ones. This is generally a good practice when you have a lot of values or key/values. This lets you clearly separate the intent of the code (loading needed components) from the details (where each component lives).

Ryathal
  • 13,396