emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Make ob-shell conform to the org-babel interface
@ 2015-05-27 15:30 Bjarte Johansen
  2015-06-01 17:18 ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Bjarte Johansen @ 2015-05-27 15:30 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi,

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. 


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

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

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.
---
 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..c8db512 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..5a050fe 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)))
+	(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)


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

* Re: Make ob-shell conform to the org-babel interface
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2015-06-01 17:18 UTC (permalink / raw)
  To: Bjarte Johansen; +Cc: emacs-orgmode

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

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

* Re: Make ob-shell conform to the org-babel interface
  2015-06-01 17:18 ` Nicolas Goaziou
@ 2015-06-03 10:58   ` Bjarte Johansen
  0 siblings, 0 replies; 3+ messages in thread
From: Bjarte Johansen @ 2015-06-03 10:58 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

[-- 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


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

end of thread, other threads:[~2015-06-03 10:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

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).