Skip to content

Commit

Permalink
Adding samples
Browse files Browse the repository at this point in the history
  • Loading branch information
Grant-Archibald-MS committed Dec 28, 2024
1 parent 1352ed1 commit d086f80
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
26 changes: 26 additions & 0 deletions context/python.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Python Sample

These samples make use of executing Python in the browser using pyioide. You can use these skills to allow you to use you python skills and make use of them in web pages and inside the extension points of the Power Platform.

Lets look at some examples.

## Integers

{% pyodide %}
1 + 1
{% endpyodide %}

## String

{% pyodide %}
"a" + "b"
{% endpyodide %}

## Functions

{% pyodide %}
def hello(name):
return "Hello " + name

hello("World!")
{% endpyodide %}
2 changes: 1 addition & 1 deletion examples/coe-kit-infrastructure-as-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ This template provide optional steps to do the following:
4. Create a developer environment for each test user

> [NOTES]:
> 1. For developer environments [Power Aps Developer Plan](https://www.microsoft.com/en-us/power-platform/products/power-apps/free) could be applied
> 1. For developer environments [Power Apps Developer Plan](https://www.microsoft.com/en-us/power-platform/products/power-apps/free) could be applied
> 2. Microsoft 365 Business Premium licenses has been purchased from Microsoft 365 Admin portal market place https://admin.microsoft.com/Adminportal/Home#/catalog. The [Try or buy a Microsoft 365 for business subscription](https://learn.microsoft.com/microsoft-365/commerce/try-or-buy-microsoft-365) can help you with choices.
> 3. Power Automate Premium licenses has been purchased from Microsoft 365 Admin portal market place. The [Types of Power Automate licenses](https://learn.microsoft.com/power-platform/admin/power-automate-licensing/types) can help you select license choices.
Expand Down
63 changes: 63 additions & 0 deletions site/_plugins/python/pyodide_plugin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# _plugins/pyodide_plugin.rb
module Jekyll
class PyodideTag < Liquid::Block
def initialize(tag_name, text, tokens)
super
@id = "pyodide-#{rand(1000..9999)}"
end

def render(context)
code = super.strip
<<~HTML
<style>
.CodeMirror {
border: 1px solid #eee;
height: auto;
}
.CodeMirror-scroll {
max-height: 200px;
}
</style>
<textarea id="#{@id}-code" rows="10" cols="50" style="width: 100%;">#{code}</textarea>
<button id="#{@id}-runButton" onclick="runPython('#{@id}')" disabled>Run</button>
<pre id="#{@id}-output"></pre>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/codemirror.min.css">
<script src="https://cdn.jsdelivr.net/pyodide/v0.26.4/full/pyodide.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/mode/python/python.min.js"></script>
<script>
async function loadPyodideAndPackages() {
if (typeof window.pyodide === "undefined") {
window.editors = [];
window.pyodide = await loadPyodide({
indexURL: "https://cdn.jsdelivr.net/pyodide/v0.26.4/full/"
});
}
window.editors["#{@id}-code"] = CodeMirror.fromTextArea(document.getElementById('#{@id}-code'), {
mode: 'python',
lineNumbers: true
});
document.getElementById('#{@id}-runButton').disabled = false;
}
loadPyodideAndPackages();
if (typeof window.runPython === "undefined") {
window.runPython = async function runPython(id) {
let editor = window.editors[id + '-code'];
let code = editor.getValue();
let outputElement = document.getElementById(id + '-output');
try {
let result = await pyodide.runPythonAsync(code);
outputElement.textContent = result;
} catch (err) {
outputElement.textContent = err;
}
}
}
</script>
HTML
end
end
end

Liquid::Template.register_tag('pyodide', Jekyll::PyodideTag)

0 comments on commit d086f80

Please sign in to comment.