Skip to content

Conversation

romain-intel
Copy link
Contributor

No description provided.

@romain-intel romain-intel changed the base branch from master to feat/packaging-v2-again June 18, 2025 17:01
@romain-intel romain-intel force-pushed the feat/user_decorators_v2 branch from 719dcd3 to 5342612 Compare June 19, 2025 10:23
This also includes packaging for local runs
@romain-intel romain-intel force-pushed the feat/packaging-v2-again branch from 301b0d5 to 68ddbcd Compare July 3, 2025 09:33
@romain-intel romain-intel force-pushed the feat/user_decorators_v2 branch from 2f97ddd to a57a7f1 Compare July 3, 2025 11:02
@romain-intel romain-intel force-pushed the feat/user_decorators_v2 branch from a57a7f1 to 6fb4fbf Compare July 7, 2025 09:15
@romain-intel romain-intel force-pushed the feat/user_decorators_v2 branch from 1436b0c to 38486fc Compare July 7, 2025 16:15
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
@romain-intel romain-intel force-pushed the feat/user_decorators_v2 branch from 38486fc to 5f1e2bd Compare July 9, 2025 00:00
@savingoyal savingoyal marked this pull request as ready for review July 11, 2025 03:02
@saikonen saikonen force-pushed the feat/packaging-v2-again branch from c225d81 to a59c07f Compare July 11, 2025 08:36
Base automatically changed from feat/packaging-v2-again to master July 11, 2025 08:37
@@ -177,8 +179,6 @@ class KubernetesDecorator(StepDecorator):
target_platform = KUBERNETES_CONDA_ARCH or "linux-64"

def init(self):
super(KubernetesDecorator, self).init()
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

@savingoyal savingoyal merged commit 85fb152 into master Jul 12, 2025
29 of 30 checks passed
@savingoyal savingoyal deleted the feat/user_decorators_v2 branch July 12, 2025 14:27
valayDave added a commit to valayDave/metaflow that referenced this pull request Jul 17, 2025
savingoyal pushed a commit that referenced this pull request Jul 17, 2025
The packaging PR #2463 introduced the
`extract_args_kwargs_from_decorator_spec` to parse the decospecs added
from the command line. This function has a subtle bug where it returns
from the for loop instead of the end of the function.
valayDave added a commit to valayDave/metaflow that referenced this pull request Jul 22, 2025
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)
romain-intel pushed a commit that referenced this pull request Jul 22, 2025
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)
valayDave added a commit to valayDave/metaflow that referenced this pull request Jul 25, 2025
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)
valayDave added a commit that referenced this pull request Aug 11, 2025
`deconame` is not declared and the code would have crashed on that code path. replaced it with the correct variable name
savingoyal pushed a commit that referenced this pull request Aug 11, 2025
`deconame` is not declared and the code would have crashed on that code
path. replaced it with the correct variable name
valayDave added a commit to valayDave/metaflow that referenced this pull request Aug 11, 2025
savingoyal pushed a commit that referenced this pull request Aug 11, 2025
- Same flavor of bug fix as #2513

Reproduce by doing something like : 

```python
from metaflow import project

....

mymutableflow.add_decorator(
project, deco_kwargs={"name":"abc"}, duplicates=3)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants