This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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

Created on 2017-03-10 07:40 by 0xl3vi, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 473 closed 0xl3vi, 2017-03-10 07:40
PR 13208 open ZackerySpytz, 2019-05-08 19:17
Messages (5)
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: (yan12125) * 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.
msg343375 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2019-05-24 11:34
PR 473 was closed by its author. I have created a new pull request (PR 13208) that addresses all of Berker Peksag's comments on the old PR. Please have a look.
History
Date User Action Args
2022-04-11 14:58:44adminsetgithub: 73965
2019-05-24 11:34:21ZackerySpytzsetnosy: + ZackerySpytz

messages: + msg343375
versions: + Python 3.8, - Python 3.7
2019-05-08 19:17:03ZackerySpytzsetkeywords: + patch
pull_requests: + pull_request13119
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:51yan12125setmessages: + msg289497
2017-03-12 11:13:54yan12125setnosy: + yan12125
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