add options to configure pyscript interpreter
This commit is contained in:
parent
25cb9c6403
commit
62c020ca7b
2 changed files with 25 additions and 6 deletions
|
|
@ -2,7 +2,7 @@
|
|||
#import "./html_body.typ": html-body
|
||||
#import "./html_utils.typ": html-show
|
||||
#import "./summary.typ": summary, card-list
|
||||
#import "./pyscript.typ": state-use-pyscript, state-pyscript-headers, state-pyscript-version, pyscript-show
|
||||
#import "./pyscript.typ": state-use-pyscript, state-pyscript-headers, state-pyscript-version, state-pyscript-interpreters, state-pyscript-default-interpreter, pyscript-show
|
||||
#import "./rss.typ": rss
|
||||
#import "./icons.typ"
|
||||
|
||||
|
|
@ -34,8 +34,12 @@
|
|||
me-links: (),
|
||||
/// Dictionnary of available tags to add in header for each versions of pyscript
|
||||
pyscript-headers: (:),
|
||||
/// Dictionnary of available python version to add in header for each pyscript interpreter
|
||||
pyscript-interpreters: (:),
|
||||
/// Pyscript version to use
|
||||
pyscript-version: none,
|
||||
/// Default python version to use for selecting the pyscript interpreter
|
||||
pyscript-default-interpreter: none,
|
||||
//-- Body --
|
||||
/// Array of element to add on the top left of the page
|
||||
nav-elements: none,
|
||||
|
|
@ -54,7 +58,9 @@
|
|||
assert(type(url) == str, message: "A page must have an url")
|
||||
context {
|
||||
state-pyscript-headers.update(x => pyscript-headers)
|
||||
state-pyscript-interpreters.update(x => pyscript-interpreters)
|
||||
state-pyscript-version.update(x => pyscript-version)
|
||||
state-pyscript-default-interpreter.update(x => pyscript-default-interpreter)
|
||||
}
|
||||
show: html-show
|
||||
show raw.where(block: true, lang: "python"): pyscript-show
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#let state-use-pyscript = state("state-use-pyscript", false)
|
||||
#let state-pyscript-version = state("state-pyscript-version", none)
|
||||
#let state-pyscript-headers = state("state-pyscript-headers", (:))
|
||||
#let state-pyscript-interpreters = state("state-pyscript-interpreters", (:))
|
||||
#let state-pyscript-default-interpreter = state("state-pyscript-default-interpreter", none)
|
||||
|
||||
#let get-pep723(script) = {
|
||||
script.find(regex(
|
||||
|
|
@ -39,6 +41,7 @@
|
|||
"run", default: true
|
||||
) {
|
||||
state-use-pyscript.update(x => true)
|
||||
context {
|
||||
let config = metadata.at("tool", default: (:)).at("pyscript", default: (:))
|
||||
|
||||
let pyscript-config = (:)
|
||||
|
|
@ -52,14 +55,24 @@
|
|||
let attrs = (
|
||||
type: "py"
|
||||
)
|
||||
if pyscript-config != (:) {
|
||||
attrs.insert("config", json.encode(pyscript-config))
|
||||
}
|
||||
if true {
|
||||
if true { // TODO: pygame ?
|
||||
attrs.insert("terminal", "")
|
||||
attrs.insert("worker", "")
|
||||
}
|
||||
|
||||
if "interpreter" in config {
|
||||
pyscript-config.insert("interpreter", config.at("interpreter")
|
||||
} else if state-pyscript-default-interpreter.final() != none {
|
||||
assert(
|
||||
state-pyscript-default-interpreter.final() in state-pyscript-interpreters.final(),
|
||||
message: state-pyscript-default-interpreter.final() + " is not in pyscript-interpreters",
|
||||
)
|
||||
pyscript-config.insert("interpreter", state-pyscript-interpreters.final().at(state-pyscript-default-interpreter.final())
|
||||
}
|
||||
if pyscript-config != (:) {
|
||||
attrs.insert("config", json.encode(pyscript-config))
|
||||
}
|
||||
|
||||
let script = it.text;
|
||||
if config.at("repl", default: false) {
|
||||
script = "import code\n" + script + "\ncode.interact(banner='', local=globals())"
|
||||
|
|
@ -107,4 +120,4 @@
|
|||
it
|
||||
}
|
||||
//raw(block: true, lang: "json", json.encode(metadata))
|
||||
}
|
||||
}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue