diff --git a/configure.sh b/configure.sh deleted file mode 100755 index 12c40ab..0000000 --- a/configure.sh +++ /dev/null @@ -1,111 +0,0 @@ -#!/bin/bash - -# Divider line -line="########################################################################" -version="0.0.3" - -echo -echo $line -echo "Pyralid Template Set Up Script" -echo -echo "Author: Samuel Farrens" -echo "Year: 2020" -echo "Version:" $version -echo -echo "See https://github.com/sfarrens/pyralid-template for help." -echo -echo $line -echo -echo "Please provide the following information:" - -read -p "> Your name: " _author_ -read -p "> Your email address: " _email_ -read -p "> Your GitHub user name: " _ghuser_ -read -p "> The current year [2020]: " _year_ -read -p "> Your package name: " _package_name_ -read -p "> A short description of your package: " _describe_ -read -p "> A list of packages your code requires (e.g. numpy,scipy,matplotlib): " _requires_ - - -_year_=${_year_:-"2020"} - -echo - -echo "The following files and directories will be updated with the package name '$_package_name_':" - -echo ./package_name -grep -rl "configure_package_name" . --exclude=.git --exclude=configure.sh - -echo - -echo "and the package will be updated with the following details:" -echo " - Your name: $_author_" -echo " - Your email address: $_email_" -echo " - Your GitHub user name: $_ghuser_" -echo " - The current year: $_year_" -echo " - A short description of your package: $_describe_" -echo " - A list of packages your code requires: $_requires_" - -echo - -echo "Are you sure you want to make these changes?" - -read -p "> [y/N]: " _response_ - -echo - -_response_=${_response_:-"n"} - -if [ "$_response_" != "Y" ] && [ "$_response_" != "y" ]; then - echo "Looks like you are not happy with that. Better start over!" - exit 1 -fi - -update_template() { - if [[ "$OSTYPE" == "darwin"* ]]; then - grep -rl $1 . --exclude=.git --exclude=configure.sh| xargs sed -i '' -e "s,$1,$2,g" - else - grep -rl $1 . --exclude=.git --exclude=configure.sh| xargs sed -i -e "s,$1,$2,g" - fi -} - -update_requirements() { - for package in $(echo $_requires_ | sed "s/,/ /g") - do - echo $package >> requirements.txt - done -} - -export LC_ALL=C -mv ./package_name ./$_package_name_ -update_template "configure_package_name" "$_package_name_" -update_template "configure_author" "$_author_" -update_template "configure_email" "$_email_" -update_template "configure_ghuser" "$_ghuser_" -update_template "configure_year" "$_year_" -update_template "configure_description" "$_describe_" -update_requirements - -finish() { - echo "All done!" - exit 1 -} - -echo "Do you want the script to push these changes to GitHub for you?" -read -p "> [y/N]: " _response2_ - -echo - -_response2_=${_response2_:-"n"} - -if [ "$_response2_" != "Y" ] && [ "$_response2_" != "y" ]; then - finish -fi - -echo "Commiting changes to template." - -git add . -git commit -m "updated template" -git push - -finish diff --git a/cs_util/logging.py b/cs_util/logging.py new file mode 100644 index 0000000..189cf62 --- /dev/null +++ b/cs_util/logging.py @@ -0,0 +1,62 @@ +"""LOGGING. + +:Description: This script contains utility methods for job execution and progress logging. + +:Author: Martin Kilbinger + +""" + + +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_') + 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() diff --git a/develop.txt b/develop.txt index 592123c..03f912d 100644 --- a/develop.txt +++ b/develop.txt @@ -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 diff --git a/requirements.txt b/requirements.txt index 90a862b..1fba4de 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ +astropy +datetime importlib_metadata numpy -astropy matplotlib pycodestyle==2.9.0 vos -datetime diff --git a/setup.cfg b/setup.cfg index 3c5c0bf..2c51224 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,9 +22,9 @@ testpaths = scripts addopts = --verbose - --emoji - --flake8 --cov=cs_util --cov-report=term --cov-report=xml --junitxml=pytest.xml +#--emoji +#--flake8 diff --git a/setup.py b/setup.py index c3635e6..9cc0b4f 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ # Set the package release version major = 0 minor = 0 -patch = 0 +patch = 1 # Set the package details name = 'cs_util'