-
Notifications
You must be signed in to change notification settings - Fork 21
add docs for check_and_build_global_config()
#270
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| **Added:** | ||
|
|
||
| * no news added: simply adding documentation for config update workflow | ||
|
|
||
| **Changed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Deprecated:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Removed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Fixed:** | ||
|
|
||
| * <news item> | ||
|
|
||
| **Security:** | ||
|
|
||
| * <news item> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,29 +4,7 @@ | |
| from pathlib import Path | ||
|
|
||
|
|
||
| def clean_dict(obj): | ||
| """ | ||
| Remove keys from the dictionary where the corresponding value is None. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| obj: dict | ||
| The dictionary to clean. If None, initialize as an empty dictionary. | ||
|
|
||
| Returns | ||
| ------- | ||
| dict: | ||
| The cleaned dictionary with keys removed where the value is None. | ||
|
|
||
| """ | ||
| obj = obj if obj is not None else {} | ||
| for key, value in copy(obj).items(): | ||
| if not value: | ||
| del obj[key] | ||
| return obj | ||
|
|
||
|
|
||
| def stringify(obj): | ||
| def _stringify(obj): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make this function private and remove unncessary functions |
||
| """ | ||
| Convert None to an empty string. | ||
|
|
||
|
|
@@ -43,7 +21,7 @@ def stringify(obj): | |
| return obj if obj is not None else "" | ||
|
|
||
|
|
||
| def load_config(file_path): | ||
| def _load_config(file_path): | ||
| """ | ||
| Load configuration from a .json file. | ||
|
|
||
|
|
@@ -67,29 +45,6 @@ def load_config(file_path): | |
| return {} | ||
|
|
||
|
|
||
| def _sorted_merge(*dicts): | ||
| merged = {} | ||
| for d in dicts: | ||
| merged.update(d) | ||
| return merged | ||
|
|
||
|
|
||
| def _create_global_config(args): | ||
| username = input( | ||
| f"Please enter the name you would want future work to be credited to " f"[{args.get('username', '')}]: " | ||
| ).strip() or args.get("username", "") | ||
| email = input(f"Please enter the your email " f"[{args.get('email', '')}]: ").strip() or args.get("email", "") | ||
| return_bool = False if username is None or email is None else True | ||
| with open(Path().home() / "diffpyconfig.json", "w") as f: | ||
| f.write(json.dumps({"username": stringify(username), "email": stringify(email)})) | ||
| print( | ||
| f"You can manually edit the config file at {Path().home() / 'diffpyconfig.json'} using any text editor.\n" | ||
| f"Or you can update the config file by passing new values to get_user_info(), " | ||
| f"see examples here: https://www.diffpy.org/diffpy.utils/examples/toolsexample.html" | ||
| ) | ||
| return return_bool | ||
|
|
||
|
|
||
| def get_user_info(owner_name=None, owner_email=None, owner_orcid=None): | ||
| """ | ||
| Get name, email and orcid of the owner/user from various sources and return it as a metadata dictionary | ||
|
|
@@ -116,7 +71,7 @@ def get_user_info(owner_name=None, owner_email=None, owner_orcid=None): | |
| 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. | ||
| owner_orcid: string, optional, default is the value stored in the global or local config file. | ||
| The ORCID id of the user/owner | ||
|
|
||
| Returns | ||
|
|
@@ -130,8 +85,8 @@ def get_user_info(owner_name=None, owner_email=None, owner_orcid=None): | |
| for key, value in copy(runtime_info).items(): | ||
| if value is None or value == "": | ||
| del runtime_info[key] | ||
| global_config = load_config(Path().home() / "diffpyconfig.json") | ||
| local_config = load_config(Path().cwd() / "diffpyconfig.json") | ||
| global_config = _load_config(Path().home() / "diffpyconfig.json") | ||
| local_config = _load_config(Path().cwd() / "diffpyconfig.json") | ||
| # if global_config is None and local_config is None: | ||
| # print( | ||
| # "No global configuration file was found containing " | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.