Skip to content

Commit

Permalink
Address codefactor complaints (lanl#135)
Browse files Browse the repository at this point in the history
* Address some codefactor complaints

* Disable redefined built-in warning for ord

* Skip test if no internet connection

* Add note on change in jaxlib/jax versions

* Resolve lanl#133
  • Loading branch information
bwohlberg authored Dec 15, 2021
1 parent 593e9c2 commit 0fbc4b9
Show file tree
Hide file tree
Showing 43 changed files with 471 additions and 524 deletions.
2 changes: 1 addition & 1 deletion .github/isbin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ for f in $@; do
exit 1
fi
charset=$(file -b --mime $f | sed -e 's/.*charset=//')
if [ ! -L "$f" -a "$charset" = "binary" ]; then
if [ ! -L "$f" ] && [ "$charset" = "binary" ]; then
echo "binary files cannot be commited to the repository"
echo "raw data and ipynb files should go in scico-data"
exit 2
Expand Down
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Version 0.0.2 (unreleased)

• Additional optimization algorithms: Linearized ADMM and PDHG.
• Move optimization algorithms into ``optimize`` subpackage.
• Bump pinned `jaxlib` and `jax` versions to 0.1.70 and 0.2.19 respectively.


Version 0.0.1 (2021-11-24)
Expand Down
8 changes: 4 additions & 4 deletions docs/source/_static/scico.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ dl.citation {

dl.citation > dt {
background-color: #ffffff !important;
border-top: 0px !important;
margin: 0 0 0 0 !important;
border-top: 0 !important;
margin: 0 !important;
grid-column-start: 1;
width: 2em;
}

dl.citation > dd {
padding-bottom: 0px !important;
margin-bottom: 0px !important;
padding-bottom: 0 !important;
margin-bottom: 0 !important;
margin-left: 5px !important;
grid-column-start: 2;
}
Expand Down
3 changes: 1 addition & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ def patched_parse(self):


if on_rtd:
print("Building on ReadTheDocs")
print
print("Building on ReadTheDocs\n")
print("Current working directory: {}".format(os.path.abspath(os.curdir)))
import numpy as np

Expand Down
7 changes: 4 additions & 3 deletions docs/source/docutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def package_classes(package):
# Get internal module name of class for comparison with working module name
try:
objmodname = getattr(sys.modules[modname], obj.__name__).__module__
except:
except Exception:
objmodname = None
if objmodname == modname:
classes.append(modname + "." + obj.__name__)
Expand Down Expand Up @@ -80,8 +80,9 @@ def insert_inheritance_diagram(clsqname):
if not lines:
return
# Cut leading whitespace lines
for n in range(len(lines)):
if lines[n] != "":
n = 0
for n, line in enumerate(lines):
if line != "":
break
lines = lines[n:]
# Define inheritance diagram insertion text
Expand Down
5 changes: 2 additions & 3 deletions examples/makenotebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import argparse
import os
import re
import sys
from pathlib import Path
from timeit import default_timer as timer

Expand Down Expand Up @@ -88,8 +87,8 @@ def py_file_to_string(src):
def script_to_notebook(src, dst):
"""Convert a Python example script into a Jupyter notebook."""

str = py_file_to_string(src)
nb = py_string_to_notebook(str)
s = py_file_to_string(src)
nb = py_string_to_notebook(s)
write_notebook(nb, dst)


Expand Down
11 changes: 6 additions & 5 deletions examples/scriptcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Currently only supported under Linux.

# Check for presence of Xvfb tool which is used to avoid plots being displayed.
if [ ! "`which Xvfb 2>/dev/null`" ]; then
if [ ! "$(which Xvfb 2>/dev/null)" ]; then
msg="Warning: required tool Xvfb not found: functionality will be degraded"
echo $msg >&2
pid=0
Expand All @@ -17,7 +17,7 @@ fi

# Set environment variables and paths. This script is assumed to be run
# from its root directory.
export PYTHONPATH=`(cd .. && pwd)`
export PYTHONPATH=$((cd .. && pwd))
export PYTHONIOENCODING=utf-8
d='/tmp/scriptcheck_'$$
mkdir -p $d
Expand All @@ -41,14 +41,15 @@ for f in scripts/*.py; do

# Create temporary copy of script with all algorithm maxiter values set
# to small number and final input statements commented out.
g=$d/`basename $f`
g=$d/$(basename $f)
sed -E -e "$re1$re2$re3" $f > $g

# Run temporary script.
python $g > /dev/null 2>&1

# Print status message.
if [ $? = 0 ]; then
# Run temporary script and print status message.
if python $g > /dev/null 2>&1
then
printf "%-50s %s\n" $f succeeded
else
printf "%-50s %s\n" $f FAILED
Expand Down
14 changes: 7 additions & 7 deletions misc/conda/install_conda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ URLROOT=https://repo.continuum.io/miniconda/
INSTLINUX=Miniconda3-latest-Linux-x86_64.sh
INSTMACOSX=Miniconda3-latest-MacOSX-x86_64.sh

SCRIPT=`basename $0`
SCRIPT=$(basename $0)
USAGE=$(cat <<-EOF
Usage: $SCRIPT [-h] [-y] install_path
[-h] Display usage information
Expand Down Expand Up @@ -36,32 +36,32 @@ if [ ! $# -eq 1 ] ; then
exit 1
fi

OS=`uname -a | cut -d ' ' -f 1`
OS=$(uname -a | cut -d ' ' -f 1)
case "$OS" in
Linux) SOURCEURL=$URLROOT$INSTLINUX;;
Darwin) SOURCEURL=$URLROOT$INSTMACOSX;;
*) echo "Error: unsupported operating system $OS" >&2; exit 2;;
esac

if [ ! "`which wget 2>/dev/null`" ]; then
if [ ! "$(which wget 2>/dev/null)" ]; then
has_wget=0
else
has_wget=1
fi

if [ ! "`which curl 2>/dev/null`" ]; then
if [ ! "$(which curl 2>/dev/null)" ]; then
has_curl=0
else
has_curl=1
fi

if [ $has_curl -eq 0 -a $has_wget -eq 0 ]; then
if [ $has_curl -eq 0 ] && [ $has_wget -eq 0 ]; then
echo "Error: neither curl nor wget found; at least one required" >&2
exit 3
fi

INSTALLROOT=$1
if [ ! -d "$INSTALLROOT" -o ! -w "$INSTALLROOT" ]; then
if [ ! -d "$INSTALLROOT" ] || [ ! -w "$INSTALLROOT" ]; then
echo "Error: installation root path \"$INSTALLROOT\" is not a directory "\
"or is not writable" >&2
exit 4
Expand All @@ -77,7 +77,7 @@ fi
if [ "$AGREE" == "no" ]; then
read -r -p "Confirm conda installation in root path $INSTALLROOT [y/N] "\
CNFRM
if [ "$CNFRM" != 'y' -a "$CNFRM" != 'Y' ]; then
if [ "$CNFRM" != 'y' ] && [ "$CNFRM" != 'Y' ]; then
echo "Cancelling installation"
exit 6
fi
Expand Down
76 changes: 37 additions & 39 deletions misc/conda/make_conda_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Run with -h flag for usage information
set -e # exit when any command fails

SCRIPT=`basename $0`
SCRIPT=$(basename $0)
USAGE=$(cat <<-EOF
Usage: $SCRIPT [-h] [-y] [-g] [-p python_version] [-c cuda_version]
[-e env_name] [-j jaxlib_url]
Expand All @@ -34,7 +34,7 @@ GPU=no
CUVER=""
JLVER="0.1.71"
PYVER="3.8"
ENVNM=py`echo $PYVER | sed -e 's/\.//g'`
ENVNM=py$(echo $PYVER | sed -e 's/\.//g')

# Project requirements files
REQUIRE=$(cat <<-EOF
Expand All @@ -54,31 +54,29 @@ EOF

OPTIND=1
while getopts ":hygc:p:e:j:" opt; do
case $opt in
c|p|e|j) if [ -z "$OPTARG" -o "${OPTARG:0:1}" = "-" ] ; then
echo "Error: option -$opt requires an argument" >&2
case $opt in
c|p|e|j) if [ -z "$OPTARG" ] || [ "${OPTARG:0:1}" = "-" ] ; then
echo "Error: option -$opt requires an argument" >&2
echo "$USAGE" >&2
exit 1
fi
;;&
h) echo "$USAGE"; exit 0;;
y) AGREE=yes;;
g) GPU=yes;;
c) CUVER=$OPTARG;;
p) PYVER=$OPTARG;;
e) ENVNM=$OPTARG;;
j) JAXURL=$OPTARG;;
:) echo "Error: option -$OPTARG requires an argument" >&2
echo "$USAGE" >&2
exit 1
fi
exit 1
;;
\?) echo "Error: invalid option -$OPTARG" >&2
echo "$USAGE" >&2
exit 1
;;
esac
case $opt in
h) echo "$USAGE"; exit 0;;
y) AGREE=yes;;
g) GPU=yes;;
c) CUVER=$OPTARG;;
p) PYVER=$OPTARG;;
e) ENVNM=$OPTARG;;
j) JAXURL=$OPTARG;;
:) echo "Error: option -$OPTARG requires an argument" >&2
echo "$USAGE" >&2
exit 1
;;
\?) echo "Error: invalid option -$OPTARG" >&2
echo "$USAGE" >&2
exit 1
;;
esac

done

shift $((OPTIND-1))
Expand All @@ -88,46 +86,46 @@ if [ ! $# -eq 0 ] ; then
exit 1
fi

if [ ! "`which conda 2>/dev/null`" ]; then
if [ ! "$(which conda 2>/dev/null)" ]; then
echo "Error: conda command required but not found" >&2
exit 2
fi

# Not available on BSD systems such as OSX: install via MacPorts etc.
if [ ! "`which realpath 2>/dev/null`" ]; then
if [ ! "$(which realpath 2>/dev/null)" ]; then
echo "Error: realpath command required but not found" >&2
exit 3
fi

OS=`uname -a | cut -d ' ' -f 1`
OS=$(uname -a | cut -d ' ' -f 1)
case "$OS" in
Linux) SOURCEURL=$URLROOT$INSTLINUX; SED=sed;;
Darwin) SOURCEURL=$URLROOT$INSTMACOSX; SED=gsed;;
Linux) SOURCEURL=$URLROOT$INSTLINUX; SED="sed";;
Darwin) SOURCEURL=$URLROOT$INSTMACOSX; SED="gsed";;
*) echo "Error: unsupported operating system $OS" >&2; exit 4;;
esac
if [ "$OS" == "Darwin" -a "$GPU" == yes ]; then
if [ "$OS" == "Darwin" ] && [ "$GPU" == yes ]; then
echo "Error: GPU-enabled jaxlib installation not supported under OSX" >&2
exit 5
fi
if [ "$OS" == "Darwin" ]; then
if [ ! "`which gsed 2>/dev/null`" ]; then
if [ ! "$(which gsed 2>/dev/null)" ]; then
echo "Error: gsed command required but not found" >&2
exit 6
fi
fi

if [ "$GPU" == "yes" -a "$CUVER" == "" ]; then
if [ "`which nvcc`" == "" ]; then
if [ "$GPU" == "yes" ] && [ "$CUVER" == "" ]; then
if [ "$(which nvcc)" == "" ]; then
echo "Error: GPU-enabled jaxlib requested but CUDA version not"\
"specified and could not be automatically determined" >&2
exit 7
else
CUVER=`nvcc --version | grep -o 'release [0-9][0-9]*\.[[0-9][0-9]*' \
| sed -e 's/release //' -e 's/\.//'`
CUVER=$(nvcc --version | grep -o 'release [0-9][0-9]*\.[[0-9][0-9]*' \
| sed -e 's/release //' -e 's/\.//')
fi
fi

CONDAHOME=`conda info --base`
CONDAHOME=$(conda info --base)
ENVDIR=$CONDAHOME/envs/$ENVNM
if [ -d "$ENVDIR" ]; then
echo "Error: environment $ENVNM already exists"
Expand All @@ -138,7 +136,7 @@ if [ "$AGREE" == "no" ]; then
RSTR="Confirm creation of conda environment $ENVNM with Python $PYVER"
RSTR="$RSTR [y/N] "
read -r -p "$RSTR" CNFRM
if [ "$CNFRM" != 'y' -a "$CNFRM" != 'Y' ]; then
if [ "$CNFRM" != 'y' ] && [ "$CNFRM" != 'Y' ]; then
echo "Cancelling environment creation"
exit 9
fi
Expand Down Expand Up @@ -201,7 +199,7 @@ conda install $CONDA_FLAGS $CONDAREQ ipython
# Utility ffmpeg is required by imageio for reading mp4 video files
# it can also be installed via the system package manager, .e.g.
# sudo apt install ffmpeg
if [ "`which ffmpeg`" = '' ]; then
if [ "$(which ffmpeg)" = '' ]; then
conda install $CONDA_FLAGS ffmpeg
fi

Expand Down
Loading

0 comments on commit 0fbc4b9

Please sign in to comment.