Merge lp:~nmb/bzr/xdgconfigdir into lp:bzr

Proposed by Neil Martinsen-Burrell
Status: Merged
Merged at revision: 5553
Proposed branch: lp:~nmb/bzr/xdgconfigdir
Merge into: lp:bzr
Diff against target: 142 lines (+85/-1)
5 files modified
bzrlib/config.py (+18/-1)
bzrlib/tests/test_config.py (+30/-0)
doc/developers/xdg_config_spec.txt (+27/-0)
doc/en/release-notes/bzr-2.3.txt (+3/-0)
doc/en/whats-new/whats-new-in-2.3.txt (+7/-0)
To merge this branch: bzr merge lp:~nmb/bzr/xdgconfigdir
Reviewer Review Type Date Requested Status
Andrew Bennetts Approve
John A Meinel Needs Fixing
Review via email: mp+40888@code.launchpad.net

Commit message

Support configuration files located in $XDG_CONFIG_HOME/bazaar

Description of the change

As discussed on the email list, this reads configuration files in $XDG_CONFIG_HOME/bazaar if that directory exists, but has no user-visible warnings. It also doesn't change the location of the plugins directory.

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

16 if not os.path.isdir(path):
17 - if sys.platform == 'win32':
18 - parent_dir = os.path.dirname(path)
19 - if not os.path.isdir(parent_dir):
20 - trace.mutter('creating config parent directory: %r', parent_dir)
21 - os.mkdir(parent_dir)
22 + parent_dir = os.path.dirname(path)
23 + if not os.path.isdir(parent_dir):
24 + trace.mutter('creating config parent directory: %r', parent_dir)
25 + os.mkdir(parent_dir)

^- I think this breaks it for Windows. The path is "$APPDATA\Bazaar\2.0\" so we have 2 levels of directories to create, and you removed one of them.

A possible fix is to have it use "os.makedirs()" instead.

review: Needs Fixing
Revision history for this message
Neil Martinsen-Burrell (nmb) wrote :

I put the ensure_config_dir code back as it was, since the XDG_CONFIG_HOME stuff is now optional we don't have to worry about creating two levels of directories on Linux as well (which was the original intent of my code above).

Revision history for this message
Andrew Bennetts (spiv) wrote :

It looks like you've addressed John's review nicely.

In doc/developers/xdg_config_spec.txt there's a typo:

> +%APPDATA%/Bazaar/2.0 and on Mac OS X, the directory is ~/.bazaaar. With the

You don't need quite so many “a”s in bazaar :)

> Note that the following descriptions do not apply
> +to Windows or Mac OS X which can and should use their own native configuration
> +locations.

True... although is ~/.bazaar the native location for Mac OS X? I'm not sure what
is expected on OS X, and improving the OS X experience is out of scope for this
patch, but this doc shouldn't be misleading about how good we are currently.

It would be nice to have tests for this, but I guess it's awkward to do. Hmm, I
suppose it's possible by overriding the environment variables for $HOME and/or
$XDG_CONFIG_HOME. TestConfigPath in bzrlib/tests/test_config.py is probably a
good starting point.

The only other comment I have is this is worth highlighting in What's New in 2.3
as well.

I think this should have some simple tests added before we merge it, so I'm voting
Needs Fixing, but basically this is looking pretty good.

review: Needs Fixing
Revision history for this message
Neil Martinsen-Burrell (nmb) wrote :

Andrew's comments addressed with two tests in bzrlib/tests/test_config.py and better documentation. I tried to clarify our current behavior WRT Windows and Mac OS X in doc/developers/xdg_config_spec.txt

Revision history for this message
Andrew Bennetts (spiv) wrote :

Looks good, thanks! I'm going to make some very minor tweaks to the tests (give a reason to TestNotApplicable, move some duplicated test code into setUp, say “BZR_HOME” rather than “this” in the comment, add docstrings to test methods), then I'll send it to PQM.

review: Approve
Revision history for this message
Andrew Bennetts (spiv) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bzrlib/config.py'
--- bzrlib/config.py 2010-11-17 15:51:10 +0000
+++ bzrlib/config.py 2010-11-28 06:16:46 +0000
@@ -1123,7 +1123,9 @@
1123def config_dir():1123def config_dir():
1124 """Return per-user configuration directory.1124 """Return per-user configuration directory.
11251125
1126 By default this is ~/.bazaar/1126 By default this is %APPDATA%/bazaar/2.0 on Windows, ~/.bazaar on Mac OS X
1127 and Linux. On Linux, if there is a $XDG_CONFIG_HOME/bazaar directory,
1128 that will be used instead.
11271129
1128 TODO: Global option --config-dir to override this.1130 TODO: Global option --config-dir to override this.
1129 """1131 """
@@ -1137,8 +1139,23 @@
1137 raise errors.BzrError('You must have one of BZR_HOME, APPDATA,'1139 raise errors.BzrError('You must have one of BZR_HOME, APPDATA,'
1138 ' or HOME set')1140 ' or HOME set')
1139 return osutils.pathjoin(base, 'bazaar', '2.0')1141 return osutils.pathjoin(base, 'bazaar', '2.0')
1142 elif sys.platform == 'darwin':
1143 if base is None:
1144 # this takes into account $HOME
1145 base = os.path.expanduser("~")
1146 return osutils.pathjoin(base, '.bazaar')
1140 else:1147 else:
1141 if base is None:1148 if base is None:
1149
1150 xdg_dir = os.environ.get('XDG_CONFIG_HOME', None)
1151 if xdg_dir is None:
1152 xdg_dir = osutils.pathjoin(os.path.expanduser("~"), ".config")
1153 xdg_dir = osutils.pathjoin(xdg_dir, 'bazaar')
1154 if osutils.isdir(xdg_dir):
1155 trace.mutter(
1156 "Using configuration in XDG directory %s." % xdg_dir)
1157 return xdg_dir
1158
1142 base = os.path.expanduser("~")1159 base = os.path.expanduser("~")
1143 return osutils.pathjoin(base, ".bazaar")1160 return osutils.pathjoin(base, ".bazaar")
11441161
11451162
=== modified file 'bzrlib/tests/test_config.py'
--- bzrlib/tests/test_config.py 2010-11-17 15:52:03 +0000
+++ bzrlib/tests/test_config.py 2010-11-28 06:16:46 +0000
@@ -432,6 +432,36 @@
432 '/home/bogus/.cache')432 '/home/bogus/.cache')
433433
434434
435class TestXDGConfigDir(tests.TestCaseInTempDir):
436 # must be in temp dir because config tests for the existence of the bazaar
437 # subdirectory of $XDG_CONFIG_HOME
438
439 def setUp(self):
440 super(TestXDGConfigDir, self).setUp()
441 os.environ['HOME'] = self.test_home_dir
442
443 def test_xdg_config_dir_exists(self):
444 if sys.platform in ('darwin', 'win32'):
445 raise tests.TestNotApplicable
446 # this overrides everything we want to test so get rid of it
447 del os.environ['BZR_HOME']
448 newdir = osutils.pathjoin(self.test_home_dir, '.config', 'bazaar')
449 os.makedirs(newdir)
450 self.assertEqual(config.config_dir(), newdir)
451
452 def test_xdg_config_home(self):
453 if sys.platform in ('darwin', 'win32'):
454 raise tests.TestNotApplicable
455 # this overrides everything we want to test so get rid of it
456 del os.environ['BZR_HOME']
457
458 xdgconfigdir = osutils.pathjoin(self.test_home_dir, 'xdgconfig')
459 os.environ['XDG_CONFIG_HOME'] = xdgconfigdir
460 newdir = osutils.pathjoin(xdgconfigdir, 'bazaar')
461 os.makedirs(newdir)
462 self.assertEqual(config.config_dir(), newdir)
463
464
435class TestIniConfig(tests.TestCaseInTempDir):465class TestIniConfig(tests.TestCaseInTempDir):
436466
437 def make_config_parser(self, s):467 def make_config_parser(self, s):
438468
=== added file 'doc/developers/xdg_config_spec.txt'
--- doc/developers/xdg_config_spec.txt 1970-01-01 00:00:00 +0000
+++ doc/developers/xdg_config_spec.txt 2010-11-28 06:16:46 +0000
@@ -0,0 +1,27 @@
1Transitioning Unix installs to the XDG Base Directory Specification
2===================================================================
3
4Currently, Bazaar stores its configuration files and plugins under the
5directory ~/.bazaar on unix installs. On Windows, this is
6%APPDATA%/Bazaar/2.0 and on Mac OS X, the directory is ~/.bazaar. With the
7XDG Base Directory specification
8(http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html), many
9Linux and Unix platforms have tried to centralize configuration files under a
10specific directory referred to as $XDG_CONFIG_HOME. This has a default value
11of ~/.config.
12
13Bazaar would like to be a good Unix citizen by using these standard locations
14for configuration files. As such, we should support that location, but not
15require it. Note that the following descriptions do not apply
16to Windows or Mac OS X which should use their own native configuration
17locations. (On Windows, we currently do this by working under %APPDATA%. The
18Mac OS X equivalent would be ~/Library/Application Support/Bazaar but there is
19also cultural support for ~/.bazaar on that platform.)
20
21* If $XDG_CONFIG_HOME/bazaar exists, use the files there for configuration,
22 noting in the log that we are doing so. This allows individuals who would
23 like to use the XDG specification to do so.
24* Due to a lack of consensus on where plugins should live under the XDG Base
25 Directory spec, continue to look for plugins in ~/.bazaar/plugins. To
26 change this directory to something not under ~/.bazaar, use the environment
27 variable $BZR_PLUGIN_PATH.
028
=== modified file 'doc/en/release-notes/bzr-2.3.txt'
--- doc/en/release-notes/bzr-2.3.txt 2010-11-26 15:57:20 +0000
+++ doc/en/release-notes/bzr-2.3.txt 2010-11-28 06:16:46 +0000
@@ -39,6 +39,9 @@
39 number of remaining conflicts. This provides a better feedback about the39 number of remaining conflicts. This provides a better feedback about the
40 whole resolution process. (Vincent Ladeuil)40 whole resolution process. (Vincent Ladeuil)
4141
42* Read configuration files in $XDG_CONFIG_HOME/bazaar on Unix if there is
43 already a directory there. (Neil Martinsen-Burrell, #195397)
44
42Bug Fixes45Bug Fixes
43*********46*********
4447
4548
=== modified file 'doc/en/whats-new/whats-new-in-2.3.txt'
--- doc/en/whats-new/whats-new-in-2.3.txt 2010-11-22 03:35:24 +0000
+++ doc/en/whats-new/whats-new-in-2.3.txt 2010-11-28 06:16:46 +0000
@@ -38,6 +38,13 @@
38 get the old behavior, one can use ``bzr tags --sort=alpha``.38 get the old behavior, one can use ``bzr tags --sort=alpha``.
39 (Neil Martinsen-Burrell, #640760)39 (Neil Martinsen-Burrell, #640760)
4040
41* On platforms other than Windows and Mac OS X, Bazaar will use configuration
42 files that live in $XDG_CONFIG_HOME/bazaar if that directory exists. This
43 allows interested individuals to conform to the XDG Base Directory
44 specification. The plugin location has not changed and is still
45 ~/.bazaar/plugins. To use a different directory for plugins, use the
46 environment variable BZR_PLUGIN_PATH. (Neil Martinsen-Burrell, #195397)
47
41Launchpad integration48Launchpad integration
42*********************49*********************
4350