emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* (9.2) Noweb blocks not expanded in Python blocks.
@ 2019-02-04 11:32 Emmanuel Charpentier
  2019-02-04 13:11 ` John Kitchin
  0 siblings, 1 reply; 7+ messages in thread
From: Emmanuel Charpentier @ 2019-02-04 11:32 UTC (permalink / raw)
  To: emacs-orgmode

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

Seen in `org-mode' version `9.2'.

Using `noweb' syntax works OK with `emacs-lisp':

┌────
│ #+name: a
│ #+begin_src emacs-lisp
│   (setq L (append L (list i)))
│ #+end_src
│ 
│ #+name: b
│ #+begin_src emacs-lisp :noweb yes :exports both
│   ;; Lisp version
│   (setq L nil)
│   (dotimes (i 5) <<a>>)
│   L
│ #+end_src
└────

This gives :

┌────
│ (setq L (append L (list i)))
└────

┌────
│ ;; Lisp version
│ (setq L nil)
│ (dotimes (i 5) )
│ L
└────

The `noweb' syntax also works with `Sage' (a symbolic maths oriented
Python derivative):

┌────
│ #+name: Aaarghhh
│ #+begin_src sage
│   L.append(i)
│ #+end_src
│ 
│ #+name: Berde
│ #+begin_src sage :noweb yes :exports both
│   ## Python version
│   L=[]
│   for i in range(1,6):
│       <<Aaarghhh>>
│   L
│ #+end_src
└────

wich gives :

┌────
│ L.append(i)
└────

┌────
│ ## Sage version
│ L=[]
│ for i in range(1,6):
│ 
│ L
└────

But using the same syntax in Python fails miserably:

┌────
│ #+name: Ah
│ #+begin_src python
│   L.append(i)
│ #+end_src
│ 
│ #+name: Beee
│ #+begin_src python :noweb yes :exports both
│   ## Python version
│   L=[]
│   for i in range(1,6):
│       <<Ah>>
│   L
│ #+end_src
└────

┌────
│ L.append(i)
└────

┌────
│ ## Python version
│ L=[]
│ for i in range(1,6):
│     <<Ah>>
│ L
└────

┌────
│ []
└────


It *seems* that the "Ah" block is not expanded.

The code itself should be sound *if* it expanded:

┌────
│ #+name: B0
│ #+begin_src python :exports both
│   L=[]
│   for i in range(1,6):
│       L.append(i)
│   L
│ #+end_src
└────

┌────
│ L=[]
│ for i in range(1,6):
│     L.append(i)
│ L
└────

━━━━━━━━━━━━━━━
 1  2  3  4  5 
━━━━━━━━━━━━━━━

During the compilation of the source of this mail, the following is
printed in the `*Python*' buffer:

┌────
│ >>> L.append(i)
│ >>> 
│ >>> open('/tmp/babel-OJSsxf/python-dVESY4', 'w').write(str(_))
│ >>> 
│ >>> 
│ >>> 'org_babel_python_eoe'
│ 'org_babel_python_eoe'
│ >>> ## Python version
│ ... L=[]
│ >>> for i in range(1,6):
│ ...     <<Ah>>
│   File "<stdin>", line 2
│     <<Ah>>
│      ^
│ SyntaxError: invalid syntax
│ >>> 
│ >>> L
│ []
│ >>> 
│ >>> open('/tmp/babel-OJSsxf/python-9NR46u', 'w').write(str(_))
│ >>> 
│ >>> 
│ >>> 'org_babel_python_eoe'
│ 'org_babel_python_eoe'
│ >>> L=[]
│ >>> for i in range(1,6):
│ ...     L.append(i)
│ ... 
│ >>> L
│ [1, 2, 3, 4, 5]
│ >>> 
│ >>> open('/tmp/babel-OJSsxf/python-fW5gK0', 'w').write(str(_))
│ >>> 
│ >>> 
│ >>> 'org_babel_python_eoe'
│ 'org_babel_python_eoe'
│ >>> 
└────

The source code of this mail is attached.

--
Emmanuel Charpentier

[-- Attachment #2: PythonNowebProblem.org --]
[-- Type: text/plain, Size: 2819 bytes --]

# Syntaxe noweb ?

#+title:
#+date:
#+author:
#+options: toc:nil

#+property: header-args:python :session
#+property: header-args:sage :session

Seen in ~org-mode~ version src_emacs-lisp{org-version}.

Using ~noweb~ syntax works OK with ~emacs-lisp~:

#+begin_example
#+name: a
#+begin_src emacs-lisp
  (setq L (append L (list i)))
#+end_src

#+name: b
#+begin_src emacs-lisp :noweb yes :exports both
  ;; Lisp version
  (setq L nil)
  (dotimes (i 5) <<a>>)
  L
#+end_src
#+end_example

This gives :

#+name: a
#+begin_src emacs-lisp
  (setq L (append L (list i)))
#+end_src

#+name: b
#+begin_src emacs-lisp :noweb yes :exports both
  ;; Lisp version
  (setq L nil)
  (dotimes (i 5) <<a>>)
  L
#+end_src

The ~noweb~ syntax also works with ~Sage~ (a symbolic maths oriented
Python derivative):

#+begin_example
#+name: Aaarghhh
#+begin_src sage
  L.append(i)
#+end_src

#+name: Berde
#+begin_src sage :noweb yes :exports both
  ## Python version
  L=[]
  for i in range(1,6):
      <<Aaarghhh>>
  L
#+end_src
#+end_example

wich gives :

#+name: Aaarghhh
#+begin_src sage
  L.append(i)
#+end_src

#+name: Berde
#+begin_src sage :noweb yes :exports both
  ## Sage version
  L=[]
  for i in range(1,6):
      <<Aaarghhh>>
  L
#+end_src

But using the same syntax in Python fails miserably:

#+begin_example
#+name: Ah
#+begin_src python
  L.append(i)
#+end_src

#+name: Beee
#+begin_src python :noweb yes :exports both
  ## Python version
  L=[]
  for i in range(1,6):
      <<Ah>>
  L
#+end_src
#+end_example

#+name: Ah
#+begin_src python
  L.append(i)
#+end_src

#+name: Beee
#+begin_src python :noweb yes :exports both
  ## Python version
  L=[]
  for i in range(1,6):
      <<Ah>>
  L
#+end_src

It *seems* that the "Ah" block is not expanded.

The code itself should be sound *if* it expanded:

#+begin_example
#+name: B0
#+begin_src python :exports both
  L=[]
  for i in range(1,6):
      L.append(i)
  L
#+end_src
#+end_example

#+name: B0
#+begin_src python :exports both
  L=[]
  for i in range(1,6):
      L.append(i)
  L
#+end_src

During the compilation of the source of this mail, the following is
printed in the ~*Python*~ buffer:

#+begin_example
>>> L.append(i)
>>> 
>>> open('/tmp/babel-OJSsxf/python-dVESY4', 'w').write(str(_))
>>> 
>>> 
>>> 'org_babel_python_eoe'
'org_babel_python_eoe'
>>> ## Python version
... L=[]
>>> for i in range(1,6):
...     <<Ah>>
  File "<stdin>", line 2
    <<Ah>>
     ^
SyntaxError: invalid syntax
>>> 
>>> L
[]
>>> 
>>> open('/tmp/babel-OJSsxf/python-9NR46u', 'w').write(str(_))
>>> 
>>> 
>>> 'org_babel_python_eoe'
'org_babel_python_eoe'
>>> L=[]
>>> for i in range(1,6):
...     L.append(i)
... 
>>> L
[1, 2, 3, 4, 5]
>>> 
>>> open('/tmp/babel-OJSsxf/python-fW5gK0', 'w').write(str(_))
>>> 
>>> 
>>> 'org_babel_python_eoe'
'org_babel_python_eoe'
>>> 
#+end_example

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

* Re: (9.2) Noweb blocks not expanded in Python blocks.
  2019-02-04 11:32 (9.2) Noweb blocks not expanded in Python blocks Emmanuel Charpentier
@ 2019-02-04 13:11 ` John Kitchin
  2019-02-04 13:40   ` (9.2) Noweb blocks not expanded in Python blocks : it should be a bug Emmanuel Charpentier
  0 siblings, 1 reply; 7+ messages in thread
From: John Kitchin @ 2019-02-04 13:11 UTC (permalink / raw)
  To: Emmanuel Charpentier; +Cc: org-mode-email

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

The problem may be the name is only two characters long. Try Ahh instead.
That works for me.
John

-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



On Mon, Feb 4, 2019 at 7:00 AM Emmanuel Charpentier <emm.charpentier@free.fr>
wrote:

> Seen in `org-mode' version `9.2'.
>
> Using `noweb' syntax works OK with `emacs-lisp':
>
> ┌────
> │ #+name: a
> │ #+begin_src emacs-lisp
> │   (setq L (append L (list i)))
> │ #+end_src
> │
> │ #+name: b
> │ #+begin_src emacs-lisp :noweb yes :exports both
> │   ;; Lisp version
> │   (setq L nil)
> │   (dotimes (i 5) <<a>>)
> │   L
> │ #+end_src
> └────
>
> This gives :
>
> ┌────
> │ (setq L (append L (list i)))
> └────
>
> ┌────
> │ ;; Lisp version
> │ (setq L nil)
> │ (dotimes (i 5) )
> │ L
> └────
>
> The `noweb' syntax also works with `Sage' (a symbolic maths oriented
> Python derivative):
>
> ┌────
> │ #+name: Aaarghhh
> │ #+begin_src sage
> │   L.append(i)
> │ #+end_src
> │
> │ #+name: Berde
> │ #+begin_src sage :noweb yes :exports both
> │   ## Python version
> │   L=[]
> │   for i in range(1,6):
> │       <<Aaarghhh>>
> │   L
> │ #+end_src
> └────
>
> wich gives :
>
> ┌────
> │ L.append(i)
> └────
>
> ┌────
> │ ## Sage version
> │ L=[]
> │ for i in range(1,6):
> │
> │ L
> └────
>
> But using the same syntax in Python fails miserably:
>
> ┌────
> │ #+name: Ah
> │ #+begin_src python
> │   L.append(i)
> │ #+end_src
> │
> │ #+name: Beee
> │ #+begin_src python :noweb yes :exports both
> │   ## Python version
> │   L=[]
> │   for i in range(1,6):
> │       <<Ah>>
> │   L
> │ #+end_src
> └────
>
> ┌────
> │ L.append(i)
> └────
>
> ┌────
> │ ## Python version
> │ L=[]
> │ for i in range(1,6):
> │     <<Ah>>
> │ L
> └────
>
> ┌────
> │ []
> └────
>
>
> It *seems* that the "Ah" block is not expanded.
>
> The code itself should be sound *if* it expanded:
>
> ┌────
> │ #+name: B0
> │ #+begin_src python :exports both
> │   L=[]
> │   for i in range(1,6):
> │       L.append(i)
> │   L
> │ #+end_src
> └────
>
> ┌────
> │ L=[]
> │ for i in range(1,6):
> │     L.append(i)
> │ L
> └────
>
> ━━━━━━━━━━━━━━━
>  1  2  3  4  5
> ━━━━━━━━━━━━━━━
>
> During the compilation of the source of this mail, the following is
> printed in the `*Python*' buffer:
>
> ┌────
> │ >>> L.append(i)
> │ >>>
> │ >>> open('/tmp/babel-OJSsxf/python-dVESY4', 'w').write(str(_))
> │ >>>
> │ >>>
> │ >>> 'org_babel_python_eoe'
> │ 'org_babel_python_eoe'
> │ >>> ## Python version
> │ ... L=[]
> │ >>> for i in range(1,6):
> │ ...     <<Ah>>
> │   File "<stdin>", line 2
> │     <<Ah>>
> │      ^
> │ SyntaxError: invalid syntax
> │ >>>
> │ >>> L
> │ []
> │ >>>
> │ >>> open('/tmp/babel-OJSsxf/python-9NR46u', 'w').write(str(_))
> │ >>>
> │ >>>
> │ >>> 'org_babel_python_eoe'
> │ 'org_babel_python_eoe'
> │ >>> L=[]
> │ >>> for i in range(1,6):
> │ ...     L.append(i)
> │ ...
> │ >>> L
> │ [1, 2, 3, 4, 5]
> │ >>>
> │ >>> open('/tmp/babel-OJSsxf/python-fW5gK0', 'w').write(str(_))
> │ >>>
> │ >>>
> │ >>> 'org_babel_python_eoe'
> │ 'org_babel_python_eoe'
> │ >>>
> └────
>
> The source code of this mail is attached.
>
> --
> Emmanuel Charpentier
>

[-- Attachment #2: Type: text/html, Size: 5416 bytes --]

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

* Re: (9.2) Noweb blocks not expanded in Python blocks : it should be a bug...
  2019-02-04 13:11 ` John Kitchin
@ 2019-02-04 13:40   ` Emmanuel Charpentier
  2019-02-04 13:50     ` John Kitchin
  0 siblings, 1 reply; 7+ messages in thread
From: Emmanuel Charpentier @ 2019-02-04 13:40 UTC (permalink / raw)
  To: John Kitchin; +Cc: org-mode-email

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

Le lundi 04 février 2019 à 08:11 -0500, John Kitchin a écrit :
> The problem may be the name is only two characters long. Try Ahh
> instead. That works for me. 

Indeed. Nice catch ; how did you find this ?
Since this doesn't happen with emacs-lisp or Sage, and since nothing in
the docs I've read so far suggests anything about the length of a block
identifier, I consider this a bug in the Python language support code.
What do you think  ? Any hint ?
Thanks a lot !
--Emmanuel Charpentier
> John
> 
> -----------------------------------
> Professor John Kitchin 
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
> 
> 
> 
> On Mon, Feb 4, 2019 at 7:00 AM Emmanuel Charpentier <
> emm.charpentier@free.fr> wrote:
> > Seen in `org-mode' version `9.2'.
> > 
> > 
> > 
> > Using `noweb' syntax works OK with `emacs-lisp':
> > 
> > 
> > 
> > ┌────
> > 
> > │ #+name: a
> > 
> > │ #+begin_src emacs-lisp
> > 
> > │   (setq L (append L (list i)))
> > 
> > │ #+end_src
> > 
> > │ 
> > 
> > │ #+name: b
> > 
> > │ #+begin_src emacs-lisp :noweb yes :exports both
> > 
> > │   ;; Lisp version
> > 
> > │   (setq L nil)
> > 
> > │   (dotimes (i 5) <<a>>)
> > 
> > │   L
> > 
> > │ #+end_src
> > 
> > └────
> > 
> > 
> > 
> > This gives :
> > 
> > 
> > 
> > ┌────
> > 
> > │ (setq L (append L (list i)))
> > 
> > └────
> > 
> > 
> > 
> > ┌────
> > 
> > │ ;; Lisp version
> > 
> > │ (setq L nil)
> > 
> > │ (dotimes (i 5) )
> > 
> > │ L
> > 
> > └────
> > 
> > 
> > 
> > The `noweb' syntax also works with `Sage' (a symbolic maths
> > oriented
> > 
> > Python derivative):
> > 
> > 
> > 
> > ┌────
> > 
> > │ #+name: Aaarghhh
> > 
> > │ #+begin_src sage
> > 
> > │   L.append(i)
> > 
> > │ #+end_src
> > 
> > │ 
> > 
> > │ #+name: Berde
> > 
> > │ #+begin_src sage :noweb yes :exports both
> > 
> > │   ## Python version
> > 
> > │   L=[]
> > 
> > │   for i in range(1,6):
> > 
> > │       <<Aaarghhh>>
> > 
> > │   L
> > 
> > │ #+end_src
> > 
> > └────
> > 
> > 
> > 
> > wich gives :
> > 
> > 
> > 
> > ┌────
> > 
> > │ L.append(i)
> > 
> > └────
> > 
> > 
> > 
> > ┌────
> > 
> > │ ## Sage version
> > 
> > │ L=[]
> > 
> > │ for i in range(1,6):
> > 
> > │ 
> > 
> > │ L
> > 
> > └────
> > 
> > 
> > 
> > But using the same syntax in Python fails miserably:
> > 
> > 
> > 
> > ┌────
> > 
> > │ #+name: Ah
> > 
> > │ #+begin_src python
> > 
> > │   L.append(i)
> > 
> > │ #+end_src
> > 
> > │ 
> > 
> > │ #+name: Beee
> > 
> > │ #+begin_src python :noweb yes :exports both
> > 
> > │   ## Python version
> > 
> > │   L=[]
> > 
> > │   for i in range(1,6):
> > 
> > │       <<Ah>>
> > 
> > │   L
> > 
> > │ #+end_src
> > 
> > └────
> > 
> > 
> > 
> > ┌────
> > 
> > │ L.append(i)
> > 
> > └────
> > 
> > 
> > 
> > ┌────
> > 
> > │ ## Python version
> > 
> > │ L=[]
> > 
> > │ for i in range(1,6):
> > 
> > │     <<Ah>>
> > 
> > │ L
> > 
> > └────
> > 
> > 
> > 
> > ┌────
> > 
> > │ []
> > 
> > └────
> > 
> > 
> > 
> > 
> > 
> > It *seems* that the "Ah" block is not expanded.
> > 
> > 
> > 
> > The code itself should be sound *if* it expanded:
> > 
> > 
> > 
> > ┌────
> > 
> > │ #+name: B0
> > 
> > │ #+begin_src python :exports both
> > 
> > │   L=[]
> > 
> > │   for i in range(1,6):
> > 
> > │       L.append(i)
> > 
> > │   L
> > 
> > │ #+end_src
> > 
> > └────
> > 
> > 
> > 
> > ┌────
> > 
> > │ L=[]
> > 
> > │ for i in range(1,6):
> > 
> > │     L.append(i)
> > 
> > │ L
> > 
> > └────
> > 
> > 
> > 
> > ━━━━━━━━━━━━━━━
> > 
> >  1  2  3  4  5 
> > 
> > ━━━━━━━━━━━━━━━
> > 
> > 
> > 
> > During the compilation of the source of this mail, the following is
> > 
> > printed in the `*Python*' buffer:
> > 
> > 
> > 
> > ┌────
> > 
> > │ >>> L.append(i)
> > 
> > │ >>> 
> > 
> > │ >>> open('/tmp/babel-OJSsxf/python-dVESY4', 'w').write(str(_))
> > 
> > │ >>> 
> > 
> > │ >>> 
> > 
> > │ >>> 'org_babel_python_eoe'
> > 
> > │ 'org_babel_python_eoe'
> > 
> > │ >>> ## Python version
> > 
> > │ ... L=[]
> > 
> > │ >>> for i in range(1,6):
> > 
> > │ ...     <<Ah>>
> > 
> > │   File "<stdin>", line 2
> > 
> > │     <<Ah>>
> > 
> > │      ^
> > 
> > │ SyntaxError: invalid syntax
> > 
> > │ >>> 
> > 
> > │ >>> L
> > 
> > │ []
> > 
> > │ >>> 
> > 
> > │ >>> open('/tmp/babel-OJSsxf/python-9NR46u', 'w').write(str(_))
> > 
> > │ >>> 
> > 
> > │ >>> 
> > 
> > │ >>> 'org_babel_python_eoe'
> > 
> > │ 'org_babel_python_eoe'
> > 
> > │ >>> L=[]
> > 
> > │ >>> for i in range(1,6):
> > 
> > │ ...     L.append(i)
> > 
> > │ ... 
> > 
> > │ >>> L
> > 
> > │ [1, 2, 3, 4, 5]
> > 
> > │ >>> 
> > 
> > │ >>> open('/tmp/babel-OJSsxf/python-fW5gK0', 'w').write(str(_))
> > 
> > │ >>> 
> > 
> > │ >>> 
> > 
> > │ >>> 'org_babel_python_eoe'
> > 
> > │ 'org_babel_python_eoe'
> > 
> > │ >>> 
> > 
> > └────
> > 
> > 
> > 
> > The source code of this mail is attached.
> > 
> > 
> > 
> > --
> > 
> > Emmanuel Charpentier
> > 

[-- Attachment #2: Type: text/html, Size: 6420 bytes --]

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

* Re: (9.2) Noweb blocks not expanded in Python blocks : it should be a bug...
  2019-02-04 13:40   ` (9.2) Noweb blocks not expanded in Python blocks : it should be a bug Emmanuel Charpentier
@ 2019-02-04 13:50     ` John Kitchin
  2019-02-04 14:33       ` Robert Pluim
  0 siblings, 1 reply; 7+ messages in thread
From: John Kitchin @ 2019-02-04 13:50 UTC (permalink / raw)
  To: Emmanuel Charpentier; +Cc: org-mode-email

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

I doubt it is Python specific, and I don't know why it would work in some
places and not others. For me, the two character name does not work in
elisp, but 1 or 3 does. I agree that seems buggy.

The origin of the problem is here:

#+BEGIN_SRC emacs-lisp
(list
 (string-match (org-babel-noweb-wrap) "<<A>>")
 (string-match (org-babel-noweb-wrap) "<<Ah>>")
 (string-match (org-babel-noweb-wrap) "<<Ahh>>"))
#+END_SRC

#+RESULTS:
| 0 | nil | 0 |

my regex fu is not adequate to identify the problem:

#+BEGIN_SRC emacs-lisp
(org-babel-noweb-wrap)
#+END_SRC

#+RESULTS:
: <<\([^
: ].+?[^ ]\|[^
: ]\)>>

That function is used in org-babel-expand-noweb-references.


It is somewhat luck that I found that, I was tracing
org-babel-expand-noweb-references to see where it was failing, and walked
through that line to see it failed on "Ah", and worked on longer names.

John

-----------------------------------
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



On Mon, Feb 4, 2019 at 8:40 AM Emmanuel Charpentier <emm.charpentier@free.fr>
wrote:

> Le lundi 04 février 2019 à 08:11 -0500, John Kitchin a écrit :
>
> The problem may be the name is only two characters long. Try Ahh instead.
> That works for me.
>
>
> Indeed. Nice catch ; how did you find this ?
>
> Since this doesn't happen with emacs-lisp or Sage, and since nothing in
> the docs I've read so far suggests anything about the length of a block
> identifier, I consider this a bug in the Python language support code. What
> do you think ? Any hint ?
>
> Thanks a lot !
>
> --
> Emmanuel Charpentier
>
> John
>
> -----------------------------------
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
>
>
>
> On Mon, Feb 4, 2019 at 7:00 AM Emmanuel Charpentier <
> emm.charpentier@free.fr> wrote:
>
> Seen in `org-mode' version `9.2'.
>
> Using `noweb' syntax works OK with `emacs-lisp':
>
> ┌────
> │ #+name: a
> │ #+begin_src emacs-lisp
> │   (setq L (append L (list i)))
> │ #+end_src
> │
> │ #+name: b
> │ #+begin_src emacs-lisp :noweb yes :exports both
> │   ;; Lisp version
> │   (setq L nil)
> │   (dotimes (i 5) <<a>>)
> │   L
> │ #+end_src
> └────
>
> This gives :
>
> ┌────
> │ (setq L (append L (list i)))
> └────
>
> ┌────
> │ ;; Lisp version
> │ (setq L nil)
> │ (dotimes (i 5) )
> │ L
> └────
>
> The `noweb' syntax also works with `Sage' (a symbolic maths oriented
> Python derivative):
>
> ┌────
> │ #+name: Aaarghhh
> │ #+begin_src sage
> │   L.append(i)
> │ #+end_src
> │
> │ #+name: Berde
> │ #+begin_src sage :noweb yes :exports both
> │   ## Python version
> │   L=[]
> │   for i in range(1,6):
> │       <<Aaarghhh>>
> │   L
> │ #+end_src
> └────
>
> wich gives :
>
> ┌────
> │ L.append(i)
> └────
>
> ┌────
> │ ## Sage version
> │ L=[]
> │ for i in range(1,6):
> │
> │ L
> └────
>
> But using the same syntax in Python fails miserably:
>
> ┌────
> │ #+name: Ah
> │ #+begin_src python
> │   L.append(i)
> │ #+end_src
> │
> │ #+name: Beee
> │ #+begin_src python :noweb yes :exports both
> │   ## Python version
> │   L=[]
> │   for i in range(1,6):
> │       <<Ah>>
> │   L
> │ #+end_src
> └────
>
> ┌────
> │ L.append(i)
> └────
>
> ┌────
> │ ## Python version
> │ L=[]
> │ for i in range(1,6):
> │     <<Ah>>
> │ L
> └────
>
> ┌────
> │ []
> └────
>
>
> It *seems* that the "Ah" block is not expanded.
>
> The code itself should be sound *if* it expanded:
>
> ┌────
> │ #+name: B0
> │ #+begin_src python :exports both
> │   L=[]
> │   for i in range(1,6):
> │       L.append(i)
> │   L
> │ #+end_src
> └────
>
> ┌────
> │ L=[]
> │ for i in range(1,6):
> │     L.append(i)
> │ L
> └────
>
> ━━━━━━━━━━━━━━━
>  1  2  3  4  5
> ━━━━━━━━━━━━━━━
>
> During the compilation of the source of this mail, the following is
> printed in the `*Python*' buffer:
>
> ┌────
> │ >>> L.append(i)
> │ >>>
> │ >>> open('/tmp/babel-OJSsxf/python-dVESY4', 'w').write(str(_))
> │ >>>
> │ >>>
> │ >>> 'org_babel_python_eoe'
> │ 'org_babel_python_eoe'
> │ >>> ## Python version
> │ ... L=[]
> │ >>> for i in range(1,6):
> │ ...     <<Ah>>
> │   File "<stdin>", line 2
> │     <<Ah>>
> │      ^
> │ SyntaxError: invalid syntax
> │ >>>
> │ >>> L
> │ []
> │ >>>
> │ >>> open('/tmp/babel-OJSsxf/python-9NR46u', 'w').write(str(_))
> │ >>>
> │ >>>
> │ >>> 'org_babel_python_eoe'
> │ 'org_babel_python_eoe'
> │ >>> L=[]
> │ >>> for i in range(1,6):
> │ ...     L.append(i)
> │ ...
> │ >>> L
> │ [1, 2, 3, 4, 5]
> │ >>>
> │ >>> open('/tmp/babel-OJSsxf/python-fW5gK0', 'w').write(str(_))
> │ >>>
> │ >>>
> │ >>> 'org_babel_python_eoe'
> │ 'org_babel_python_eoe'
> │ >>>
> └────
>
> The source code of this mail is attached.
>
> --
> Emmanuel Charpentier
>
>

[-- Attachment #2: Type: text/html, Size: 8640 bytes --]

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

* Re: (9.2) Noweb blocks not expanded in Python blocks : it should be a bug...
  2019-02-04 13:50     ` John Kitchin
@ 2019-02-04 14:33       ` Robert Pluim
  2019-02-04 17:03         ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: Robert Pluim @ 2019-02-04 14:33 UTC (permalink / raw)
  To: John Kitchin; +Cc: Emmanuel Charpentier, org-mode-email

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> #+RESULTS:
> : <<\([^
> : ].+?[^ ]\|[^
> : ]\)>>

That regex looks malformed, and will only match strings with 1 or 3 or
more characters between << and >>. If someone knows what itʼs supposed
to be matching we can fix it. eg it looks like it wants to allow

<<ab
>>

Is that something that should be accepted?

Robert

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

* Re: (9.2) Noweb blocks not expanded in Python blocks : it should be a bug...
  2019-02-04 14:33       ` Robert Pluim
@ 2019-02-04 17:03         ` Nicolas Goaziou
  2019-02-05  6:51           ` Emmanuel Charpentier
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2019-02-04 17:03 UTC (permalink / raw)
  To: John Kitchin; +Cc: Emmanuel Charpentier, org-mode-email

Hello,

Robert Pluim <rpluim@gmail.com> writes:

> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
>> #+RESULTS:
>> : <<\([^
>> : ].+?[^ ]\|[^
>> : ]\)>>
>
> That regex looks malformed, and will only match strings with 1 or 3 or
> more characters between << and >>. If someone knows what itʼs supposed
> to be matching we can fix it. eg it looks like it wants to allow
>
> <<ab
>>>
>
> Is that something that should be accepted?

I fixed the regexp. Thank you.

Regards,

-- 
Nicolas Goaziou

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

* Re: (9.2) Noweb blocks not expanded in Python blocks : it should be a bug...
  2019-02-04 17:03         ` Nicolas Goaziou
@ 2019-02-05  6:51           ` Emmanuel Charpentier
  0 siblings, 0 replies; 7+ messages in thread
From: Emmanuel Charpentier @ 2019-02-05  6:51 UTC (permalink / raw)
  To: Nicolas Goaziou, John Kitchin; +Cc: org-mode-email

as of today's (20190118) org-plus-contrib, this seems fixed. Quick
check :

===================================================================
# Noweb syntax check

#+property: header-args:python :session
#+property: header-args:sage :session

#+name: A
#+begin_src sage
L.append(i)
#+end_src

#+name: B
#+begin_src sage :noweb yes :exports both
  L=[]
  for i in range(1,6):
      <<A>>
  L
#+end_src

#+name: C
#+begin_src python
L.append(i)
#+end_src

#+name: D
#+begin_src python :noweb yes :exports both
  L=[]
  for i in range(1,6):
      <<C>>
  L
#+end_src
===================================================================

Thanks a lot !

--
Emmanuel Charpentier

Le lundi 04 février 2019 à 18:03 +0100, Nicolas Goaziou a écrit :
> Hello,
> 
> Robert Pluim <rpluim@gmail.com> writes:
> 
> > John Kitchin <jkitchin@andrew.cmu.edu> writes:
> > 
> > > #+RESULTS:
> > > : <<\([^
> > > : ].+?[^ ]\|[^
> > > : ]\)>>
> > 
> > That regex looks malformed, and will only match strings with 1 or 3
> > or
> > more characters between << and >>. If someone knows what itʼs
> > supposed
> > to be matching we can fix it. eg it looks like it wants to allow
> > 
> > <<ab
> > 
> > Is that something that should be accepted?
> 
> I fixed the regexp. Thank you.
> 
> Regards,
> 

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

end of thread, other threads:[~2019-02-05  6:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-04 11:32 (9.2) Noweb blocks not expanded in Python blocks Emmanuel Charpentier
2019-02-04 13:11 ` John Kitchin
2019-02-04 13:40   ` (9.2) Noweb blocks not expanded in Python blocks : it should be a bug Emmanuel Charpentier
2019-02-04 13:50     ` John Kitchin
2019-02-04 14:33       ` Robert Pluim
2019-02-04 17:03         ` Nicolas Goaziou
2019-02-05  6:51           ` Emmanuel Charpentier

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