-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Metaflow Card component for rendering a syntax highlighed python function - Driveby: moved `with_component_id` and `create_component_id` functions to `card.py` - Example flow : ``` from metaflow import FlowSpec, step, card, current from metaflow.cards import PythonCode class PythonCodeDemoFlow(FlowSpec): @card @step def start(self): # Example 1: Using a function def sample_function(): x = 1 y = 2 return x + y current.card.append(PythonCode(sample_function)) # Example 2: Using a string code = """ def another_function(): return "Hello World" """ current.card.append(PythonCode(code_string=code)) self.next(self.end) @step def end(self): pass if __name__ == '__main__': PythonCodeDemoFlow() ```
- Loading branch information
Showing
10 changed files
with
156 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
metaflow/plugins/cards/ui/src/components/python-code.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!-- This component will render a simple log with syntax highlighting --> | ||
<script lang="ts"> | ||
import type * as types from "../types"; | ||
export let componentData: types.PythonCodeComponent; | ||
let el: HTMLElement; | ||
function highlightCode() { | ||
el && (window as any)?.Prism?.highlightElement(el, ); | ||
} | ||
$: el ? highlightCode() : null; | ||
</script> | ||
|
||
<!-- This needs to be in this exact format of <pre><code> ... without a new line between the <pre> and <code> tags --> | ||
<!-- Need to do this to avoid weird indentation issues --> | ||
<!-- based on https://github.com/PrismJS/prism/issues/554#issuecomment-83197995 --> | ||
<pre data-component="pythonCode"><code class="language-python" bind:this={el}>{componentData.data} | ||
</code> | ||
</pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters