Merge lp://staging/~jelmer/bzr/cachedir into lp://staging/bzr
Proposed by
Jelmer Vernooij
Status: | Rejected |
---|---|
Rejected by: | Jelmer Vernooij |
Proposed branch: | lp://staging/~jelmer/bzr/cachedir |
Merge into: | lp://staging/bzr |
Diff against target: |
200 lines (+93/-23) 2 files modified
bzrlib/config.py (+38/-13) bzrlib/tests/test_config.py (+55/-10) |
To merge this branch: | bzr merge lp://staging/~jelmer/bzr/cachedir |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Martin Packman (community) | Needs Fixing | ||
John A Meinel | Needs Fixing | ||
Review via email:
|
Description of the change
Add a cache_dir() function in bzrlib.config.
The foreign branch plugins and bzr-search currently all duplicate this code in
one form or another, so it would be nice to have it in bzrlib.
There are a few things I'm not certain about:
* using xdg.BaseDirectory versus just environment variables for the xdg stuff.
The environment variables don't always seem to be set, even on xdg systems like Ubuntu, but does that justify another import?
* Nothing in bzr relies on this during tests at the moment, but perhaps we'd like to override cache_dir during tests on Windows
to avoid cluttering the users' actual cache directory.
To post a comment you must log in.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 8/14/2011 5:45 PM, Jelmer Vernooij wrote: /code.launchpad .net/~jelmer/ bzr/cachedir/ +merge/ 71486
> Jelmer Vernooij has proposed merging lp:~jelmer/bzr/cachedir into
> lp:bzr.
>
> Requested reviews: bzr-core (bzr-core)
>
> For more details, see:
> https:/
>
> Add a cache_dir() function in bzrlib.config.
>
> The foreign branch plugins and bzr-search currently all duplicate
> this code in one form or another, so it would be nice to have it in
> bzrlib.
>
> There are a few things I'm not certain about:
>
> * using xdg.BaseDirectory versus just environment variables for the
> xdg stuff. The environment variables don't always seem to be set,
> even on xdg systems like Ubuntu, but does that justify another
> import?
>
> * Nothing in bzr relies on this during tests at the moment, but
> perhaps we'd like to override cache_dir during tests on Windows to
> avoid cluttering the users' actual cache directory.
I don't think we want a try/except ImportError in the middle of live
code. Because then the import gets tried on every call, and fails each
time. Can we pull it out somewhere? Possibly just a function call that
caches negative results.
+
+def cache_dir():
+ """Return the cache directory to use."""
+ if sys.platform in ("nt", "win32"):
sys.platform should always be "win32" I think it is os.name that is 'nt'.
And if we get a 'str' out of Windows, then it should be decoded with user_encoding' . user_encoding is deprecated anyway, get_user_ encoding( )" but that is terminal encoding,
"mbcs" not 'bzrlib.
vs using "osutils.
not filesystem encoding or file content encoding.
xdg_cache_dir seems to be a public function, so I'm not sure why you're
just removing it. (I really don't know who has been calling it.)
+ if cache_dir is None: expanduser( '~/.cache' )
+ cache_dir = os.path.
Shouldn't this somehow be a bzr specific cache directory?
+class TestXDGCacheDir (tests. TestCaseInTempD ir):
You are using just "cache_dir()" as the function name, so the test class
should match.
+ def setUp(self): plicable( cheDir, self).setUp() v('HOME' , self.test_home_dir) v('BZR_ HOME', None) cache_dir_ exists( self): pathjoin( self.test_ home_dir, '.cache') pathjoin( cachedir, 'bazaar') tr(BaseDirector y, "xdg_cache_home", cachedir) l(config. cache_dir( ), newdir)
+ if sys.platform in ('darwin', 'win32'):
+ raise tests.TestNotAp
+ 'XDG cache dir not used on this platform')
+ super(TestXDGCa
+ self.overrideEn
+ # BZR_HOME overrides everything we want to test so unset it.
+ self.overrideEn
+
+ def test_xdg_
+ """When ~/.cache/bazaar exists, use it as the config dir."""
+ cachedir = osutils.
+ newdir = osutils.
+ try:
+ from xdg import BaseDirectory
+ except ImportError:
+ pass
+ else:
+ self.overrideAt
+ os.makedirs(newdir)
+ self.assertEqua
I don't see how this test could pass if 'xdg' wasn't present, since you
don't set the cache location any other way. As such, it would seem that
the try/except in this location function is superfluous. And if you want
to t...