metaflow icon indicating copy to clipboard operation
metaflow copied to clipboard

set FlowSpec attrs via metaclass, add pytest to CI

Open ryan-williams opened this issue 4 years ago • 4 comments

(factored out of #612)

  • set core FlowSpec attrs (file, name, path_spec, _graph, _steps) at definition, using FlowSpecMeta metaclass
  • add proof-of-concept pytest test (and associated testing utilities); run pytest in CI
  • use click's standalone_mode to control expectations around SystemExit on flow completion

Previously, Flow definition logic has been split between two locations/times:

  • class-definition time (the flow is a class, steps are methods, they are defined when the Python interpreter loads the class definition)
  • "run-time" (FlowSpec.__init__), when a flow is instantiated (typically as part of being run)

This change computes "static" flow properties (graph structure, file, name, Parameter info) at class-definition time, and leaves the __init__ to handle logic related to a specific run of a flow. It does this by adding a FlowSpecMeta metaclass to the FlowSpec base class (cf. flowspec.py#L47), which lets Metaflow compile/parse flows when they are defined, and cleans up the distinction between "flow definition" and "flow instantiation".

ryan-williams avatar Aug 24 '21 16:08 ryan-williams

Not immediately obvious to me what happened in "R tests on macos-latest":

Loading required package: data.table
Loading required package: Matrix
Loading required package: glmnet
Loaded glmnet 4.1-2
Loading required package: caret
Loading required package: lattice
Loading required package: ggplot2
Metaflow 2.3.0 executing BasicArtifactsTestFlow for user:runner
Creating local datastore in current directory (/Users/runner/work/metaflow/metaflow/R/tests/.metaflow)
Validating your flow...
    The graph looks good!
2021-08-24 16:47:29.143 Workflow starting (run-id 1629823649050969):
2021-08-24 16:47:29.167 [1629823649050969/start/1 (pid 9336)] Task is starting.
2021-08-24 16:47:33.403 [1629823649050969/start/1 (pid 9336)] Error in py_call_impl(callable, dots$args, dots$keywords) : SystemExit: 0
2021-08-24 16:47:33.420 [1629823649050969/start/1 (pid 9336)] 
2021-08-24 16:47:33.420 [1629823649050969/start/1 (pid 9336)] Detailed traceback:
2021-08-24 16:47:33.421 [1629823649050969/start/1 (pid 9336)] File "/Users/runner/.virtualenvs/r-metaflow/lib/python3.7/site-packages/metaflow/R.py", line 102, in run
2021-08-24 16:47:33.421 [1629823649050969/start/1 (pid 9336)] entrypoint=full_cmdline[:-len(metaflow_args)])
2021-08-24 16:47:33.421 [1629823649050969/start/1 (pid 9336)] File "/Users/runner/.virtualenvs/r-metaflow/lib/python3.7/site-packages/metaflow/cli.py", line 1010, in main
2021-08-24 16:47:33.421 [1629823649050969/start/1 (pid 9336)] start(**start_kwargs)
2021-08-24 16:47:33.421 [1629823649050969/start/1 (pid 9336)] File "/Users/runner/.virtualenvs/r-metaflow/lib/python3.7/site-packages/click/core.py", line 1137, in __call__
2021-08-24 16:47:33.422 [1629823649050969/start/1 (pid 9336)] return self.main(*args, **kwargs)
2021-08-24 16:47:33.422 [1629823649050969/start/1 (pid 9336)] File "/Users/runner/.virtualenvs/r-metaflow/lib/python3.7/site-packages/click/core.py", line 1090, in main
2021-08-24 16:47:33.422 [1629823649050969/start/1 (pid 9336)] sys.exit(e.exit_code)
2021-08-24 16:47:33.422 [1629823649050969/start/1 (pid 9336)] Calls: <Anonymous> -> py_call_impl
2021-08-24 16:47:33.422 [1629823649050969/start/1 (pid 9336)] Execution halted
2021-08-24 16:47:33.429 [1629823649050969/start/1 (pid 9336)] Task failed.
2021-08-24 16:47:33.441 Workflow failed.
2021-08-24 16:47:33.442 Terminating 0 active tasks...
2021-08-24 16:47:33.442 Flushing logs...
    Step failure:
    Step start (task-id 1) failed.

Error: Error in run_tests(context) : status_code == 0 is not TRUE
Calls: source ... eval -> run_tests_all_contexts -> run_tests -> stopifnot
Execution halted
Error: Process completed with exit code 1.

ryan-williams avatar Aug 24 '21 16:08 ryan-williams

"R tests on macos-latest" still failing, seems like a real issue, I'll try to reproduce locally

ryan-williams avatar Nov 01 '21 17:11 ryan-williams

Alright, figured out the R tests issue, this was the fix, tests all passing now! 🎉

ryan-williams avatar Nov 02 '21 03:11 ryan-williams

This is ready to review, I think!

ryan-williams avatar Jan 08 '22 17:01 ryan-williams