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

POC: exposing the watermark function outside Jupyter #46

Merged
merged 7 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
pep8 friendly
  • Loading branch information
Tymoteusz Wolodzko committed Jan 3, 2019
commit 2970b96dedb2460fbf4a8a8c20b5e61a244e3419
2 changes: 1 addition & 1 deletion watermark/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ def watermark(self, line):


def load_ipython_extension(ipython):
ipython.register_magics(WaterMark)
ipython.register_magics(WaterMark)
20 changes: 11 additions & 9 deletions watermark/watermark.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
import sys


def watermark(author=None, current_date=False, datename=False, current_time=False,
iso8601=False, timezone=False, updated=False, custom_time=None,
python=False, packages=None, hostname=False, machine=False,
githash=False, gitrepo=False, gitbranch=False, watermark=False,
iversions=False):
def watermark(author=None, current_date=False, datename=False,
current_time=False, iso8601=False, timezone=False,
updated=False, custom_time=None, python=False,
packages=None, hostname=False, machine=False,
githash=False, gitrepo=False, gitbranch=False,
watermark=False, iversions=False):

'''Function to print date/time stamps and various system information.

Expand Down Expand Up @@ -75,7 +76,7 @@ def watermark(author=None, current_date=False, datename=False, current_time=Fals
if not any(args.values()) or iso8601:
try:
dt = datetime.datetime.fromtimestamp(int(time()),
datetime.timezone.utc)
datetime.timezone.utc)
iso_dt = dt.astimezone().isoformat()
except AttributeError: # timezone only supported by Py >=3.2:
iso_dt = strftime('%Y-%m-%dT%H:%M:%S')
Expand Down Expand Up @@ -122,7 +123,8 @@ def watermark(author=None, current_date=False, datename=False, current_time=Fals
if gitbranch:
out += get_git_branch(bool(machine))
if iversions:
out += get_imported_packages() # change here
# change here
out += get_imported_packages()
if watermark:
out += '\nwatermark %s' % __version__
print(out.strip())
Expand Down Expand Up @@ -235,12 +237,12 @@ def get_imported_packages():
name = val.split('.')[0]
pkg = sys.modules[name]
if pkg.__name__ not in sys.builtin_module_names \
and not pkg.__name__.startswith('_') :
and not pkg.__name__.startswith('_'):
try:
packages.add((pkg.__name__, pkg.__version__))
except AttributeError:
continue
out = ''
for pkg in packages:
out += '\n%-15s%s' % pkg
return out
return out