Skip to content

Commit

Permalink
Merge pull request #582 from TC01/dotconfig
Browse files Browse the repository at this point in the history
XDG compliance for Unix/Linux (~/.config)
  • Loading branch information
pnasrat committed Oct 23, 2012
2 parents 74a4e65 + b4a3133 commit 319289f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Andrey Bulgakov
Antti Kaihola
Armin Ronacher
Aziz Köksal
Ben Rosser
Brian Rosner
Carl Meyer
Chris McDonough
Expand Down
3 changes: 2 additions & 1 deletion docs/configuration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ Location
The names and locations of the configuration files vary slightly across
platforms.

On Unix and Mac OS X the configuration file is: :file:`$HOME/.pip/pip.conf`
On Unix and Mac OS X the configuration file is:
:file:`$HOME/.config/pip/pip.conf`

And on Windows, the configuration file is: :file:`%HOME%\\pip\\pip.ini`

Expand Down
5 changes: 4 additions & 1 deletion docs/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ develop (unreleased)
Hsiaoming Yang and Markus Hametner.

* Use a temporary directory as the default build location outside of a
virtualenv. Fixes issues #339 and #381. Thanks TC01.
virtualenv. Fixes issues #339 and #381. Thanks Ben Rosser.

* Moved pip configuration data to ~/.config/pip, the XDG standard for config
files on Unix/Linux systems. Thanks Ben Rosser.

* Added support for specifying extras with local editables. Thanks Nick
Stenning.
Expand Down
23 changes: 22 additions & 1 deletion pip/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import site
import os
import shutil
import tempfile
from pip.backwardcompat import get_python_lib

Expand Down Expand Up @@ -60,9 +61,29 @@ def virtualenv_no_global():
default_log_file = os.path.join(default_storage_dir, 'pip.log')
else:
bin_py = os.path.join(sys.prefix, 'bin')
default_storage_dir = os.path.join(user_dir, '.pip')

# Use XDG_CONFIG_HOME instead of the ~/.pip
# On some systems, we may have to create this, on others it probably exists
xdg_dir = os.path.join(user_dir, '.config')
xdg_dir = os.environ.get('XDG_CONFIG_HOME', xdg_dir)
if not os.path.exists(xdg_dir):
os.mkdir(xdg_dir)
default_storage_dir = os.path.join(xdg_dir, 'pip')
default_config_file = os.path.join(default_storage_dir, 'pip.conf')
default_log_file = os.path.join(default_storage_dir, 'pip.log')

# Migration path for users- move things from the old dir if it exists
# If the new dir exists and has no pip.conf and the old dir does, move it
# When these checks are finished, delete the old directory
old_storage_dir = os.path.join(user_dir, '.pip')
old_config_file = os.path.join(old_storage_dir, 'pip.conf')
if os.path.exists(old_storage_dir):
if not os.path.exists(default_storage_dir):
shutil.copytree(old_storage_dir, default_storage_dir)
elif os.path.exists(old_config_file) and not os.path.exists(default_config_file):
shutil.copy2(old_config_file, default_config_file)
shutil.rmtree(old_storage_dir)

# Forcing to use /usr/local/bin for standard Mac OS X framework installs
# Also log to ~/Library/Logs/ for use with the Console.app log viewer
if sys.platform[:6] == 'darwin' and sys.prefix[:16] == '/System/Library/':
Expand Down

2 comments on commit 319289f

@qwcode
Copy link
Contributor

@qwcode qwcode commented on 319289f Oct 30, 2012

Choose a reason for hiding this comment

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

@pnasrat this shutil migration code is troublesome. my test runs keep migrating my config out from under the main pip I'm using on my machine. I'm inclined to take the migration out? maybe add a pip_migration console script instead? or just leave it up to the users?

@pnasrat
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm fine to take it out, make it conditional or prompt or some external script.

Please sign in to comment.