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
1=== modified file 'bzrlib/config.py'
2--- bzrlib/config.py 2010-11-17 15:51:10 +0000
3+++ bzrlib/config.py 2010-11-28 06:16:46 +0000
4@@ -1123,7 +1123,9 @@
5 def config_dir():
6 """Return per-user configuration directory.
7
8- By default this is ~/.bazaar/
9+ By default this is %APPDATA%/bazaar/2.0 on Windows, ~/.bazaar on Mac OS X
10+ and Linux. On Linux, if there is a $XDG_CONFIG_HOME/bazaar directory,
11+ that will be used instead.
12
13 TODO: Global option --config-dir to override this.
14 """
15@@ -1137,8 +1139,23 @@
16 raise errors.BzrError('You must have one of BZR_HOME, APPDATA,'
17 ' or HOME set')
18 return osutils.pathjoin(base, 'bazaar', '2.0')
19+ elif sys.platform == 'darwin':
20+ if base is None:
21+ # this takes into account $HOME
22+ base = os.path.expanduser("~")
23+ return osutils.pathjoin(base, '.bazaar')
24 else:
25 if base is None:
26+
27+ xdg_dir = os.environ.get('XDG_CONFIG_HOME', None)
28+ if xdg_dir is None:
29+ xdg_dir = osutils.pathjoin(os.path.expanduser("~"), ".config")
30+ xdg_dir = osutils.pathjoin(xdg_dir, 'bazaar')
31+ if osutils.isdir(xdg_dir):
32+ trace.mutter(
33+ "Using configuration in XDG directory %s." % xdg_dir)
34+ return xdg_dir
35+
36 base = os.path.expanduser("~")
37 return osutils.pathjoin(base, ".bazaar")
38
39
40=== modified file 'bzrlib/tests/test_config.py'
41--- bzrlib/tests/test_config.py 2010-11-17 15:52:03 +0000
42+++ bzrlib/tests/test_config.py 2010-11-28 06:16:46 +0000
43@@ -432,6 +432,36 @@
44 '/home/bogus/.cache')
45
46
47+class TestXDGConfigDir(tests.TestCaseInTempDir):
48+ # must be in temp dir because config tests for the existence of the bazaar
49+ # subdirectory of $XDG_CONFIG_HOME
50+
51+ def setUp(self):
52+ super(TestXDGConfigDir, self).setUp()
53+ os.environ['HOME'] = self.test_home_dir
54+
55+ def test_xdg_config_dir_exists(self):
56+ if sys.platform in ('darwin', 'win32'):
57+ raise tests.TestNotApplicable
58+ # this overrides everything we want to test so get rid of it
59+ del os.environ['BZR_HOME']
60+ newdir = osutils.pathjoin(self.test_home_dir, '.config', 'bazaar')
61+ os.makedirs(newdir)
62+ self.assertEqual(config.config_dir(), newdir)
63+
64+ def test_xdg_config_home(self):
65+ if sys.platform in ('darwin', 'win32'):
66+ raise tests.TestNotApplicable
67+ # this overrides everything we want to test so get rid of it
68+ del os.environ['BZR_HOME']
69+
70+ xdgconfigdir = osutils.pathjoin(self.test_home_dir, 'xdgconfig')
71+ os.environ['XDG_CONFIG_HOME'] = xdgconfigdir
72+ newdir = osutils.pathjoin(xdgconfigdir, 'bazaar')
73+ os.makedirs(newdir)
74+ self.assertEqual(config.config_dir(), newdir)
75+
76+
77 class TestIniConfig(tests.TestCaseInTempDir):
78
79 def make_config_parser(self, s):
80
81=== added file 'doc/developers/xdg_config_spec.txt'
82--- doc/developers/xdg_config_spec.txt 1970-01-01 00:00:00 +0000
83+++ doc/developers/xdg_config_spec.txt 2010-11-28 06:16:46 +0000
84@@ -0,0 +1,27 @@
85+Transitioning Unix installs to the XDG Base Directory Specification
86+===================================================================
87+
88+Currently, Bazaar stores its configuration files and plugins under the
89+directory ~/.bazaar on unix installs. On Windows, this is
90+%APPDATA%/Bazaar/2.0 and on Mac OS X, the directory is ~/.bazaar. With the
91+XDG Base Directory specification
92+(http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html), many
93+Linux and Unix platforms have tried to centralize configuration files under a
94+specific directory referred to as $XDG_CONFIG_HOME. This has a default value
95+of ~/.config.
96+
97+Bazaar would like to be a good Unix citizen by using these standard locations
98+for configuration files. As such, we should support that location, but not
99+require it. Note that the following descriptions do not apply
100+to Windows or Mac OS X which should use their own native configuration
101+locations. (On Windows, we currently do this by working under %APPDATA%. The
102+Mac OS X equivalent would be ~/Library/Application Support/Bazaar but there is
103+also cultural support for ~/.bazaar on that platform.)
104+
105+* If $XDG_CONFIG_HOME/bazaar exists, use the files there for configuration,
106+ noting in the log that we are doing so. This allows individuals who would
107+ like to use the XDG specification to do so.
108+* Due to a lack of consensus on where plugins should live under the XDG Base
109+ Directory spec, continue to look for plugins in ~/.bazaar/plugins. To
110+ change this directory to something not under ~/.bazaar, use the environment
111+ variable $BZR_PLUGIN_PATH.
112
113=== modified file 'doc/en/release-notes/bzr-2.3.txt'
114--- doc/en/release-notes/bzr-2.3.txt 2010-11-26 15:57:20 +0000
115+++ doc/en/release-notes/bzr-2.3.txt 2010-11-28 06:16:46 +0000
116@@ -39,6 +39,9 @@
117 number of remaining conflicts. This provides a better feedback about the
118 whole resolution process. (Vincent Ladeuil)
119
120+* Read configuration files in $XDG_CONFIG_HOME/bazaar on Unix if there is
121+ already a directory there. (Neil Martinsen-Burrell, #195397)
122+
123 Bug Fixes
124 *********
125
126
127=== modified file 'doc/en/whats-new/whats-new-in-2.3.txt'
128--- doc/en/whats-new/whats-new-in-2.3.txt 2010-11-22 03:35:24 +0000
129+++ doc/en/whats-new/whats-new-in-2.3.txt 2010-11-28 06:16:46 +0000
130@@ -38,6 +38,13 @@
131 get the old behavior, one can use ``bzr tags --sort=alpha``.
132 (Neil Martinsen-Burrell, #640760)
133
134+* On platforms other than Windows and Mac OS X, Bazaar will use configuration
135+ files that live in $XDG_CONFIG_HOME/bazaar if that directory exists. This
136+ allows interested individuals to conform to the XDG Base Directory
137+ specification. The plugin location has not changed and is still
138+ ~/.bazaar/plugins. To use a different directory for plugins, use the
139+ environment variable BZR_PLUGIN_PATH. (Neil Martinsen-Burrell, #195397)
140+
141 Launchpad integration
142 *********************
143