diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-05-01 17:53:27 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-05-01 17:53:27 -0400 |
commit | bfd2b7585e64f4766e4eec315f94d187e2d4f976 (patch) | |
tree | 67e94be7cad9f3a147d96f2e8066ed6864135f32 /coverage/misc.py | |
parent | 3d43c74cd2dd8c66c29572bc04a4b0de3e206364 (diff) | |
download | python-coveragepy-git-bfd2b7585e64f4766e4eec315f94d187e2d4f976.tar.gz |
refactor: move the remaining backward.py code, no more backward.py
Diffstat (limited to 'coverage/misc.py')
-rw-r--r-- | coverage/misc.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/coverage/misc.py b/coverage/misc.py index 7182d385..6f104ac0 100644 --- a/coverage/misc.py +++ b/coverage/misc.py @@ -5,6 +5,7 @@ import errno import hashlib +import importlib.util import inspect import locale import os @@ -315,6 +316,30 @@ def substitute_variables(text, variables): return text +def format_local_datetime(dt): + """Return a string with local timezone representing the date. + """ + return dt.astimezone().strftime('%Y-%m-%d %H:%M %z') + + +def import_local_file(modname, modfile=None): + """Import a local file as a module. + + Opens a file in the current directory named `modname`.py, imports it + as `modname`, and returns the module object. `modfile` is the file to + import if it isn't in the current directory. + + """ + if modfile is None: + modfile = modname + '.py' + spec = importlib.util.spec_from_file_location(modname, modfile) + mod = importlib.util.module_from_spec(spec) + sys.modules[modname] = mod + spec.loader.exec_module(mod) + + return mod + + class BaseCoverageException(Exception): """The base of all Coverage exceptions.""" pass |