Skip to content

Commit a76c94c

Browse files
doc cleanup
1 parent 9e3daa7 commit a76c94c

File tree

5 files changed

+29
-17
lines changed

5 files changed

+29
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
### Added
2626
* Add `__slots__` and `__eq__` to `FileVersionInfo` for memory usage optimization and ease of testing
2727
* Add support for SSE-C server-side encryption mode
28+
* Add support for `XDG_CONFIG_HOME` for determining the location of `SqliteAccountInfo` db file
2829

2930
### Changed
3031
* `BasicSyncEncryptionSettingsProvider` supports different settings sets for reading and writing

b2sdk/_v2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from b2sdk.account_info.abstract import AbstractAccountInfo
3535
from b2sdk.account_info.in_memory import InMemoryAccountInfo
3636
from b2sdk.account_info.sqlite_account_info import SqliteAccountInfo
37-
from b2sdk.account_info.sqlite_account_info import B2_ACCOUNT_INFO_ENV_VAR, B2_ACCOUNT_INFO_DEFAULT_FILE
37+
from b2sdk.account_info.sqlite_account_info import B2_ACCOUNT_INFO_ENV_VAR, B2_ACCOUNT_INFO_DEFAULT_FILE, XDG_CONFIG_HOME_ENV_VAR
3838
from b2sdk.account_info.stub import StubAccountInfo
3939
from b2sdk.account_info.upload_url_pool import UploadUrlPool
4040
from b2sdk.account_info.upload_url_pool import UrlPoolAccountInfo

b2sdk/account_info/sqlite_account_info.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
B2_ACCOUNT_INFO_ENV_VAR = 'B2_ACCOUNT_INFO'
2626
B2_ACCOUNT_INFO_DEFAULT_FILE = '~/.b2_account_info'
27+
XDG_CONFIG_HOME_ENV_VAR = 'XDG_CONFIG_HOME'
2728

2829

2930
class SqliteAccountInfo(UrlPoolAccountInfo):
@@ -44,13 +45,14 @@ def __init__(self, file_name=None, last_upgrade_to_run=None):
4445
instead, use ``self.filename`` to get the actual resolved location.
4546
4647
SqliteAccountInfo currently checks locations in the following order:
48+
4749
* ``file_name``, if truthy
48-
* ``B2_ACCOUNT_INFO_ENV_VAR``'s value, if set
49-
* ``~/.b2_account_info``, if it exists
50-
* ``$XDG_CONFIG_HOME/b2/account_info``, if XDG_CONFIG_HOME is set
51-
* ``~/.b2_account_info``, as default
50+
* ``{B2_ACCOUNT_INFO_ENV_VAR}`` env var's value, if set
51+
* ``{B2_ACCOUNT_INFO_DEFAULT_FILE}``, if it exists
52+
* ``{XDG_CONFIG_HOME_ENV_VAR}/b2/account_info``, if ``{XDG_CONFIG_HOME_ENV_VAR}`` env var is set
53+
* ``{B2_ACCOUNT_INFO_DEFAULT_FILE}``, as default
5254
53-
If the directory ``$XDG_CONFIG_HOME/b2`` does not exist, it is created.
55+
If the directory ``{XDG_CONFIG_HOME_ENV_VAR}/b2`` does not exist (and is needed), it is created.
5456
5557
:param str file_name: The sqlite file to use; overrides the default.
5658
:param int last_upgrade_to_run: For testing only, override the auto-update on the db.
@@ -63,8 +65,8 @@ def __init__(self, file_name=None, last_upgrade_to_run=None):
6365
user_account_info_path = os.environ[B2_ACCOUNT_INFO_ENV_VAR]
6466
elif os.path.exists(os.path.expanduser(B2_ACCOUNT_INFO_DEFAULT_FILE)):
6567
user_account_info_path = B2_ACCOUNT_INFO_DEFAULT_FILE
66-
elif 'XDG_CONFIG_HOME' in os.environ:
67-
config_home = os.environ['XDG_CONFIG_HOME']
68+
elif XDG_CONFIG_HOME_ENV_VAR in os.environ:
69+
config_home = os.environ[XDG_CONFIG_HOME_ENV_VAR]
6870
user_account_info_path = os.path.join(config_home, 'b2', 'account_info')
6971
if not os.path.exists(os.path.join(config_home, 'b2')):
7072
os.makedirs(os.path.join(config_home, 'b2'), mode=0o755)
@@ -79,6 +81,16 @@ def __init__(self, file_name=None, last_upgrade_to_run=None):
7981
self._create_tables(conn, last_upgrade_to_run)
8082
super(SqliteAccountInfo, self).__init__()
8183

84+
# dirty trick to use parameters in the docstring
85+
if getattr(__init__, '__doc__', None): # don't break when using `python -oo`
86+
__init__.__doc__ = __init__.__doc__.format(
87+
**dict(
88+
B2_ACCOUNT_INFO_ENV_VAR=B2_ACCOUNT_INFO_ENV_VAR,
89+
B2_ACCOUNT_INFO_DEFAULT_FILE=B2_ACCOUNT_INFO_DEFAULT_FILE,
90+
XDG_CONFIG_HOME_ENV_VAR=XDG_CONFIG_HOME_ENV_VAR,
91+
)
92+
)
93+
8294
def _validate_database(self, last_upgrade_to_run=None):
8395
"""
8496
Make sure that the database is openable. Removes the file if it's not.

b2sdk/v1/account_info.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
logger = logging.getLogger(__name__)
1919

20+
2021
class OldAccountInfoMethods:
2122
def set_auth_data(
2223
self,

test/unit/account_info/test_account_info.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import pytest
2020

21-
from apiver_deps import AbstractAccountInfo, InMemoryAccountInfo, UploadUrlPool, SqliteAccountInfo, TempDir, B2_ACCOUNT_INFO_ENV_VAR
21+
from apiver_deps import AbstractAccountInfo, InMemoryAccountInfo, UploadUrlPool, SqliteAccountInfo, TempDir, B2_ACCOUNT_INFO_ENV_VAR, XDG_CONFIG_HOME_ENV_VAR
2222
from apiver_deps_exception import CorruptAccountInfo, MissingAccountData
2323

2424
from .fixtures import *
@@ -348,11 +348,9 @@ def _make_sqlite_account_info(self, env=None, last_upgrade_to_run=None):
348348
)
349349

350350
def test_uses_default(self):
351-
account_info = self._make_sqlite_account_info(
352-
env={
353-
'HOME': self.home,
354-
}
355-
)
351+
account_info = self._make_sqlite_account_info(env={
352+
'HOME': self.home,
353+
})
356354
actual_path = os.path.abspath(account_info.filename)
357355
assert os.path.join(self.home, '.b2_account_info') == actual_path
358356

@@ -361,7 +359,7 @@ def test_uses_xdg_config_home(self, apiver):
361359
account_info = self._make_sqlite_account_info(
362360
env={
363361
'HOME': self.home,
364-
'XDG_CONFIG_HOME': d,
362+
XDG_CONFIG_HOME_ENV_VAR: d,
365363
}
366364
)
367365
if apiver in ['v0', 'v1']:
@@ -379,7 +377,7 @@ def test_uses_existing_file_and_ignores_xdg(self):
379377
account_info = self._make_sqlite_account_info(
380378
env={
381379
'HOME': self.home,
382-
'XDG_CONFIG_HOME': d,
380+
XDG_CONFIG_HOME_ENV_VAR: d,
383381
}
384382
)
385383
assert not os.path.exists(os.path.join(d, 'b2'))
@@ -391,7 +389,7 @@ def test_account_info_env_var_overrides_xdg_config_home(self):
391389
account_info = self._make_sqlite_account_info(
392390
env={
393391
'HOME': self.home,
394-
'XDG_CONFIG_HOME': d,
392+
XDG_CONFIG_HOME_ENV_VAR: d,
395393
B2_ACCOUNT_INFO_ENV_VAR: os.path.join(d, 'b2_account_info'),
396394
}
397395
)

0 commit comments

Comments
 (0)