all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* variable interpolation in code snippets
@ 2019-02-20 14:50 Ricardo Wurmus
  2019-02-25 23:00 ` zimoun
  0 siblings, 1 reply; 11+ messages in thread
From: Ricardo Wurmus @ 2019-02-20 14:50 UTC (permalink / raw)
  To: gwl-devel

Hi,

code snippets can now reference variables.  Here’s an example:

--8<---------------cut here---------------start------------->8---
define-module : snippets-wisp

import
  gwl processes
  gwl workflows
  gwl sugar

process: python-test
  package-inputs : list "python2"
  data-inputs
    list "sample.bam" "hg38.fa" "abc"
  procedure # python {
import os

def hello():
  print "hello from python 2"
  print "{{data-inputs}}"
  print "{{name}}"
  print os.environ["_GWL_PROCESS_DATA_INPUTS"]
  print os.environ["_GWL_PROCESS_NAME"]

hello()
}
--8<---------------cut here---------------end--------------->8---

The “python-test” process refers to the variables “data-inputs” and
“name”.  These variables are provided by the “process” record (values
for all defined fields are let bound, so that other fields can access
them), but you could access any other variable that’s in scope.

This is accomplished with the same reader macro that implements the “# ”
syntax for procedures.

The above example also shows access of the same values through
environment variables.  Note that in both cases all values are forced to
be strings.  You can’t have a Scheme list and use it natively as Python
array.  This whole “# ” syntax only operates on strings.  (You can have
a Scheme string that *looks* like Python syntax, of course, and splice
it into your inline Python code, but … you probably shouldn’t do that.)

--
Ricardo

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-06-07 15:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-20 14:50 variable interpolation in code snippets Ricardo Wurmus
2019-02-25 23:00 ` zimoun
2019-02-26  8:12   ` Ricardo Wurmus
2019-02-26 17:35     ` zimoun
2019-02-26 19:04       ` Ricardo Wurmus
2019-02-26 19:29         ` zimoun
2019-05-29 13:27           ` Ricardo Wurmus
2019-06-03 14:54             ` zimoun
2019-06-03 16:04               ` Ricardo Wurmus
2019-06-03 18:19                 ` Roel Janssen
2019-06-07 14:59                 ` Ricardo Wurmus

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.