Skip to content
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

Use logging #129

Merged
merged 6 commits into from
May 7, 2019
Merged

Use logging #129

merged 6 commits into from
May 7, 2019

Conversation

counkomol
Copy link
Contributor

This PR converts the package print statements into logging module calls. Addresses #121.

Also, fixes bug #125.

@@ -39,12 +44,11 @@ def save_default_train_options(path_save: str) -> None:
Save path for default training options json.

"""
if os.path.exists(path_save):
print('Training options file already exists:', path_save)
path_save = Path(path_save)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to make this Path(path_save).expanduser().resolve(). It will make it so people can put relative paths and also include their home directory like ~/Desktop/trained_fnet_model/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! I'll look to add this type of functionality when I address #128.

'seed': None,
}
with open(path_save, 'w') as fo:
with path_save.open('w') as fo:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pathlib.Path works with the default open function, but TIL Path objects have an open function too.

Copy link
Member

@heeler heeler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice upgrade from print to logger!

print('Training options file already exists:', path_save)
path_save = Path(path_save)
if path_save.exists():
logger.info(f'Training options file already exists: {path_save}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably throw a custom exception here personally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An exception would imply that something went "wrong" though. The idea is to simply exit if the intended action had already been completed in the past. That way the user does not have to manually check the file system.

@@ -213,7 +217,7 @@ def save_args_as_json(path_save_dir: str, args: argparse.Namespace) -> None:
)
with open(path_json, 'w') as fo:
json.dump(vars(args), fo, indent=4, sort_keys=True)
print('Saved:', path_json)
logger.info('Saved: {path_json}')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the logger statement indented into the open statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally, the intent was to only log a message if a json was actually written. Now that I think about it though, if a json was not written because of, say, and IO error, then there would be some exception and the program would crash out anyway. Anyway, I'll fix this. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added another commit to pull the logging statement outside of the context block.

@counkomol counkomol merged commit 54ebe56 into master May 7, 2019
@counkomol counkomol deleted the use_logging branch May 7, 2019 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants