Skip to content

Commit

Permalink
Remove psutil and bottombar dependencies (#895)
Browse files Browse the repository at this point in the history
  • Loading branch information
gertjanvanzwieten committed Jan 29, 2025
2 parents ef3977d + f122094 commit b92a3d8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
2 changes: 1 addition & 1 deletion nutils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'Numerical Utilities for Finite Element Analysis'

__version__ = version = '9a43'
__version__ = version = '9a44'
version_name = 'jook-sing'
13 changes: 10 additions & 3 deletions nutils/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def timeit():
treelog.info(f'finish {te:%Y-%m-%d %H:%M:%S}, elapsed {format_timedelta(te-t0)}')


class timer:
class elapsed:
'''Timer that returns elapsed seconds as string representation.'''

def __init__(self):
Expand Down Expand Up @@ -592,7 +592,7 @@ def name_of_main():
def add_htmllog(outrootdir: str = '~/public_html', outrooturi: str = '', scriptname: str = '', outdir: str = '', outuri: str = ''):
'''Context to add a HtmlLog to the active logger.'''

import html, base64, bottombar
import html, base64

if not scriptname and (not outdir or outrooturi and not outuri):
scriptname = name_of_main()
Expand All @@ -619,7 +619,14 @@ def add_htmllog(outrootdir: str = '~/public_html', outrooturi: str = '', scriptn
with treelog.HtmlLog(outdir, title=scriptname, htmltitle=htmltitle, favicon=favicon) as htmllog:
loguri = outuri + '/' + htmllog.filename
try:
with treelog.add(htmllog), bottombar.add(loguri, label='writing log to'):
import bottombar
except ImportError:
treelog.info(f'writing log to: {loguri}')
status = contextlib.nullcontext()
else:
status = bottombar.add(loguri, label='writing log to')
try:
with treelog.add(htmllog), status:
yield
except Exception as e:
with treelog.set(htmllog):
Expand Down
34 changes: 21 additions & 13 deletions nutils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,33 @@
def run(f, *, argv=None):
'''Command line interface for a single function.'''

import treelog, bottombar
import treelog
from . import _util as util, matrix, parallel, cache, warnings

decorators = (
util.trap_sigint(),
bottombar.add(util.timer(), label='runtime', right=True, refresh=1), \
bottombar.add(util.memory(), label='memory', right=True, refresh=1), \
util.in_context(cache.caching),
util.in_context(parallel.maxprocs),
util.in_context(matrix.backend),
util.in_context(util.set_stdoutlog),
util.in_context(util.add_htmllog),
util.in_context(util.log_traceback),
util.in_context(util.post_mortem),
decorators = [util.trap_sigint()]
for func in util.elapsed, util.memory:
try:
import bottombar
status = func()
except:
pass
else:
decorators.append(bottombar.add(status, label=func.__name__, right=True, refresh=1))
decorators.extend(util.in_context(c) for c in [
cache.caching,
parallel.maxprocs,
matrix.backend,
util.set_stdoutlog,
util.add_htmllog,
util.log_traceback,
util.post_mortem,
])
decorators.extend([
warnings.via(treelog.warning),
util.log_version,
util.log_arguments,
util.timeit(),
)
])

for decorator in reversed(decorators):
f = decorator(f)
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ authors = [
requires-python = '>=3.8'
dependencies = [
"appdirs >=1,<2",
"bottombar >=2,<3",
"numpy >=1.17,<3",
"nutils-poly >=1,<2",
"psutil >=5,<6",
"stringly",
"treelog >=1,<2",
]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ def test_timeit(self):
self.assertEqual(cm.output[1], 'ERROR:nutils:test')
self.assertEqual(cm.output[2][:18], 'INFO:nutils:finish')

def test_timer(self):
self.assertEqual(str(util.timer()), '0:00')
def test_elapsed(self):
self.assertEqual(str(util.elapsed()), '0:00')


class in_context(TestCase):
Expand Down

0 comments on commit b92a3d8

Please sign in to comment.