Skip to content

Commit

Permalink
add is_attribute_user_defined check to conda decorators (#2011)
Browse files Browse the repository at this point in the history
  • Loading branch information
saikonen authored Sep 3, 2024
1 parent d135cc9 commit 05521ff
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion metaflow/plugins/pypi/conda_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class CondaStepDecorator(StepDecorator):
# conda channels, users can specify channel::package as the package name.

def __init__(self, attributes=None, statically_defined=False):
self._user_defined_attributes = (
attributes.copy() if attributes is not None else {}
)
super(CondaStepDecorator, self).__init__(attributes, statically_defined)

# Support legacy 'libraries=' attribute for the decorator.
Expand All @@ -59,6 +62,9 @@ def __init__(self, attributes=None, statically_defined=False):
}
del self.attributes["libraries"]

def is_attribute_user_defined(self, name):
return name in self._user_defined_attributes

def step_init(self, flow, graph, step, decos, environment, flow_datastore, logger):
# The init_environment hook for Environment creates the relevant virtual
# environments. The step_init hook sets up the relevant state for that hook to
Expand All @@ -71,11 +77,16 @@ def step_init(self, flow, graph, step, decos, environment, flow_datastore, logge

# Support flow-level decorator.
if "conda_base" in self.flow._flow_decorators:
super_attributes = self.flow._flow_decorators["conda_base"][0].attributes
conda_base = self.flow._flow_decorators["conda_base"][0]
super_attributes = conda_base.attributes
self.attributes["packages"] = {
**super_attributes["packages"],
**self.attributes["packages"],
}
self._user_defined_attributes = {
**self._user_defined_attributes,
**conda_base._user_defined_attributes,
}
self.attributes["python"] = (
self.attributes["python"] or super_attributes["python"]
)
Expand Down Expand Up @@ -322,6 +333,9 @@ class CondaFlowDecorator(FlowDecorator):
}

def __init__(self, attributes=None, statically_defined=False):
self._user_defined_attributes = (
attributes.copy() if attributes is not None else {}
)
super(CondaFlowDecorator, self).__init__(attributes, statically_defined)

# Support legacy 'libraries=' attribute for the decorator.
Expand All @@ -333,6 +347,9 @@ def __init__(self, attributes=None, statically_defined=False):
if self.attributes["python"]:
self.attributes["python"] = str(self.attributes["python"])

def is_attribute_user_defined(self, name):
return name in self._user_defined_attributes

def flow_init(
self, flow, graph, environment, flow_datastore, metadata, logger, echo, options
):
Expand Down

0 comments on commit 05521ff

Please sign in to comment.