all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ricardo Wurmus <rekado@elephly.net>
To: gwl-devel@gnu.org
Subject: variable interpolation in code snippets
Date: Wed, 20 Feb 2019 15:50:34 +0100	[thread overview]
Message-ID: <87lg2atsxx.fsf@elephly.net> (raw)

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

             reply	other threads:[~2019-02-20 16:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-20 14:50 Ricardo Wurmus [this message]
2019-02-25 23:00 ` variable interpolation in code snippets 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lg2atsxx.fsf@elephly.net \
    --to=rekado@elephly.net \
    --cc=gwl-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.