public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] set/show python dont-write-bytecode fixes
@ 2022-07-23 21:23 Kevin Buettner
  2022-07-24  5:40 ` Eli Zaretskii
  2022-07-25  1:04 ` Simon Marchi
  0 siblings, 2 replies; 4+ messages in thread
From: Kevin Buettner @ 2022-07-23 21:23 UTC (permalink / raw)
  To: gdb-patches; +Cc: Kevin Buettner, Simon Marchi, Eli Zaretskii, Pedro Alves

GDB uses the environment variable PYTHONDONTWRITEBYTECODE to
determine whether or not to write the result of byte-compiling
python modules when the "python dont-write-bytecode" setting
is "auto".  Simon noticed that GDB's implementation doesn't
follow the Python documentation.

At present, GDB only checks for the existence of this environment
variable.  That is not sufficient though.  Regarding
PYTHONDONTWRITEBYTECODE, this document...

    https://docs.python.org/3/using/cmdline.html

...says:

    If this is set to a non-empty string, Python won't try to write
    .pyc files on the import of source modules.

This commit fixes GDB's handling of PYTHONDONTWRITEBYTECODE by adding
an empty string check.

This commit also corrects the set/show command documentation for
"python dont-write-bytecode".  The current doc was just a copy
of that for set/show python ignore-environment.

During his review of an earlier version of this patch, Eli Zaretskii
asked that the help text that I proposed for "set/show python
dont-write-bytecode" be expanded.  I've done that in addition to
clarifying the documentation of this option in the GDB manual.
---
 gdb/doc/python.texi | 11 ++++++++---
 gdb/python/python.c | 32 +++++++++++++++++++++++++-------
 2 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index eeb847aeaa8..6d7bb832c22 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -134,9 +134,14 @@ initialized early during @value{GDBN}'s startup process, then this
 option must be placed into the early initialization file
 (@pxref{Initialization Files}) to have the desired effect.
 
-By default this option is set to @samp{auto}, in this mode Python will
-check the environment variable @env{PYTHONDONTWRITEBYTECODE} to see
-if it should write out byte-code or not.
+By default this option is set to @samp{auto}.  In this mode, provided
+the @code{python ignore-environment} setting is @samp{off}, the
+environment variable @env{PYTHONDONTWRITEBYTECODE} is examined to see
+if it should write out byte-code or not. 
+@env{PYTHONDONTWRITEBYTECODE} is considered to be off/disabled either
+when set to the empty string or when the environment variable doesn't
+exist.  All other settings, including those which don't seem to make
+sense, indicate that it's on/enabled.
 
 This option is equivalent to passing @option{-B} to the real
 @command{python} executable.
diff --git a/gdb/python/python.c b/gdb/python/python.c
index c7d4157b70c..7997bee2c69 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1866,8 +1866,15 @@ python_write_bytecode ()
   int wbc = 0;
 
   if (python_dont_write_bytecode == AUTO_BOOLEAN_AUTO)
-    wbc = (!python_ignore_environment
-	    && getenv ("PYTHONDONTWRITEBYTECODE") != nullptr) ? 0 : 1;
+    {
+      if (python_ignore_environment)
+	wbc = 1;
+      else
+	{
+	  const char *pdwbc = getenv ("PYTHONDONTWRITEBYTECODE");
+	  wbc = (pdwbc == nullptr || pdwbc[0] == '\0') ? 1 : 0;
+	}
+    }
   else
     wbc = python_dont_write_bytecode == AUTO_BOOLEAN_TRUE ? 0 : 1;
 
@@ -2346,11 +2353,22 @@ python executable."),
 
   add_setshow_auto_boolean_cmd ("dont-write-bytecode", no_class,
 				&python_dont_write_bytecode, _("\
-Set whether the Python interpreter should ignore environment variables."), _(" \
-Show whether the Python interpreter showlist ignore environment variables."), _(" \
-When enabled GDB's Python interpreter will ignore any Python related\n	\
-flags in the environment.  This is equivalent to passing `-E' to a\n	\
-python executable."),
+Set whether the Python interpreter should avoid byte-compiling python modules."), _("\
+Show whether the Python interpreter should avoid byte-compiling python modules."), _("\
+When enabled, GDB's embedded Python interpreter won't byte-compile python\n\
+modules.  In order to take effect, this setting must be enabled in an early\n\
+initialization file, i.e. those run via the --early-init-eval-command or\n\
+-eix command line options.  A 'set python dont-write-bytecode on' command\n\
+can also be issued directly from the GDB command line via the\n\
+--early-init-eval-command or -eiex command line options.\n\
+\n\
+This setting defaults to 'auto'.  In this mode, provided the 'python\n\
+ignore-environment' setting is 'off', the environment variable\n\
+PYTHONDONTWRITEBYTECODE is examined to determine whether or not to\n\
+byte-compile python modules.  PYTHONDONTWRITEBYTECODE is considered to be\n\
+off/disabled either when set to the empty string or when the\n\
+environment variable doesn't exist.  All other settings, including those\n\
+which don't seem to make sense, indicate that it's on/enabled."),
 				set_python_dont_write_bytecode,
 				show_python_dont_write_bytecode,
 				&user_set_python_list,
-- 
2.36.1


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

* Re: [PATCH v2] set/show python dont-write-bytecode fixes
  2022-07-23 21:23 [PATCH v2] set/show python dont-write-bytecode fixes Kevin Buettner
@ 2022-07-24  5:40 ` Eli Zaretskii
  2022-07-25  1:04 ` Simon Marchi
  1 sibling, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2022-07-24  5:40 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: gdb-patches, simark, pedro

> From: Kevin Buettner <kevinb@redhat.com>
> Cc: Kevin Buettner <kevinb@redhat.com>,
> 	Simon Marchi <simark@simark.ca>,
> 	Eli Zaretskii <eliz@gnu.org>,
> 	Pedro Alves <pedro@palves.net>
> Date: Sat, 23 Jul 2022 14:23:25 -0700
> 
> GDB uses the environment variable PYTHONDONTWRITEBYTECODE to
> determine whether or not to write the result of byte-compiling
> python modules when the "python dont-write-bytecode" setting
> is "auto".  Simon noticed that GDB's implementation doesn't
> follow the Python documentation.
> 
> At present, GDB only checks for the existence of this environment
> variable.  That is not sufficient though.  Regarding
> PYTHONDONTWRITEBYTECODE, this document...
> 
>     https://docs.python.org/3/using/cmdline.html
> 
> ...says:
> 
>     If this is set to a non-empty string, Python won't try to write
>     .pyc files on the import of source modules.
> 
> This commit fixes GDB's handling of PYTHONDONTWRITEBYTECODE by adding
> an empty string check.
> 
> This commit also corrects the set/show command documentation for
> "python dont-write-bytecode".  The current doc was just a copy
> of that for set/show python ignore-environment.
> 
> During his review of an earlier version of this patch, Eli Zaretskii
> asked that the help text that I proposed for "set/show python
> dont-write-bytecode" be expanded.  I've done that in addition to
> clarifying the documentation of this option in the GDB manual.
> ---
>  gdb/doc/python.texi | 11 ++++++++---
>  gdb/python/python.c | 32 +++++++++++++++++++++++++-------
>  2 files changed, 33 insertions(+), 10 deletions(-)

Thanks, the documentation parts are fine in this version.

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

* Re: [PATCH v2] set/show python dont-write-bytecode fixes
  2022-07-23 21:23 [PATCH v2] set/show python dont-write-bytecode fixes Kevin Buettner
  2022-07-24  5:40 ` Eli Zaretskii
@ 2022-07-25  1:04 ` Simon Marchi
  2022-07-25 19:07   ` Kevin Buettner
  1 sibling, 1 reply; 4+ messages in thread
From: Simon Marchi @ 2022-07-25  1:04 UTC (permalink / raw)
  To: Kevin Buettner, gdb-patches; +Cc: Eli Zaretskii, Pedro Alves



On 2022-07-23 17:23, Kevin Buettner wrote:
> GDB uses the environment variable PYTHONDONTWRITEBYTECODE to
> determine whether or not to write the result of byte-compiling
> python modules when the "python dont-write-bytecode" setting
> is "auto".  Simon noticed that GDB's implementation doesn't
> follow the Python documentation.
> 
> At present, GDB only checks for the existence of this environment
> variable.  That is not sufficient though.  Regarding
> PYTHONDONTWRITEBYTECODE, this document...
> 
>     https://docs.python.org/3/using/cmdline.html
> 
> ...says:
> 
>     If this is set to a non-empty string, Python won't try to write
>     .pyc files on the import of source modules.
> 
> This commit fixes GDB's handling of PYTHONDONTWRITEBYTECODE by adding
> an empty string check.
> 
> This commit also corrects the set/show command documentation for
> "python dont-write-bytecode".  The current doc was just a copy
> of that for set/show python ignore-environment.
> 
> During his review of an earlier version of this patch, Eli Zaretskii
> asked that the help text that I proposed for "set/show python
> dont-write-bytecode" be expanded.  I've done that in addition to
> clarifying the documentation of this option in the GDB manual.
> ---
>  gdb/doc/python.texi | 11 ++++++++---
>  gdb/python/python.c | 32 +++++++++++++++++++++++++-------
>  2 files changed, 33 insertions(+), 10 deletions(-)
> 
> diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
> index eeb847aeaa8..6d7bb832c22 100644
> --- a/gdb/doc/python.texi
> +++ b/gdb/doc/python.texi
> @@ -134,9 +134,14 @@ initialized early during @value{GDBN}'s startup process, then this
>  option must be placed into the early initialization file
>  (@pxref{Initialization Files}) to have the desired effect.
>  
> -By default this option is set to @samp{auto}, in this mode Python will
> -check the environment variable @env{PYTHONDONTWRITEBYTECODE} to see
> -if it should write out byte-code or not.
> +By default this option is set to @samp{auto}.  In this mode, provided
> +the @code{python ignore-environment} setting is @samp{off}, the
> +environment variable @env{PYTHONDONTWRITEBYTECODE} is examined to see
> +if it should write out byte-code or not. 

Spurious space at the end of this line.  Otherwise, LGTM.

Simon

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

* Re: [PATCH v2] set/show python dont-write-bytecode fixes
  2022-07-25  1:04 ` Simon Marchi
@ 2022-07-25 19:07   ` Kevin Buettner
  0 siblings, 0 replies; 4+ messages in thread
From: Kevin Buettner @ 2022-07-25 19:07 UTC (permalink / raw)
  To: gdb-patches

On Sun, 24 Jul 2022 21:04:58 -0400
Simon Marchi <simark@simark.ca> wrote:

> On 2022-07-23 17:23, Kevin Buettner wrote:
> >  
> > -By default this option is set to @samp{auto}, in this mode Python will
> > -check the environment variable @env{PYTHONDONTWRITEBYTECODE} to see
> > -if it should write out byte-code or not.
> > +By default this option is set to @samp{auto}.  In this mode, provided
> > +the @code{python ignore-environment} setting is @samp{off}, the
> > +environment variable @env{PYTHONDONTWRITEBYTECODE} is examined to see
> > +if it should write out byte-code or not.   
> 
> Spurious space at the end of this line.  Otherwise, LGTM.

Fixed and pushed.

Kevin


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

end of thread, other threads:[~2022-07-25 19:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-23 21:23 [PATCH v2] set/show python dont-write-bytecode fixes Kevin Buettner
2022-07-24  5:40 ` Eli Zaretskii
2022-07-25  1:04 ` Simon Marchi
2022-07-25 19:07   ` Kevin Buettner

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