From 390917d3a5e24875c0e09de9a53ca7bb58e71e6f Mon Sep 17 00:00:00 2001 From: Ben Rosser Date: Mon, 21 May 2012 22:10:50 -0400 Subject: [PATCH 1/8] Moved configuration and logging to .config for XDG compliance --- pip/locations.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pip/locations.py b/pip/locations.py index 25e4cfc20ab..50c516647a6 100644 --- a/pip/locations.py +++ b/pip/locations.py @@ -47,6 +47,12 @@ def running_under_virtualenv(): default_log_file = os.path.join(default_storage_dir, 'pip.log') else: bin_py = os.path.join(sys.prefix, 'bin') + + #Use ~/.config/pip instead of ~/.pip- cleaner home folder + #On some systems, we may have to create this, on others it probably exists + if not os.path.exists(os.path.join(user_dir, '.config')): + os.mkdir(os.path.join(user_dir, '.config')) + default_storage_dir = os.path.join(user_dir, '.pip') default_config_file = os.path.join(default_storage_dir, 'pip.conf') default_log_file = os.path.join(default_storage_dir, 'pip.log') From 5442218c6d98ff1fc8bc9269ee1f20e553103636 Mon Sep 17 00:00:00 2001 From: Ben Rosser Date: Mon, 21 May 2012 22:14:25 -0400 Subject: [PATCH 2/8] Fixed commit #1 to actually work --- pip/locations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pip/locations.py b/pip/locations.py index 50c516647a6..31eeadbde09 100644 --- a/pip/locations.py +++ b/pip/locations.py @@ -52,8 +52,8 @@ def running_under_virtualenv(): #On some systems, we may have to create this, on others it probably exists if not os.path.exists(os.path.join(user_dir, '.config')): os.mkdir(os.path.join(user_dir, '.config')) + default_storage_dir = os.path.join(user_dir, '.config', 'pip') - default_storage_dir = os.path.join(user_dir, '.pip') default_config_file = os.path.join(default_storage_dir, 'pip.conf') default_log_file = os.path.join(default_storage_dir, 'pip.log') # Forcing to use /usr/local/bin for standard Mac OS X framework installs From 882227a0e976c4bcbd67d11bcc2d5e2cba57da97 Mon Sep 17 00:00:00 2001 From: Ben Rosser Date: Mon, 21 May 2012 22:37:46 -0400 Subject: [PATCH 3/8] Switched to use XDG_CONFIG_DIR environment variable if possible (default to ~/.config if not) --- pip/locations.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pip/locations.py b/pip/locations.py index 31eeadbde09..4abe8c0a029 100644 --- a/pip/locations.py +++ b/pip/locations.py @@ -13,7 +13,6 @@ def running_under_virtualenv(): """ return hasattr(sys, 'real_prefix') - if running_under_virtualenv(): ## FIXME: is build/ a good name? build_prefix = os.path.join(sys.prefix, 'build') @@ -22,8 +21,8 @@ def running_under_virtualenv(): #Use tempfile to create a temporary folder build_prefix = tempfile.mkdtemp('-build', 'pip-') src_prefix = tempfile.mkdtemp('-src', 'pip-') - #This is a terrible hack- since pip relies on this directory not being created yet - #We will delete it now, and have pip recreate it later + # This is a terrible hack- since pip relies on this directory not being created yet + # We will delete it now, and have pip recreate it later os.rmdir(build_prefix) os.rmdir(src_prefix) @@ -47,12 +46,14 @@ def running_under_virtualenv(): default_log_file = os.path.join(default_storage_dir, 'pip.log') else: bin_py = os.path.join(sys.prefix, 'bin') - - #Use ~/.config/pip instead of ~/.pip- cleaner home folder - #On some systems, we may have to create this, on others it probably exists - if not os.path.exists(os.path.join(user_dir, '.config')): - os.mkdir(os.path.join(user_dir, '.config')) - default_storage_dir = os.path.join(user_dir, '.config', 'pip') + + # Use XDG_CONFIG_DIR 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_DIR', 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') From 3a23763dfe489faa70faa3404f04aa6f6402d04e Mon Sep 17 00:00:00 2001 From: Ben Rosser Date: Wed, 23 May 2012 15:26:01 -0400 Subject: [PATCH 4/8] Added migration path from ~/.pip to ~/.config/pip --- pip/locations.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pip/locations.py b/pip/locations.py index 4abe8c0a029..c675c0eac39 100644 --- a/pip/locations.py +++ b/pip/locations.py @@ -2,6 +2,7 @@ import sys import os +import shutil import tempfile from pip.backwardcompat import get_python_lib @@ -47,16 +48,27 @@ def running_under_virtualenv(): else: bin_py = os.path.join(sys.prefix, 'bin') - # Use XDG_CONFIG_DIR instead of the ~/.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_DIR', xdg_dir) + 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') + 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(os.path.join(old_storage_dir, 'pip.conf')) and not os.path.exists(default_config_file): + shutil.copy2(os.path.join(old_storage_dir, 'pip.conf'), 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/': From 51051964dfb8c7826165faff3c336a8e027c4620 Mon Sep 17 00:00:00 2001 From: Ben Rosser Date: Wed, 30 May 2012 11:43:55 -0400 Subject: [PATCH 5/8] Minor fixes --- pip/locations.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pip/locations.py b/pip/locations.py index c675c0eac39..63be35b04c6 100644 --- a/pip/locations.py +++ b/pip/locations.py @@ -19,13 +19,13 @@ def running_under_virtualenv(): build_prefix = os.path.join(sys.prefix, 'build') src_prefix = os.path.join(sys.prefix, 'src') else: - #Use tempfile to create a temporary folder - build_prefix = tempfile.mkdtemp('-build', 'pip-') - src_prefix = tempfile.mkdtemp('-src', 'pip-') - # This is a terrible hack- since pip relies on this directory not being created yet - # We will delete it now, and have pip recreate it later - os.rmdir(build_prefix) - os.rmdir(src_prefix) + try: + ## FIXME: this isn't a very good default + build_prefix = os.path.join(os.getcwd(), 'build') + src_prefix = os.path.join(os.getcwd(), 'src') + except OSError: + # In case the current working directory has been renamed or deleted + sys.exit("The folder you are executing pip from can no longer be found.") # under Mac OS X + virtualenv sys.prefix is not properly resolved # it is something like /path/to/python/bin/.. @@ -62,11 +62,12 @@ def running_under_virtualenv(): # 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(os.path.join(old_storage_dir, 'pip.conf')) and not os.path.exists(default_config_file): - shutil.copy2(os.path.join(old_storage_dir, 'pip.conf'), default_config_file) + 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 From 5d9c7e56f3bfee2104f3c7b2c13f21503667b21a Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 19 Jun 2012 19:10:09 -0400 Subject: [PATCH 6/8] Re-add import shutil that got lost in merge --- pip/locations.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pip/locations.py b/pip/locations.py index 7cbc35d658f..daf86139cea 100644 --- a/pip/locations.py +++ b/pip/locations.py @@ -3,6 +3,7 @@ import sys import site import os +import shutil import tempfile from pip.backwardcompat import get_python_lib From 0202fc839e8073fd674368e9574c99468d800f3b Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 23 Jun 2012 22:15:08 -0400 Subject: [PATCH 7/8] Documented change and added author --- AUTHORS.txt | 1 + docs/configuration.txt | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index 515eb20e2f1..c1ea6f49f5b 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -3,6 +3,7 @@ Alex Morega Alexandre Conrad Antti Kaihola Armin Ronacher +Ben Rosser Brian Rosner Carl Meyer Christian Oudard diff --git a/docs/configuration.txt b/docs/configuration.txt index 35d0a347f41..a1302b04d8f 100644 --- a/docs/configuration.txt +++ b/docs/configuration.txt @@ -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` From cd679a14aafa99c8368011d09e3fdc563a7a0751 Mon Sep 17 00:00:00 2001 From: Ben Rosser Date: Thu, 4 Oct 2012 20:30:36 -0400 Subject: [PATCH 8/8] Added changelog entry to news.txt --- docs/news.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/news.txt b/docs/news.txt index f3d34a6dc76..99e59489e31 100644 --- a/docs/news.txt +++ b/docs/news.txt @@ -20,7 +20,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.