* [PATCH] ob-python: Rename exec tmpfile handle to prevent conflict
@ 2020-10-06 21:44 Adrian Kummerländer
0 siblings, 0 replies; 7+ messages in thread
From: Adrian Kummerländer @ 2020-10-06 21:44 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 416 bytes --]
Hello,
I noticed that after updating to Org 9.4 many of my Python-based Org
files fail to execute with various `io.TextIOWrapper' related error
messages. The reason for this is that opening the exec tmpfile as `f'
shadows this possibly user-defined variable.
The attached patch fixes this problem for me. As this is my first
time contributing to Org I am especially open for any suggestions!
Best wishes,
Adrian
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ob-python: Rename exec tmpfile handle to prevent conflict --]
[-- Type: text/x-patch, Size: 2739 bytes --]
From 239aa9aaa8da0f98719469abdff46ecb7a3994ba Mon Sep 17 00:00:00 2001
From: Adrian Kummerlaender <adrian@kummerlaender.eu>
Date: Tue, 6 Oct 2020 23:06:08 +0200
Subject: [PATCH] ob-python: Rename exec tmpfile handle to prevent conflict
* lisp/ob-python.el (org-babel-python--exec-tmpfile): Rename tmpfile handle
(org-babel-python-format-session-value): Rename tmpfile handle
Opening the exec tmpfile as a `f' variable shadows any such variable
that might by defined by the Python session context. e.g. my Org babel
files commonly pass single letter variables inside a session which is
broken by this behavior.
The new name `__org_babel_python_tmpfile' is in line with other org
mode specific Python variables set by ob-python. This is unlikely to
conflict with the user's Python code.
---
lisp/ob-python.el | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/lisp/ob-python.el b/lisp/ob-python.el
index 785b9191b..6752adc17 100644
--- a/lisp/ob-python.el
+++ b/lisp/ob-python.el
@@ -244,8 +244,8 @@ def main():
open('%s', 'w').write( pprint.pformat(main()) )")
(defconst org-babel-python--exec-tmpfile "\
-with open('%s') as f:
- exec(compile(f.read(), f.name, 'exec'))"
+with open('%s') as __org_babel_python_tmpfile:
+ exec(compile(__org_babel_python_tmpfile.read(), __org_babel_python_tmpfile.name, 'exec'))"
"Template for Python session command with output results.
Has a single %s escape, the tempfile containing the source code
@@ -256,20 +256,20 @@ to evaluate.")
"Return Python code to evaluate SRC-FILE and write result to RESULT-FILE."
(format "\
import ast
-with open('%s') as f:
- __org_babel_python_ast = ast.parse(f.read())
+with open('%s') as __org_babel_python_tmpfile:
+ __org_babel_python_ast = ast.parse(__org_babel_python_tmpfile.read())
__org_babel_python_final = __org_babel_python_ast.body[-1]
if isinstance(__org_babel_python_final, ast.Expr):
__org_babel_python_ast.body = __org_babel_python_ast.body[:-1]
exec(compile(__org_babel_python_ast, '<string>', 'exec'))
__org_babel_python_final = eval(compile(ast.Expression(
__org_babel_python_final.value), '<string>', 'eval'))
- with open('%s', 'w') as f:
+ with open('%s', 'w') as __org_babel_python_tmpfile:
if %s:
import pprint
- f.write(pprint.pformat(__org_babel_python_final))
+ __org_babel_python_tmpfile.write(pprint.pformat(__org_babel_python_final))
else:
- f.write(str(__org_babel_python_final))
+ __org_babel_python_tmpfile.write(str(__org_babel_python_final))
else:
exec(compile(__org_babel_python_ast, '<string>', 'exec'))
__org_babel_python_final = None"
--
2.25.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH] ob-python: Rename exec tmpfile handle to prevent conflict
@ 2020-10-07 6:27 Adrian Kummerländer
2020-10-10 23:10 ` Jack Kamm
0 siblings, 1 reply; 7+ messages in thread
From: Adrian Kummerländer @ 2020-10-07 6:27 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 417 bytes --]
Hello,
I noticed that after updating to Org 9.4 many of my Python-based Org
files fail to execute with various `io.TextIOWrapper' related error
messages. The reason for this is that opening the exec tmpfile as `f'
shadows this possibly user-defined variable.
The attached patch fixes this problem for me. As this is my first
time contributing to Org I am especially open for any suggestions!
Best regards,
Adrian
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ob-python: Rename exec tmpfile handle to prevent conflict --]
[-- Type: text/x-patch, Size: 2739 bytes --]
From 239aa9aaa8da0f98719469abdff46ecb7a3994ba Mon Sep 17 00:00:00 2001
From: Adrian Kummerlaender <adrian@kummerlaender.eu>
Date: Tue, 6 Oct 2020 23:06:08 +0200
Subject: [PATCH] ob-python: Rename exec tmpfile handle to prevent conflict
* lisp/ob-python.el (org-babel-python--exec-tmpfile): Rename tmpfile handle
(org-babel-python-format-session-value): Rename tmpfile handle
Opening the exec tmpfile as a `f' variable shadows any such variable
that might by defined by the Python session context. e.g. my Org babel
files commonly pass single letter variables inside a session which is
broken by this behavior.
The new name `__org_babel_python_tmpfile' is in line with other org
mode specific Python variables set by ob-python. This is unlikely to
conflict with the user's Python code.
---
lisp/ob-python.el | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/lisp/ob-python.el b/lisp/ob-python.el
index 785b9191b..6752adc17 100644
--- a/lisp/ob-python.el
+++ b/lisp/ob-python.el
@@ -244,8 +244,8 @@ def main():
open('%s', 'w').write( pprint.pformat(main()) )")
(defconst org-babel-python--exec-tmpfile "\
-with open('%s') as f:
- exec(compile(f.read(), f.name, 'exec'))"
+with open('%s') as __org_babel_python_tmpfile:
+ exec(compile(__org_babel_python_tmpfile.read(), __org_babel_python_tmpfile.name, 'exec'))"
"Template for Python session command with output results.
Has a single %s escape, the tempfile containing the source code
@@ -256,20 +256,20 @@ to evaluate.")
"Return Python code to evaluate SRC-FILE and write result to RESULT-FILE."
(format "\
import ast
-with open('%s') as f:
- __org_babel_python_ast = ast.parse(f.read())
+with open('%s') as __org_babel_python_tmpfile:
+ __org_babel_python_ast = ast.parse(__org_babel_python_tmpfile.read())
__org_babel_python_final = __org_babel_python_ast.body[-1]
if isinstance(__org_babel_python_final, ast.Expr):
__org_babel_python_ast.body = __org_babel_python_ast.body[:-1]
exec(compile(__org_babel_python_ast, '<string>', 'exec'))
__org_babel_python_final = eval(compile(ast.Expression(
__org_babel_python_final.value), '<string>', 'eval'))
- with open('%s', 'w') as f:
+ with open('%s', 'w') as __org_babel_python_tmpfile:
if %s:
import pprint
- f.write(pprint.pformat(__org_babel_python_final))
+ __org_babel_python_tmpfile.write(pprint.pformat(__org_babel_python_final))
else:
- f.write(str(__org_babel_python_final))
+ __org_babel_python_tmpfile.write(str(__org_babel_python_final))
else:
exec(compile(__org_babel_python_ast, '<string>', 'exec'))
__org_babel_python_final = None"
--
2.25.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] ob-python: Rename exec tmpfile handle to prevent conflict
2020-10-07 6:27 Adrian Kummerländer
@ 2020-10-10 23:10 ` Jack Kamm
2020-10-24 11:53 ` Bastien
0 siblings, 1 reply; 7+ messages in thread
From: Jack Kamm @ 2020-10-10 23:10 UTC (permalink / raw)
To: Adrian Kummerländer, emacs-orgmode
Hi Adrian,
Adrian Kummerländer <adrian.kummerlaender@student.kit.edu> writes:
> I noticed that after updating to Org 9.4 many of my Python-based Org
> files fail to execute with various `io.TextIOWrapper' related error
> messages. The reason for this is that opening the exec tmpfile as `f'
> shadows this possibly user-defined variable.
>
> The attached patch fixes this problem for me. As this is my first
> time contributing to Org I am especially open for any suggestions!
The patch looks good. I've pushed it to master, after making a couple
minor fixes to the commit message (adding a TINYCHANGE cookie and
adjusting some of the spacing).
Thanks for your contribution!
Jack
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ob-python: Rename exec tmpfile handle to prevent conflict
2020-10-10 23:10 ` Jack Kamm
@ 2020-10-24 11:53 ` Bastien
2020-10-24 14:06 ` Jack Kamm
0 siblings, 1 reply; 7+ messages in thread
From: Bastien @ 2020-10-24 11:53 UTC (permalink / raw)
To: Jack Kamm; +Cc: emacs-orgmode, Adrian Kummerländer
Hi Jack and Adrian,
Jack Kamm <jackkamm@gmail.com> writes:
> Adrian Kummerländer <adrian.kummerlaender@student.kit.edu> writes:
>
>> I noticed that after updating to Org 9.4 many of my Python-based Org
>> files fail to execute with various `io.TextIOWrapper' related error
>> messages. The reason for this is that opening the exec tmpfile as `f'
>> shadows this possibly user-defined variable.
>>
>> The attached patch fixes this problem for me. As this is my first
>> time contributing to Org I am especially open for any suggestions!
>
> The patch looks good. I've pushed it to master, after making a couple
> minor fixes to the commit message (adding a TINYCHANGE cookie and
> adjusting some of the spacing).
Thanks for applying the patch, I'm marking it as "applied" through
Woof! adding "X-Woof-Patch: applied" in the headers.
Best,
--
Bastien
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ob-python: Rename exec tmpfile handle to prevent conflict
2020-10-24 11:53 ` Bastien
@ 2020-10-24 14:06 ` Jack Kamm
2020-10-24 14:50 ` Bastien
0 siblings, 1 reply; 7+ messages in thread
From: Jack Kamm @ 2020-10-24 14:06 UTC (permalink / raw)
To: Bastien; +Cc: emacs-orgmode, Adrian Kummerländer
Thanks Bastien, the Woof! tool looks interesting.
By the way, on seeing this thread again, I realized this patch probably should have been applied to the maint branch. So I've cherry picked it into there, and merged back into master.
Bastien <bzg@gnu.org> writes:
> Hi Jack and Adrian,
>
> Jack Kamm <jackkamm@gmail.com> writes:
>
>> Adrian Kummerländer <adrian.kummerlaender@student.kit.edu> writes:
>>
>>> I noticed that after updating to Org 9.4 many of my Python-based Org
>>> files fail to execute with various `io.TextIOWrapper' related error
>>> messages. The reason for this is that opening the exec tmpfile as `f'
>>> shadows this possibly user-defined variable.
>>>
>>> The attached patch fixes this problem for me. As this is my first
>>> time contributing to Org I am especially open for any suggestions!
>>
>> The patch looks good. I've pushed it to master, after making a couple
>> minor fixes to the commit message (adding a TINYCHANGE cookie and
>> adjusting some of the spacing).
>
> Thanks for applying the patch, I'm marking it as "applied" through
> Woof! adding "X-Woof-Patch: applied" in the headers.
>
> Best,
>
> --
> Bastien
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ob-python: Rename exec tmpfile handle to prevent conflict
2020-10-24 14:06 ` Jack Kamm
@ 2020-10-24 14:50 ` Bastien
2020-10-25 13:25 ` stardiviner
0 siblings, 1 reply; 7+ messages in thread
From: Bastien @ 2020-10-24 14:50 UTC (permalink / raw)
To: Jack Kamm; +Cc: emacs-orgmode, Adrian Kummerländer
Hi Jack,
Jack Kamm <jackkamm@gmail.com> writes:
> Thanks Bastien, the Woof! tool looks interesting.
Thanks! I'm working on a small woof.el package to make it more
useful for both maintainers (setting headers) and users (checking
upcoming changes or help requests).
> By the way, on seeing this thread again, I realized this patch
> probably should have been applied to the maint branch. So I've cherry
> picked it into there, and merged back into master.
Thanks for this!
--
Bastien
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ob-python: Rename exec tmpfile handle to prevent conflict
2020-10-24 14:50 ` Bastien
@ 2020-10-25 13:25 ` stardiviner
0 siblings, 0 replies; 7+ messages in thread
From: stardiviner @ 2020-10-25 13:25 UTC (permalink / raw)
To: Bastien; +Cc: Jack Kamm, emacs-orgmode, Adrian Kummerländer
Bastien <bzg@gnu.org> writes:
> Hi Jack,
>
> Jack Kamm <jackkamm@gmail.com> writes:
>
>> Thanks Bastien, the Woof! tool looks interesting.
>
> Thanks! I'm working on a small woof.el package to make it more
> useful for both maintainers (setting headers) and users (checking
> upcoming changes or help requests).
>
This is great and helpful! Thanks Bastien.
>> By the way, on seeing this thread again, I realized this patch
>> probably should have been applied to the maint branch. So I've cherry
>> picked it into there, and merged back into master.
>
> Thanks for this!
--
[ stardiviner ]
I try to make every word tell the meaning that I want to express.
Blog: https://stardiviner.github.io/
IRC(freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-10-26 9:21 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-06 21:44 [PATCH] ob-python: Rename exec tmpfile handle to prevent conflict Adrian Kummerländer
-- strict thread matches above, loose matches on Subject: below --
2020-10-07 6:27 Adrian Kummerländer
2020-10-10 23:10 ` Jack Kamm
2020-10-24 11:53 ` Bastien
2020-10-24 14:06 ` Jack Kamm
2020-10-24 14:50 ` Bastien
2020-10-25 13:25 ` stardiviner
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).