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

[cards] Fix config issue permanently. #2205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

valayDave
Copy link
Collaborator

@valayDave valayDave commented Jan 10, 2025

  • Ensures configs behave consistently with cards.
    Testing script to see it works :
from metaflow import FlowSpec, step, card, current, Config
from metaflow.cards import ProgressBar

def git_info(args=None):
    from subprocess import check_output, CalledProcessError

    info = {
        "commit": ["git", "rev-parse", "HEAD"],
        "branch": ["git", "rev-parse", "--abbrev-ref", "HEAD"],
        "message": ["git", "log", "-1", "--pretty=%B"],
        "remote": ["git", "config", "--get", "remote.origin.url"],
    }
    cfg = {}
    try:
        for key, cmd in info.items():
            cfg[key] = check_output(cmd, text=True).strip()
    except CalledProcessError as e:
        # Handle cases where git commands fail
        cfg["error"] = f"Git command failed: {e}"
    return cfg


class PythonCodeDemoFlow(FlowSpec):

    git_info = Config("git_info", default_value="", parser=git_info)

    @card
    @card(type="blank", id="progress_bar", customize=True)
    @step
    def start(self):
        import time
        progress = ProgressBar(max=100)

        current.card.append(progress)
        for i in range(100):
            progress.update(i)
            current.card.refresh()
            time.sleep(1)
        
        self.next(self.end)

    @step
    def end(self):
        pass

if __name__ == '__main__':
    PythonCodeDemoFlow()

- Ensures configs behave consistently with cards.
Comment on lines -249 to -254
# Unlink the config file if it exists
if self._config_file_name:
try:
os.unlink(self._config_file_name)
except Exception as e:
pass
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Earlier we were naively removing the config file when the same config file is referenced for all CardCreators. So this broke configs when many cards are present.

Comment on lines +272 to +277
self._increment_completed_counter()
if self.task_finished_decos == self.total_decos_on_step[step_name]:
# Unlink the config file if it exists
if self._config_file_name:
try:
os.unlink(self._config_file_name)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Now we only remove the config when all the decorators are either done with task_finished or with task_exception

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.

1 participant