-
Notifications
You must be signed in to change notification settings - Fork 21
refactor to separate getting info and creating config files #264
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #264 +/- ##
===========================================
- Coverage 100.00% 98.68% -1.32%
===========================================
Files 8 8
Lines 391 381 -10
===========================================
- Hits 391 376 -15
- Misses 0 5 +5
|
@@ -40,16 +41,17 @@ The function will return | |||
|
|||
.. code-block:: python | |||
|
|||
{"email": "janedoe@email.com", "username": "Jane Doe"} | |||
{"owner_email": "janedoe@email.com", "owner_name": "Jane Doe", "owner_orcid": "0000-0000-0000-0000"} |
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 like the term "owner" - and orcid since that's a gateway for more info
It looks first for the file in the current working directory. If it cannot find it there it will look | ||
user's home, i.e., login, directory. To find this directory, open a terminal and a unix or mac system type :: | ||
It looks for files in the current working directory and in the computer-user's home (i.e., login) directory. | ||
For example, it might be in C:/Users/yourname`` or something like that, but to find this directory, open |
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.
much clearer since there is an example provided since i wasn't sure what "login" meant here.
Getting user data with no config files and with no interruption of execution | ||
---------------------------------------------------------------------------- | ||
If no configuration files can be found, they can be created using a text editor, or by using a diffpy tool | ||
called ``check_and_build_global_config()`` which, if no global config file can be found, prompts the user for the |
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.
clear - when no config is found, this function is called.
``check_and_build_global_config()`` takes an optional boolean ``skip_config_creation`` parameter that | ||
could be set to ``True`` at runtime to override the config creation. | ||
|
||
I entered the wrong information in my config file so it always loads incorrect information, how do I fix that? |
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.
Clear on how to reset config
@@ -91,47 +90,62 @@ def _create_global_config(args): | |||
return return_bool | |||
|
|||
|
|||
def get_user_info(args=None): | |||
def get_user_info(owner_name=None, owner_email=None, owner_orcid=None): |
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.
much better - instead of args
, this line explicitly communicates what info can be optionally provided
|
||
Parameters | ||
---------- | ||
args argparse.Namespace | ||
The arguments from the parser, default is None. | ||
owner_name: string, optional, default is the value stored in the global or local config file. |
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.
Ah.. this gives me joy
local_config_data = {"username": "cwd_username", "email": "cwd@email.com"} | ||
with open(Path(user_filesystem) / "diffpyconfig.json", "w") as f: | ||
@pytest.mark.parametrize( | ||
"runtime_inputs, expected", |
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 like it - runtime is much clearer than cli
@pytest.mark.parametrize("inputs, expected", params_user_info_with_home_conf_file) | ||
def test_get_user_info_with_home_conf_file(monkeypatch, inputs, expected, user_filesystem): | ||
_setup_dirs(monkeypatch, user_filesystem) | ||
_run_tests(inputs, expected) |
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.
yes, this mysterious _run_tests
func is replaced.
], | ||
) | ||
def test_get_user_info_with_home_conf_file(runtime_inputs, expected, user_filesystem, mocker): | ||
# user_filesystem[0] is tmp_dir/home_dir with the global config file in it, user_filesystem[1] |
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 was wondering user_filesystem
and the comment clarifies it
@sbillinge I did my review via in-line comments. One general question, should we follow pep8 convention for comments? 1) capitalize the first word
|
@yucongalicechen @bobleesj I need the updated |
@@ -65,7 +64,7 @@ def load_config(file_path): | |||
config = json.load(f) | |||
return config | |||
else: | |||
return None | |||
return {} | |||
|
|||
|
|||
def _sorted_merge(*dicts): |
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 wonder do we want to make some of the functions private (like load_config
)?
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.
yes, this should probably be private, I agree.
Can we also check? I don't think we need _sorted_dict()
any more so that could be deleted on a new PR.
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.
Yes, I can fix these on a new PR, once that updater workflow PR is merged
The name of the user who will show as owner in the metadata that is stored with the data | ||
owner_email: string, optional, default is the value stored in the global or local config file. | ||
The email of the user/owner | ||
owner_name: string, optional, default is the value stored in the global or local config file. |
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.
typo - owner_orcid
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.
thanks, good catch.
|
||
It is easy to fix this simply by deleting the global and/or local config files, which will allow | ||
you to re-enter the information during the ``check_and_build_global_config()`` initialization | ||
workflow. You can also simply editi the ``diffpyconfig.json`` file directly using a text |
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.
typo - edit
I finished my review @sbillinge here. Like this new structure and just caught two typos. |
Thanks for the excellent review @yucongalicechen . Please could you make a PR to fix those things? Let's also double check there are no private functions that are not use, or public functions that we want to make private. If @bobleesj finds anything else we can put that into the same PR. I also wanted to add into the docs what happens in the update config workflow when it is triggered, so reproduce what the user would see and give an example of how they would respond. It would be great for me if that could be in the same PR? |
Sounds good, I'll do that |
closes #245
replaces #253
@yucongalicechen @bobleesj ready for review. I will put the config-file creation workflow on another PR
Commented text will be reused (and removed from here) in a separate function for creating a missing global config file in a future PR.