Skip to content

gh-88405: Use platform defined data directories instead of ~/.python_history #26377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

oxalica
Copy link

@oxalica oxalica commented May 26, 2021

Currently we use path ~/.python_history for history file in all platforms.
It is not a good choice since it spams in user's home directory.

This patch use platform defined directories for put the history file.
For Windows, it's %APPDATA%/Python/history;
for Mac OS, it's ~/Library/Application Support/Python/history;
for other POSIX platforms, it's $XDG_STATE_HOME/python/history or ~/.local/state/python/history;
otherwise, fallback to ~/.python_history.

Also if ~/.python_history exists and is readable, it will always be used for compatibility.

https://bugs.python.org/issue44239

@the-knights-who-say-ni

This comment was marked as resolved.

@Ayushparikh-code

This comment was marked as resolved.

@oxalica

This comment was marked as resolved.

@Ayushparikh-code

This comment was marked as resolved.

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Jun 28, 2021
@oxalica
Copy link
Author

oxalica commented Jun 28, 2021

This PR is stale because it has been open for 30 days with no activity.

How can I ask for review? I'm not sure whom to notify.

@Ayushparikh-code
Copy link
Contributor

This PR is stale because it has been open for 30 days with no activity.

How can I ask for review? I'm not sure whom to notify.

Alright

@github-actions github-actions bot removed the stale Stale PR or inactive for long period of time. label Jun 29, 2021
@SvartaHjarta
Copy link

.python_history probably belongs under $XDG_STATE_HOME on linux rather than $XDG_DATA_HOME

The $XDG_STATE_HOME contains state data that should persist between (application) restarts, but that is not important or portable enough to the user that it should be stored in $XDG_DATA_HOME. It may contain:

  • actions history (logs, history, recently used files, …)
  • current state of the application that can be reused on a restart (view, layout, open files, undo history, …)

Then again just getting it out of user root would be nice.

@oxalica oxalica force-pushed the fix/xdg-history-path branch from f4758ed to dc505f9 Compare September 24, 2021 18:42
@oxalica
Copy link
Author

oxalica commented Sep 24, 2021

Changed to $XDG_STATE_HOME/python/history or ~/.local/state/python/history for *nix platform now.

@eabase
Copy link

eabase commented Jan 24, 2022

Instead of you hard-coding a commonly used and often changed file-path like this, please consider using an internal built-in variable named something like DEFAULT_HISTORY_FILE. instead.

mentioned #13208

@yochem
Copy link

yochem commented Jan 11, 2023

Any updates on this? Btw, please let MacOS users also set XDG_STATE_HOME. A lot of them use the XDG specification (and if they don't, then it's just the default location you already specified)

@MestreLion
Copy link

Any chance for this to move forward?

@arhadthedev arhadthedev changed the title bpo-44239: Use platform defined data directories instead of ~/.python_history gh-88405: Use platform defined data directories instead of ~/.python_history Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants