Skip to content

Commit 00a916c

Browse files
author
Joschka zur Jacobsmühlen
committed
Add option to display active conda environment
1 parent d3553b6 commit 00a916c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

watermark/magic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class WaterMark(Magics):
4848
help='prints Python and IPython version')
4949
@argument('-p', '--packages', type=str,
5050
help='prints versions of specified Python modules and packages')
51+
@argument('-e', '--conda', action='store_true',
52+
help='prints name of current conda environment')
5153
@argument('-h', '--hostname', action='store_true',
5254
help='prints the host name')
5355
@argument('-m', '--machine', action='store_true',

watermark/watermark.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import datetime
1313
import importlib
14+
import os
1415
import platform
1516
import subprocess
1617
import time
@@ -32,7 +33,7 @@
3233
def watermark(author=None, current_date=False, datename=False,
3334
current_time=False, iso8601=False, timezone=False,
3435
updated=False, custom_time=None, python=False,
35-
packages=None, hostname=False, machine=False,
36+
packages=None, conda=False, hostname=False, machine=False,
3637
githash=False, gitrepo=False, gitbranch=False,
3738
watermark=False, iversions=False, watermark_self=None):
3839

@@ -72,6 +73,9 @@ def watermark(author=None, current_date=False, datename=False,
7273
packages :
7374
prints versions of specified Python modules and packages
7475
76+
conda :
77+
prints name of current conda environment
78+
7579
hostname :
7680
prints the host name
7781
@@ -137,6 +141,8 @@ def watermark(author=None, current_date=False, datename=False,
137141
output.append(_get_pyversions())
138142
if args['packages']:
139143
output.append(_get_packages(args['packages']))
144+
if args['conda']:
145+
output.append(_get_conda_env())
140146
if args['machine']:
141147
output.append(_get_sysinfo())
142148
if args['hostname']:
@@ -269,3 +275,7 @@ def _get_all_import_versions(vars):
269275
if pkg_version not in ("not installed", "unknown"):
270276
to_print[pkg_name] = pkg_version
271277
return to_print
278+
279+
def _get_conda_env():
280+
name = os.getenv('CONDA_DEFAULT_ENV', 'n/a')
281+
return {"conda environment": name}

0 commit comments

Comments
 (0)