Skip to content

gh-73965: New environment variable PYTHON_HISTORY#13208

Merged
hauntsaninja merged 7 commits into
python:mainfrom
ZackerySpytz:bpo-29779-PYTHONHISTORY-env-var
Jan 7, 2024
Merged

gh-73965: New environment variable PYTHON_HISTORY#13208
hauntsaninja merged 7 commits into
python:mainfrom
ZackerySpytz:bpo-29779-PYTHONHISTORY-env-var

Conversation

@ZackerySpytz

@ZackerySpytz ZackerySpytz commented May 8, 2019

Copy link
Copy Markdown
Contributor

It can be used to set the location of a .python_history file.

Co-Authored-By: Levi Sabah 0xl3vi@gmail.com

It can be used to set the location of a .python_history file.

Co-Authored-By: Levi Sabah <0xl3vi@gmail.com>
Comment thread Doc/using/cmdline.rst Outdated
Comment thread Lib/site.py Outdated
Comment thread Lib/site.py Outdated
Comment thread Misc/python.man Outdated
can be set to the callable of your debugger of choice.
.IP PYTHONHISTORY
This environment variable can be used to set the location of a history file
(it is \fI~/.python_history\fP by default).

@pablogsal pablogsal May 10, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add the windows default as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be frank, I'm not sure if the Windows default should be mentioned in the man page...

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is nothing wrong with mentioning Windows ops in man pages.

@tirkarthi

Copy link
Copy Markdown
Member

There are few other places in Docs where hardcoded value of ~/.python_history is referred to.

$ rg python_history Doc
Doc/tutorial/interactive.rst
28:history into a file named :file:`.python_history` in your user directory.

Doc/library/readline.rst
292:file named :file:`.python_history` from the user's home directory.  The code
300:   histfile = os.path.join(os.path.expanduser("~"), ".python_history")
319:   histfile = os.path.join(os.path.expanduser("~"), ".python_history")

Doc/library/site.rst
135::file:`~/.python_history` as the history save file.  To disable it, delete (or

@ZackerySpytz

Copy link
Copy Markdown
Contributor Author

@tirkarthi The first three cases mention .python_history, not ~/.python_history, no?

The fourth case mentions ~/.python_history in the context of the readline
module, which is not available on Windows. So, I'm not sure if those parts of
the docs need to be modified.

@ZackerySpytz

Copy link
Copy Markdown
Contributor Author

By the way, on Windows, os.path.expanduser("~") returns (for example) 'C:\\Users\\Tim'.

tiran
tiran previously requested changes May 15, 2019

@tiran tiran left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new env var does not obey the sys.flags.ignore_environment flag. Please add a test that the new env var is ignored with -E or -I mode.

@bedevere-bot

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@tiran

tiran commented May 15, 2019

Copy link
Copy Markdown
Member

Could you please reword to explain what the history file actually does? It's non-obvious to users that are not familiar with readline module internals.

Comment thread Lib/site.py
@ZackerySpytz

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again.

@bedevere-bot

Copy link
Copy Markdown

Thanks for making the requested changes!

@tiran: please review the changes made to this pull request.

@ZackerySpytz

Copy link
Copy Markdown
Contributor Author

Could you please reword to explain what the history file actually does?

Reword what?

@vszakats

Copy link
Copy Markdown

Can this be merged? It seems fairly obvious what .python_history means and it'd be quite nice to be able to control where it goes.

@EmilRehnberg

Copy link
Copy Markdown

Thanks for this!

Please make sure there will be no problem with paths with subdirectories that might not be created. E.g. "export PYTHONHISTORY=$HOME/.cache/python/history please assert that the path will be created if missing.

@wren

wren commented Jul 4, 2020

Copy link
Copy Markdown

Any way to help get this through? It looks like it's been ready for a while.

@warsaw

warsaw commented Oct 22, 2021

Copy link
Copy Markdown
Member

Looks like there are conflicts now which need to be resolved, and probably rebased.

@eabase

eabase commented Jan 24, 2022

Copy link
Copy Markdown

Guys, why on earth are you hard-coding a commonly used and often changed file-path like this?

I was sincerely expecting to find an internal built-in variable named something like DEFAULT_HISTORY_FILE, but to my unpleasant surprise, I instead find history = os.path.join(os.path.expanduser('~'),'.python_history').

While at the same time being met with:

readline.write_history_file.__doc__
# 'Save a readline history file. The default filename is ~/.history.'

@lucas-mior

This comment was marked as abuse.

@hugovk hugovk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve the merge conflicts.

Comment thread Doc/using/cmdline.rst Outdated
Comment thread Doc/using/cmdline.rst Outdated
Comment thread Doc/whatsnew/3.8.rst Outdated
Comment thread Lib/site.py Outdated
Comment thread Lib/site.py Outdated
Comment thread Lib/test/test_site.py Outdated
Comment thread Misc/NEWS.d/next/Library/2019-05-08-13-14-11.bpo-29779.jg33dp.rst Outdated
Comment thread Misc/python.man Outdated
Comment thread Python/initconfig.c Outdated
@hugovk hugovk changed the title bpo-29779: New environment variable PYTHONHISTORY gh-73965: New environment variable PYTHON_HISTORY Dec 26, 2023
@serhiy-storchaka serhiy-storchaka self-requested a review December 26, 2023 11:28
@hugovk

hugovk commented Jan 4, 2024

Copy link
Copy Markdown
Member

I've resolved conflicts, renamed to PYTHON_HISTORY and targeted 3.13.

@hauntsaninja

Copy link
Copy Markdown
Contributor

Thanks Hugo!

@hauntsaninja hauntsaninja merged commit f19b93f into python:main Jan 7, 2024
Comment thread Python/initconfig.c
"PYTHON_COLORS : If this variable is set to 1, the interpreter will"
" colorize various kinds of output. Setting it to 0 deactivates this behavior.\n"
"These variables have equivalent command-line parameters (see --help for details):\n"
"PYTHON_HISTORY: the location of a .python_history file.\n"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What command line parameter sets it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't have one, I compared with PYTHON_COLORS which doesn't either (#112732). Should we add one?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it doesn't have one, then it is in the wrong section.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, please see PR #113798 to move it to the correct section.

kulikjak pushed a commit to kulikjak/cpython that referenced this pull request Jan 22, 2024
It can be used to set the location of a .python_history file

---------

Co-authored-by: Levi Sabah <0xl3vi@gmail.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
It can be used to set the location of a .python_history file

---------

Co-authored-by: Levi Sabah <0xl3vi@gmail.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
It can be used to set the location of a .python_history file

---------

Co-authored-by: Levi Sabah <0xl3vi@gmail.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
rbutoi pushed a commit to rbutoi/dotfiles that referenced this pull request Nov 6, 2024
thanks to
https://unix.stackexchange.com/questions/630642/change-location-of-python-history
- don't use a new folder cause 1) no need for just 1 file 2) python won't make
it for you, will just fail to write
history. [`xdg-ninja`](https://github.com/b3nj5m1n/xdg-ninja) is good, we need
more all-in-one places for doing config like this. but it's more or less just a
community thing

will need a place for these lines in zshrc /shrug

+ try some LSP servers
+ bat hard-wraps, less -S is nice
rbutoi added a commit to rbutoi/dotfiles that referenced this pull request Jan 28, 2026
thanks to
https://unix.stackexchange.com/questions/630642/change-location-of-python-history
- don't use a new folder cause 1) no need for just 1 file 2) python won't make
it for you, will just fail to write
history. [`xdg-ninja`](https://github.com/b3nj5m1n/xdg-ninja) is good, we need
more all-in-one places for doing config like this. but it's more or less just a
community thing

will need a place for these lines in zshrc /shrug

+ try some LSP servers
+ bat hard-wraps, less -S is nice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.