Skip to content

Commit

Permalink
Set parameters for running flow instead of any imported (Netflix#1691)
Browse files Browse the repository at this point in the history
* Set parameters for running flow instead of any imported

This fixes the issue where parameters for multiple imported flows
are displayed instead of the running one when multple flows are
in the same file with parameters.

Also:
1. Change to use Exception as bare except is bad practice / fails
flake8.
2. Switch to editable/develop install so any code changes would be
   effective without reinstalling. Much faster to iterate changes.

* suggested changes

* restore except blocks

---------

Co-authored-by: Max Zheng <[email protected]>
  • Loading branch information
madhur-ob and maxzheng authored Jan 19, 2024
1 parent 60693bf commit a46f4a3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
5 changes: 4 additions & 1 deletion metaflow/flowspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from types import FunctionType, MethodType
from typing import Any, Callable, List, Optional, Tuple

from . import cmd_with_io
from . import cmd_with_io, parameters
from .parameters import DelayedEvaluationParameter, Parameter
from .exception import (
MetaflowException,
Expand Down Expand Up @@ -100,6 +100,9 @@ def __init__(self, use_cli=True):
self._graph = FlowGraph(self.__class__)
self._steps = [getattr(self, node.name) for node in self._graph]

# This must be set before calling cli.main() below (or specifically, add_custom_parameters)
parameters.parameters = [p for _, p in self._get_parameters()]

if use_cli:
# we import cli here to make sure custom parameters in
# args.py get fully evaluated before cli.py is imported.
Expand Down
7 changes: 1 addition & 6 deletions metaflow/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@
],
)

# currently we execute only one flow per process, so we can treat
# Parameters globally. If this was to change, it should/might be
# possible to move these globals in a FlowSpec (instance) specific
# closure.
parameters = []
parameters = [] # Set by FlowSpec.__init__()
context_proto = None


Expand Down Expand Up @@ -335,7 +331,6 @@ def __init__(
"Parameter *%s*: Separator is only allowed "
"for string parameters." % name
)
parameters.append(self)

def option_kwargs(self, deploy_mode):
kwargs = self.kwargs
Expand Down
2 changes: 1 addition & 1 deletion test_runner
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -o errexit -o nounset -o pipefail
install_deps() {
for version in 2 3;
do
python$version -m pip install .
python$version -m pip install .
done
}

Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
[testenv]
allowlist_externals = ./test_runner
commands = ./test_runner

0 comments on commit a46f4a3

Please sign in to comment.