Skip to content

Commit

Permalink
Merge pull request #2 from martinkilbinger/log
Browse files Browse the repository at this point in the history
tests checking
  • Loading branch information
martinkilbinger authored Oct 7, 2022
2 parents f69568e + c3fdbad commit c07b104
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 121 deletions.
111 changes: 0 additions & 111 deletions configure.sh

This file was deleted.

62 changes: 62 additions & 0 deletions cs_util/logging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""LOGGING.
:Description: This script contains utility methods for job execution and progress logging.
:Author: Martin Kilbinger <[email protected]>
"""


import sys


def log_command(argv, name=None, close_no_return=True):
"""Log Command.
Write command with arguments to a file or stdout.
Choose name = 'sys.stdout' or 'sys.stderr' for output on sceen.
MKDEBUG copied from shapepipe:cfis
Parameters
----------
argv : list
Command line arguments
name : str
Output file name (default: 'log_<command>')
close_no_return : bool
If True (default), close log file. If False, keep log file open
and return file handler
Returns
-------
filehandler
log file handler (if close_no_return is False)
"""
if name is None:
name = 'log_' + os.path.basename(argv[0])

if name == 'sys.stdout':
f = sys.stdout
elif name == 'sys.stderr':
f = sys.stderr
else:
f = open(name, 'w')

for a in argv:

# Quote argument if special characters
if '[' in a or ']' in a:
a = f'\"{a}\"'

print(a, end='', file=f)
print(' ', end='', file=f)

print('', file=f)

if not close_no_return:
return f

if name != 'sys.stdout' and name != 'sys.stderr':
f.close()
10 changes: 5 additions & 5 deletions develop.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
coverage
nose
isort
jinja2==3.0
numpydoc
pytest
pytest-cov
pytest-pep8
pytest-emoji
pytest-flake8
wemake-python-styleguide
pytest-pycodestyle
pytest-pydocstyle
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
astropy
datetime
importlib_metadata
numpy
astropy
matplotlib
pycodestyle==2.9.0
vos
datetime
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ testpaths =
scripts
addopts =
--verbose
--emoji
--flake8
--cov=cs_util
--cov-report=term
--cov-report=xml
--junitxml=pytest.xml
#--emoji
#--flake8
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Set the package release version
major = 0
minor = 0
patch = 0
patch = 1

# Set the package details
name = 'cs_util'
Expand Down

0 comments on commit c07b104

Please sign in to comment.