-
Notifications
You must be signed in to change notification settings - Fork 930
[WIP] Feat/user decorators v2 #2463
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
Conversation
719dcd3 to
5342612
Compare
This also includes packaging for local runs
301b0d5 to
68ddbcd
Compare
2f97ddd to
a57a7f1
Compare
a57a7f1 to
6fb4fbf
Compare
1436b0c to
38486fc
Compare
Two types of decorators are supported:
- a "pure" Python decorator that allows you to execute something before
and after a step. You also have the possibility of entirely skipping a step
(which is a fairly requested feature)
- mutators (Flow level or Step level). These mutators allow you to modify
the flow/steps dynamically. This is particularly useful when put together
with configs.
Still needs quite a few tests but it should be workable. A few features to try out:
- You should be able to add mutators on a base flow spec class and have it
work in a derived class
- the add_decorator function on the MutableStep should take strings,
actual MF decorators and user decorators
- the add_decorator function on the MutableFlow should take strings
and actual flow level decorators.
- --with should work with any step level decorator (user defined including
step mutators):
- the name is the FQN for the class. It supports passing arguments as well
- you can also use a shorter name provided that name is available *somewhere* where
the flowspec is defined (either itself or one of its base classes)
- mix and match decorators should work
- the UserStepDecorator class has a init function that can take arguments
if you want to build something a bit more fancy
- the mutators also take arguments
- config values can be used for any of those arguments (and of course can be
used inside any of those functions)
- inserted_by is now a list
- decorators are now auto registered on import allowing
use even if not imported in the file; the name of the decorator
is also automatically calculated as the shortest identifying one
- `package info` now shows which decorators are injected by which
portions of code
- added compatibility with pylint for user_step_decorator
Still known:
- configs in arguments to user decorators
- dash in config
Other bug fixes to also make things more natural and just plain old stupid bugs
38486fc to
5f1e2bd
Compare
…sue with auto import of modules.
c225d81 to
a59c07f
Compare
| target_platform = KUBERNETES_CONDA_ARCH or "linux-64" | ||
|
|
||
| def init(self): | ||
| super(KubernetesDecorator, self).init() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed as unnecessary? same question for all the decorators init() changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why removed? It is necessary. You need to call the base class' init because that is what resolves the attributes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wait, I removed it? Ok, let me check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right -- I now use this other function called external_init
When doing something like :
```
from metaflow import project
....
mymutableflow.add_decorator(
project, deco_kwargs={"name":"abc"})
```
Metaflow breaks with the error :
```
File ".../metaflow/flowspec.py", line 312, in _process_config_decorators
deco.pre_mutate(mutable_flow)
File "mydeco.py", line 67, in pre_mutate
mutable_flow.add_decorator(
File ".../metaflow/user_decorators/mutable_flow.py", line 409, in add_decorator
_add_flow_decorator(
File ".../metaflow/user_decorators/mutable_flow.py", line 353, in _add_flow_decorator
d for d in self._flow_cls._flow_decorators if d.name == flow_deco.name
^^^^^^
AttributeError: 'str' object has no attribute 'name'
```
This is because we dont parse the _flow_cls._flow_decorators in the right way (as a dict instead of list)
When doing something like :
```
from metaflow import project
....
mymutableflow.add_decorator(
project, deco_kwargs={"name":"abc"})
```
Metaflow breaks with the error :
```
File ".../metaflow/flowspec.py", line 312, in _process_config_decorators
deco.pre_mutate(mutable_flow)
File "mydeco.py", line 67, in pre_mutate
mutable_flow.add_decorator(
File ".../metaflow/user_decorators/mutable_flow.py", line 409, in add_decorator
_add_flow_decorator(
File ".../metaflow/user_decorators/mutable_flow.py", line 353, in _add_flow_decorator
d for d in self._flow_cls._flow_decorators if d.name == flow_deco.name
^^^^^^
AttributeError: 'str' object has no attribute 'name'
```
This is because we dont handle the _flow_cls._flow_decorators in the
right way (as a dict instead of list)
When doing something like :
```
from metaflow import project
....
mymutableflow.add_decorator(
project, deco_kwargs={"name":"abc"})
```
Metaflow breaks with the error :
```
File ".../metaflow/flowspec.py", line 312, in _process_config_decorators
deco.pre_mutate(mutable_flow)
File "mydeco.py", line 67, in pre_mutate
mutable_flow.add_decorator(
File ".../metaflow/user_decorators/mutable_flow.py", line 409, in add_decorator
_add_flow_decorator(
File ".../metaflow/user_decorators/mutable_flow.py", line 353, in _add_flow_decorator
d for d in self._flow_cls._flow_decorators if d.name == flow_deco.name
^^^^^^
AttributeError: 'str' object has no attribute 'name'
```
This is because we dont parse the _flow_cls._flow_decorators in the right way (as a dict instead of list)
`deconame` is not declared and the code would have crashed on that code path. replaced it with the correct variable name
- Same flavor of bug fix as Netflix#2513
No description provided.