classification
Title: New environment variable PYTHONHISTORY
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: 0xl3vi, Chi Hsuan Yen, barry, berker.peksag, serhiy.storchaka
Priority: normal Keywords:

Created on 2017-03-10 07:40 by 0xl3vi, last changed 2017-03-22 08:51 by berker.peksag.

Pull Requests
URL Status Linked Edit
PR 473 closed 0xl3vi, 2017-03-10 07:40
Messages (4)
msg289342 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-10 08:10
$HISTFILE is the name of the file in which Bash command history is saved. Shouldn't the name of similar environment variable for Python be PYTHONHISTFILE?

Bash uses several environment variables for control its command history: HISTCONTROL, HISTFILE, HISTFILESIZE, HISTIGNORE, HISTSIZE, HISTTIMEFORMAT. Does Python need corresponding environment variables?

Wouldn't be better to control all these details by Python code in .pythonrc.py rather than by environment variables? For example I have the following code in my .pythonrc.py:

if sys.version_info < (3,):
    try:
        import readline, os, atexit
        histfile = os.path.join(os.path.expanduser("~"), ".python2_history")
        try:
            readline.read_history_file(histfile)
        except IOError:
            pass
        atexit.register(readline.write_history_file, histfile)
        del os, histfile
    except ImportError:
        pass
msg289402 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2017-03-10 18:57
I don't think the Python envar has to follow the contraction from bash.  $PYTHONHISTORY reads very nicely.

I have similar code in my $PYTHONSTARTUP, but it would be nice to be able to get rid of it and just let Python do the common thing.
msg289497 - (view) Author: Chi Hsuan Yen (Chi Hsuan Yen) * Date: 2017-03-12 11:42
That's a great feature! Here's a question: what should be CPython's behavior when PYTHONHISTORY is explicitly set to empty? Currently there's an error:

$ PYTHONHISTORY= ./python
Python 3.7.0a0 (master:f6595983e08fe20cf06a2535d74d912c6dbb044f, Mar 12 2017, 19:22:29) 
[GCC 6.3.1 20170306] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
Error in atexit._run_exitfuncs:
FileNotFoundError: [Errno 2] No such file or directory

Maybe it's better to just disable the history functionality in this case?

By the way, seems comments starting from https://github.com/python/cpython/pull/473/files#diff-f34a16518c608b2ca946d3f5ca0a1942R419 should be updated too.
msg289624 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2017-03-14 22:05
On Mar 12, 2017, at 11:42 AM, Chi Hsuan Yen wrote:

>That's a great feature! Here's a question: what should be CPython's behavior
>when PYTHONHISTORY is explicitly set to empty? Currently there's an error:
>
>$ PYTHONHISTORY= ./python
>Python 3.7.0a0 (master:f6595983e08fe20cf06a2535d74d912c6dbb044f, Mar 12 2017, 19:22:29) 
>[GCC 6.3.1 20170306] on linux
>Type "help", "copyright", "credits" or "license" for more information.
>>>>   
>Error in atexit._run_exitfuncs:
>FileNotFoundError: [Errno 2] No such file or directory

Yeah, that's not good.  I'll note that in the PR.

(But also note that you have to unset PYTHONSTARTUP if you, like me, use that
as the old school way of enabling history.)

>Maybe it's better to just disable the history functionality in this case?

It should use the default, but it shouldn't cause an error.
History
Date User Action Args
2017-03-22 08:51:06berker.peksagsetnosy: + berker.peksag

type: enhancement
components: + Library (Lib)
stage: patch review
2017-03-14 22:05:22barrysetmessages: + msg289624
2017-03-12 11:42:51Chi Hsuan Yensetmessages: + msg289497
2017-03-12 11:13:54Chi Hsuan Yensetnosy: + Chi Hsuan Yen
2017-03-10 18:57:13barrysetmessages: + msg289402
2017-03-10 18:54:06barrysetnosy: + barry
2017-03-10 08:10:24serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg289342
2017-03-10 07:40:030xl3vicreate