emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Bjarte Johansen <bjarte.johansen@infomedia.uib.no>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: Make ob-shell conform to the org-babel interface
Date: Wed, 3 Jun 2015 12:58:55 +0200	[thread overview]
Message-ID: <E1FD1677-BCFF-411E-9FFE-6239F31ECF16@infomedia.uib.no> (raw)
In-Reply-To: <877frntkj2.fsf@nicolasgoaziou.fr>

[-- Attachment #1: Type: text/plain, Size: 39 bytes --]

Sorry for the delay.

Is this better?


[-- Attachment #2: 0001-ob-shell-Conform-to-variable-assignment-interface.patch --]
[-- Type: application/octet-stream, Size: 3612 bytes --]

From 2c68fce2a2f340740cc3dded2c8c04841742d21a Mon Sep 17 00:00:00 2001
From: Bjarte Johansen <bjarte.johansen@gmail.com>
Date: Wed, 3 Jun 2015 12:46:32 +0200
Subject: [PATCH] ob-shell: Conform to variable assignment interface

* lisp/ob-shell.el (org-babel-shell-names):
  Initialize org-babel-variable-assignments:* for each shell.

* (org-babel-variable-assignments-bash):
  Renamed from `org-babel-variable-assignments:bash'.

* (org-babel-variable-assignments:sh):
  Apply renaming.

* testing/lisp/test-ob-shell.el
  (test-ob-shell/should-respect-ob-interface-naming-convention):
  New test.

Change org-babel-variable-assignments functions in ob-shell to use the
same function so it conforms to the interface used for variable
assignment in Org Babel.
---
 lisp/ob-shell.el              | 16 ++++++++++------
 testing/lisp/test-ob-shell.el | 11 +++++++++++
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/lisp/ob-shell.el b/lisp/ob-shell.el
index 5b74821..c90ba04 100644
--- a/lisp/ob-shell.el
+++ b/lisp/ob-shell.el
@@ -48,10 +48,14 @@
     (set-default symbol (second value))
     (mapc
      (lambda (name)
-       (eval `(defun ,(intern (concat "org-babel-execute:" name)) (body params)
-		,(format "Execute a block of %s commands with Babel." name)
-		(let ((shell-file-name ,name))
-		  (org-babel-execute:shell body params)))))
+       (eval
+	`(progn
+	   (defun ,(intern (concat "org-babel-execute:" name)) (body params)
+	     ,(format "Execute a block of %s commands with Babel." name)
+	     (let ((shell-file-name ,name))
+	       (org-babel-execute:shell body params)))
+	   (defvar ,(intern (concat "org-babel-variable-assignments:" name))
+	     'org-babel-variable-assignments:sh))))
      (second value))))
 
 (defun org-babel-execute:shell (body params)
@@ -121,7 +125,7 @@ This function is called by `org-babel-execute-src-block'."
      values
      "\n")))
 
-(defun org-babel-variable-assignments:bash (varname values &optional sep hline)
+(defun org-babel-variable-assignments-bash (varname values &optional sep hline)
   "Represents the parameters as useful Bash shell variables."
   (if (listp values)
       (if (and (listp (car values)) (= 1 (length (car values))))
@@ -138,7 +142,7 @@ This function is called by `org-babel-execute-src-block'."
     (mapcar
      (lambda (pair)
        (if (string-match "bash$" shell-file-name)
-	   (org-babel-variable-assignments:bash
+	   (org-babel-variable-assignments-bash
             (car pair) (cdr pair) sep hline)
          (org-babel-variable-assignments:sh-generic
 	  (car pair) (cdr pair) sep hline)))
diff --git a/testing/lisp/test-ob-shell.el b/testing/lisp/test-ob-shell.el
index 58a7859..36f0fc1 100644
--- a/testing/lisp/test-ob-shell.el
+++ b/testing/lisp/test-ob-shell.el
@@ -27,6 +27,17 @@
 (unless (featurep 'ob-shell)
   (signal 'missing-test-dependency "Support for Shell code blocks"))
 
+(ert-deftest test-ob-shell/should-respect-ob-interface-naming-convention ()
+  "Functions used to interface with the different Org Babel
+should have the correct signature."
+  (dolist (shell org-babel-shell-names)
+    (org-test-with-temp-text
+	(format "#+BEGIN_SRC<point> %s :cache yes
+  echo test
+#+END_SRC" shell)
+      (let ((info (org-babel-get-src-block-info)))
+	(should (org-babel-sha1-hash info))))))
+
 (ert-deftest test-ob-shell/dont-insert-spaces-on-expanded-bodies ()
   "Expanded shell bodies should not start with a blank line
 unless the body of the tangled block does."
-- 
2.3.2 (Apple Git-55)


[-- Attachment #3: Type: text/plain, Size: 1899 bytes --]



> On 01 Jun 2015, at 19:18, Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
> 
> Hello,
> 
> Bjarte Johansen <bjarte.johansen@infomedia.uib.no> writes:
> 
>> I found that ob-shell’s org-babel-variable-assignments:bash function
>> does not respect the interface for org-babel. It takes multiple
>> arguments when it should only take 1. This is a problem when f.ex.
>> org-babel-sha1-hash tries to expand the body of a bash source block
>> and tries to call that function with only 1 argument.
>> 
>> I am not sure if the following patch follows best practices in the
>> project, but it solves the problem for me.
> 
> Thank you for the patch. Some comments follow.
> 
>> From 04f00e4f69c5352d51b7de1ba8783ddd96124c1f Mon Sep 17 00:00:00 2001
>> From: Bjarte Johansen <bjarte.johansen@gmail.com>
>> Date: Wed, 27 May 2015 17:20:41 +0200
>> Subject: [PATCH] ob-shell: Conform to variable assignment interface
> 
> You need to list modified functions in commit message.
> 
> 
>> Change org-babel-variable-assignments functions in ob-shell to use the
>> same function so conform to the interface used for variable assignment
>> in org-babel.
> 
> "Org Babel"
> 
>> +(ert-deftest test-ob-shell/should-respect-ob-interface-naming-convention ()
>> +  "Functions used to interface with the different org-babel
>> +  should have the correct signature."
> 
> "Org Babel".
> 
> Also, do not indent second line, and please make first sentence fit on
> a single line.
> 
>> +  (dolist (shell org-babel-shell-names)
>> +    (org-test-with-temp-text
>> +	(format "#+BEGIN_SRC<point> %s :cache yes
>> +  echo test
>> +#+END_SRC" shell)
>> +      (let ((info (org-babel-get-src-block-info)))
>> +	(org-babel-sha1-hash info)))))
> 
> You need to wrap this within a `should' in order to define a proper
> test.
> 
> 
> Regards,
> 
> -- 
> Nicolas Goaziou


      reply	other threads:[~2015-06-03 10:59 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-27 15:30 Make ob-shell conform to the org-babel interface Bjarte Johansen
2015-06-01 17:18 ` Nicolas Goaziou
2015-06-03 10:58   ` Bjarte Johansen [this message]

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

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=E1FD1677-BCFF-411E-9FFE-6239F31ECF16@infomedia.uib.no \
    --to=bjarte.johansen@infomedia.uib.no \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@nicolasgoaziou.fr \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).