Skip to content
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

fix: conda/pypi usage of _user_defined_attributes #2168

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 3 additions & 18 deletions metaflow/plugins/pypi/conda_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,9 @@ class CondaStepDecorator(StepDecorator):
# CONDA_CHANNELS in their environment. For pinning specific packages to specific
# 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)

def init(self):
super(CondaStepDecorator, self).init()

# We have to go back and fixup _user_defined_attributes for potential
# config resolution
self._user_defined_attributes = {
k: v
for k, v in self.attributes.items()
if k in self._user_defined_attributes
}

# Support legacy 'libraries=' attribute for the decorator.
self.attributes["packages"] = {
**self.attributes["libraries"],
Expand Down Expand Up @@ -94,10 +80,9 @@ def step_init(self, flow, graph, step, decos, environment, flow_datastore, logge
**super_attributes["packages"],
**self.attributes["packages"],
}
self._user_defined_attributes = {
**self._user_defined_attributes,
**conda_base._user_defined_attributes,
}
self._user_defined_attributes = self._user_defined_attributes.union(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have an issue with this but we are overloading the meaning of _user_defined_attributes here since it is now a value across decorators. We don't currently use it but since you use it for a specfiic purpose, I would create a different name for it.

conda_base._user_defined_attributes
)
self.attributes["python"] = (
self.attributes["python"] or super_attributes["python"]
)
Expand Down
13 changes: 3 additions & 10 deletions metaflow/plugins/pypi/pypi_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ class PyPIStepDecorator(StepDecorator):
name = "pypi"
defaults = {"packages": {}, "python": None, "disabled": None} # wheels

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

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 @@ -42,10 +36,9 @@ def step_init(self, flow, graph, step, decos, environment, flow_datastore, logge
if "pypi_base" in self.flow._flow_decorators:
pypi_base = self.flow._flow_decorators["pypi_base"][0]
super_attributes = pypi_base.attributes
self._user_defined_attributes = {
**self._user_defined_attributes,
**pypi_base._user_defined_attributes,
}
self._user_defined_attributes = self._user_defined_attributes.union(
pypi_base._user_defined_attributes
)
self.attributes["packages"] = {
**super_attributes["packages"],
**self.attributes["packages"],
Expand Down
Loading