Skip to content

Commit

Permalink
Improve usage outside IPython
Browse files Browse the repository at this point in the history
Build upon rasbt#46 to allow injecting globals when used outside IPython.
  • Loading branch information
Hugovdberg committed Dec 8, 2021
1 parent d3553b6 commit fb2e5c8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions watermark/watermark.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def watermark(author=None, current_date=False, datename=False,
updated=False, custom_time=None, python=False,
packages=None, hostname=False, machine=False,
githash=False, gitrepo=False, gitbranch=False,
watermark=False, iversions=False, watermark_self=None):
watermark=False, iversions=False, watermark_self=None,
globals_=None):

'''Function to print date/time stamps and various system information.
Expand Down Expand Up @@ -148,8 +149,16 @@ def watermark(author=None, current_date=False, datename=False,
if args['gitbranch']:
output.append(_get_git_branch(bool(args['machine'])))
if args['iversions']:
output.append(_get_all_import_versions(
watermark_self.shell.user_ns))
if watermark_self:
ns = watermark_self.shell.user_ns
elif globals_:
ns = globals_
else:
raise RuntimeError(
"Either `watermark_self` or `globals_` must be provided to show "
"imported package versions."
)
output.append(_get_all_import_versions(ns))
if args['watermark']:
output.append({"Watermark": __version__})

Expand Down

0 comments on commit fb2e5c8

Please sign in to comment.