-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for XDG_CONFIG_HOME #129
Conversation
We used to be able to pass a file path to the constructor of SqliteAccountInfo, but you removed it. Please restore it. Also, could you briefly explain why are you proposing this change? |
We used to be able to pass a file path to the constructor of SqliteAccountInfo, but you removed it. Please restore it.
Passing in the file path still works: I just forgot to add it to the explanatory text and the docstring. I have since done the latter.
Also, could you briefly explain why are you proposing this change
I'm proposing the change so I can remove another dotfile from `$HOME` and add b2sdk/b2 cli to the list of applications that support the XDG spec. If I'm not mistaken, version 1.1.0 should go out soonish, and will be used in the next version of the b2 cli.
|
I think it is a good change. Could you please add a unit test to make sure that we don't hit a regression on this new functionality in the future? |
I added unit tests for two cases:
I'm not sure how to test the third interaction, where A hermetic testing environment and compatibility with existing code is ensured by modifying |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nice job overall, wonderful extension, I support the motion to not pollute ~/
with config files. I've asked for a few minor tweaks after closer review.
@0az will you do those changes so that we can fit this PR in the release? |
Co-authored-by: Paweł Polewicz <p.polewicz@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good work, a couple of minor issues remian
I'm really sorry about that.
I probably should have mentioned this earlier, but for some unknown reason that I don't have time to debug after midnight, the pre-commit shell script fails with a RuntimeError: "An attempt has been made to start a new process before the current process has finished its bootstrapping phase." Logs are in this gist: https://gist.github.com/0az/234a94a123e15259f3779661feed69e6. Manually running nosetests still works as a workaround, though.
I also modified the test class to include a temporary directory acting as HOME.
|
@mlech-reef did we accidentally enable parallel testing in nosetests on Windows? I don't think that ever worked, now appveyor can't run the tests and our contributor here also has issues. Travis is absent from this PR for some reason... Do you have any clue? |
Travis is triggered properly, but for some reason, it's not showing here. I've seen this issue in other PRs. We should investigate it. |
I don't recall anything like that. AppVeyor fails not because of the parallel runs but because 2 new tests are failing with: |
@@ -36,17 +36,39 @@ class SqliteAccountInfo(UrlPoolAccountInfo): | |||
|
|||
def __init__(self, file_name=None, last_upgrade_to_run=None): | |||
""" | |||
If ``file_name`` argument is empty or ``None``, path from ``B2_ACCOUNT_INFO`` environment variable is used. If that is not available, a default of ``~/.b2_account_info`` is used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am reading this docstring over and over and I think apiver doesn't let us change the default location to use XDG_CONFIG_HOME
in v1. Someone may have written a program that relies on the promise that when the filename was not passed and B2_ACCOUNT_INFO
was not set, then the db file will land in ~/.b2_account_info
. After running something, the program might clean the environment by removing that file.
If we make this change and XDG_CONFIG_HOME
is defined, sdk user would not expect the configuration of the end user to be suddenly leaked (as it is not cleaned up anymore), possibly allowing access to the following user.
I think this is a good change and we should introduce it, but that should happen with the release of from b2sdk.v2 import *
, otherwise we risk introducing a breaking change, while the purpose of apiver is to avoid it unless fixing a bug (which we are not doing here) which would change behavior because the old behavior was just wrong.
Furthermore, we should separate the documentation of the interface from the documentation of the current behavior, so that this can be altered in the future, by mentioning that the user should not define of this algorithm staying exactly the same, but should use self.filename
to determine the actually determined location of the file in case it needs to be accessed later.
We did not have a compelling reason to release v2, but this is a good one.
@bwbeach @0az do you agree with my viewpoint? Shall we move it to v2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch: I didn't actually think of that case.
Sounds good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0az then would you please adjust the docstring here? We'll hold off merging this until b2sdk 1.1.0 and b2cli 2.0.0 are shipped, then we'll increment apiver to v2 and finally we'll merge your thing (though a final adjustment will be necessary to provide backwards compatibility)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another question for v2: should SqliteAccountInfo support :memory:
or anonymous (empty string) databases?
https://www.sqlite.org/c3ref/open.html
If the filename is ":memory:", then a private, temporary in-memory database is created for the connection. This in-memory database will vanish when the database connection is closed. Future versions of SQLite might make use of additional special filenames that begin with the ":" character. It is recommended that when a database filename actually does begin with a ":" character you should prefix the filename with a pathname such as "./" to avoid ambiguity.
If the filename is an empty string, then a private, temporary on-disk database will be created. This private database will be automatically deleted as soon as the database connection is closed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like that could replace InMemoryAccountInfo
with one line of code. I like less code.
Co-authored-by: Andrew Zhou <0az@afzhou.com>
Thanks! Was there anything else that I needed to do? It's been a while. 🙃 |
v2.B2_ACCOUNT_INFO_ENV_VAR, v2.B2_ACCOUNT_INFO_DEFAULT_FILE | ||
) | ||
self.filename = file_name or os.path.expanduser(user_account_info_path) | ||
logger.debug('%s file path to use: %s', self.__class__.__name__, self.filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is logger
initialized?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's imported from here:
logger = logging.getLogger(__name__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, but here in b2sdk/v1/account_info.py
there is no logger
, so it will crash. Logger initialization should be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, bad wording. The initialization happens there, and there's an import in this file for that logger.
It probably should get initialized here anyway, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from b2sdk.account_info.sqlite_account_info import logger
ohhh. I don't think we should do that, that is super confusing. We should initialize it locally, right?
This PR seems to contain v2 changes. Can we somehow make it clean? @0az would you mind if we took your changes and rebased them to slide it into v2 at the appropriate moment? The v2 change is a little bit chaotic and I don't want to keep pulling you into this. |
Michał sent in a PR with the v2 changes, so I merged that in. I can force push that off of the branch, if you want.
This is also fine. |
Yeah, 235 looks good. I'll close this PR, then. |
Implement support for
XDG_CONFIG_HOME
.To avoid breaking changes, we use locations in this order:
$B2_ACCOUNT_INFO_ENV_VAR
: If set~/.b2_account_info
: If exists$XDG_CONFIG_HOME/b2/account_info
: If set~/.b2_account_info
: If no path takes priority