Skip to content

Commit

Permalink
implement shellcheck for linting
Browse files Browse the repository at this point in the history
  • Loading branch information
rmartin16 committed Sep 20, 2024
1 parent 6fd2476 commit f5207e1
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 74 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ repos:
- id: check-docstring-first
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
hooks:
- id: shellcheck
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
Expand Down
14 changes: 7 additions & 7 deletions publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
# (base) $ ./publish.sh
#

for f in $(find dist -name "*.whl"); do
echo "***** PUBLISH $f ***********************************"
anaconda upload -u beeware $f
if [[ $? == 0 ]]; then
mv $f published
fi
done
while IFS= read -r -d '' FILE
do
echo "***** PUBLISH $FILE ***********************************"
if anaconda upload -u beeware "$FILE"; then
mv "$FILE" published
fi
done < <(find ./dist -name "*.whl" -print0)
8 changes: 4 additions & 4 deletions recipes/bzip2/build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
set -eu

mkdir -p $PREFIX
cp -r include $PREFIX
cp -r lib $PREFIX
mkdir -p "$PREFIX"
cp -r include "$PREFIX"
cp -r lib "$PREFIX"

# Strip out any dylib files to ensure static linking
find $PREFIX -name "*.dylib" -exec rm -rf {} \;
find "$PREFIX" -name '*.dylib' -exec rm -rf {} \;
16 changes: 8 additions & 8 deletions recipes/freetype/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
set -eu

./configure \
--host=$HOST_TRIPLET \
--build=$BUILD_TRIPLET \
--host="$HOST_TRIPLET" \
--build="$BUILD_TRIPLET" \
--enable-static \
--without-harfbuzz \
--without-png \
Expand All @@ -12,15 +12,15 @@ set -eu
ZLIB_CFLAGS="-I$INSTALL_ROOT/include" \
ZLIB_LIBS="-L$INSTALL_ROOT/lib -lz"

make -j $CPU_COUNT
make install prefix=$PREFIX
make -j "$CPU_COUNT"
make install prefix="$PREFIX"

mv $PREFIX/include/freetype2/* $PREFIX/include
rmdir $PREFIX/include/freetype2
mv "$PREFIX/include/freetype2/"* "$PREFIX/include"
rmdir "$PREFIX/include/freetype2"

# Some versions of Android (e.g. API level 26) have a libft2.so in /system/lib, but our copy
# has an SONAME of libfreetype.so, so there's no conflict.
# rm -r $PREFIX/lib/{*.a,*.la,pkgconfig}
rm -r $PREFIX/lib/{*.la,pkgconfig}
rm -r "$PREFIX/lib/"{*.la,pkgconfig}

rm -r $PREFIX/share
rm -r "$PREFIX/share"
8 changes: 4 additions & 4 deletions recipes/libffi/build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
set -eu

mkdir -p $PREFIX
cp -r include $PREFIX
cp -r lib $PREFIX
mkdir -p "$PREFIX"
cp -r include "$PREFIX"
cp -r lib "$PREFIX"

# Strip out any dylib files to ensure static linking
find $PREFIX -name "*.dylib" -exec rm -rf {} \;
find "$PREFIX" -name '*.dylib' -exec rm -rf {} \;
17 changes: 11 additions & 6 deletions recipes/libjpeg/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
set -eu

# SIMD is only available for x86, so disable for consistency between ABIs.
./configure --host=$HOST_TRIPLET --build=$BUILD_TRIPLET --without-turbojpeg --without-simd
make -j $CPU_COUNT
make install prefix=$PREFIX
./configure \
--host="$HOST_TRIPLET" \
--build="$BUILD_TRIPLET" \
--without-turbojpeg \
--without-simd
make -j "$CPU_COUNT"
make install prefix="$PREFIX"

rm -r $PREFIX/{bin,doc,man}
mv $PREFIX/lib?? $PREFIX/lib # lib32 or lib64
rm -r $PREFIX/lib/{*.la,pkgconfig}
# do not unintentionally delete /bin
rm -r "{$PREFIX:?}/"{bin,doc,man}
mv "$PREFIX/lib"?? "$PREFIX/lib" # lib32 or lib64
rm -r "$PREFIX/lib/"{*.la,pkgconfig}
21 changes: 11 additions & 10 deletions recipes/libpng/build.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#!/bin/bash
set -eu

./configure --host=$HOST_TRIPLET --build=$BUILD_TRIPLET
make -j $CPU_COUNT
make install prefix=$PREFIX
./configure --host="$HOST_TRIPLET" --build="$BUILD_TRIPLET"
make -j "$CPU_COUNT"
make install prefix="$PREFIX"

find $PREFIX -type l | xargs rm
find "$PREFIX" -type l -print0 | xargs -0 rm

rm -r $PREFIX/bin
# do not unintentionally delete /bin
rm -r "${PREFIX:?}/bin"

mv $PREFIX/include/libpng16/* $PREFIX/include
rmdir $PREFIX/include/libpng16
mv "$PREFIX/include/libpng16/"* "$PREFIX/include"
rmdir "$PREFIX/include/libpng16"

# Some versions of Android (e.g. API level 26) have a libpng.so in /system/lib, but our copy
# has an SONAME of libpng16.so, so there's no conflict.
# rm -r $PREFIX/lib/{*.a,*.la,pkgconfig}
# rm -r "$PREFIX/lib/"{*.a,*.la,pkgconfig}

# Downstream recipes expect the name libpng.a, not libpng16.a
mv $PREFIX/lib/libpng16.a $PREFIX/lib/libpng.a
mv "$PREFIX/lib/libpng16.a" "$PREFIX/lib/libpng.a"

rm -r $PREFIX/share
rm -r "$PREFIX/share"
1 change: 0 additions & 1 deletion recipes/lru-dict/test_lru_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ def test_basic():
data[1] = None
data[2] = None
data[3] = None
data[1]
data[4] = None
assert data.keys == [4, 1, 3]
6 changes: 3 additions & 3 deletions recipes/ninja/build.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/bin/bash
set -eu

mkdir -p $PREFIX
mkdir -p "$PREFIX"
cp -r ninja wheel

# Ensure the binary is executable
chmod +x wheel/ninja/data/bin/ninja

# Write the metadata for the entry point script
mkdir -p wheel/ninja-$VERSION.dist-info
cat << EOF > wheel/ninja-$VERSION.dist-info/entry_points.txt
mkdir -p "wheel/ninja-$VERSION.dist-info"
cat << EOF > "wheel/ninja-$VERSION.dist-info/entry_points.txt"
[console_scripts]
ninja = ninja:ninja
EOF
8 changes: 4 additions & 4 deletions recipes/openssl/build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
set -eu

mkdir -p $PREFIX
cp -r include $PREFIX
cp -r lib $PREFIX
mkdir -p "$PREFIX"
cp -r include "$PREFIX"
cp -r lib "$PREFIX"

# Strip out any dylib files to ensure static linking
find $PREFIX -name "*.dylib" -exec rm -rf {} \;
find "$PREFIX" -name '*.dylib' -exec rm -rf {} \;
4 changes: 2 additions & 2 deletions recipes/pillow/test/test_pillow.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ def test_font():
from PIL import ImageFont

font = ImageFont.truetype(join(dirname(__file__), "Vera.ttf"), size=20)
font.getsize("Hello") == (51, 19)
font.getsize("Hello world") == (112, 19)
assert font.getsize("Hello") == (51, 19)
assert font.getsize("Hello world") == (112, 19)
8 changes: 4 additions & 4 deletions recipes/xz/build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
set -eu

mkdir -p $PREFIX
cp -r include $PREFIX
cp -r lib $PREFIX
mkdir -p "$PREFIX"
cp -r include "$PREFIX"
cp -r lib "$PREFIX"

# Strip out any dylib files to ensure static linking
find $PREFIX -name "*.dylib" -exec rm -rf {} \;
find "$PREFIX" -name '*.dylib' -exec rm -rf {} \;
49 changes: 28 additions & 21 deletions setup-iOS.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/bash

# set -e

usage() {
Expand All @@ -16,20 +18,20 @@ usage() {
if [ "${BASH_SOURCE[0]}" = "$0" ]; then
echo "This script must be sourced."
echo
usage $0
usage "$0"
exit 1
fi

if [ -z "$1" ]; then
echo "Python version is not provided."
echo
usage $0
usage "$0"
return
fi

PYTHON_VER=$1

if [ ! -z "$VIRTUAL_ENV" ]; then
if [ -n "$VIRTUAL_ENV" ]; then
echo "A virtual environment is already active; deactivate that environment before calling this script."
return
fi
Expand All @@ -41,7 +43,8 @@ mkdir -p downloads
mkdir -p published

if [ -z "$PYTHON_APPLE_SUPPORT" ]; then
export MOBILE_FORGE_SUPPORT_PATH=$(pwd)/support
MOBILE_FORGE_SUPPORT_PATH="$(pwd)/support"
export MOBILE_FORGE_SUPPORT_PATH

if [ ! -d "$MOBILE_FORGE_SUPPORT_PATH/$PYTHON_VER/iOS" ]; then
if [ -z "$2" ]; then
Expand All @@ -62,49 +65,52 @@ if [ -z "$PYTHON_APPLE_SUPPORT" ]; then

if [ ! -e "downloads/Python-${PYTHON_VER}-iOS-support.b${SUPPORT_REVISION}.tar.gz" ]; then
echo "Downloading Python ${PYTHON_VER} b${SUPPORT_REVISION} support package"
curl --location "https://github.com/beeware/Python-Apple-support/releases/download/${PYTHON_VER}-b${SUPPORT_REVISION}/Python-${PYTHON_VER}-iOS-support.b${SUPPORT_REVISION}.tar.gz" --output downloads/Python-${PYTHON_VER}-iOS-support.b${SUPPORT_REVISION}.tar.gz
curl \
--location "https://github.com/beeware/Python-Apple-support/releases/download/${PYTHON_VER}-b${SUPPORT_REVISION}/Python-${PYTHON_VER}-iOS-support.b${SUPPORT_REVISION}.tar.gz" \
--output "downloads/Python-${PYTHON_VER}-iOS-support.b${SUPPORT_REVISION}.tar.gz"
fi

echo "Unpacking Python ${PYTHON_VER} b${SUPPORT_REVISION} support package"
mkdir -p $MOBILE_FORGE_SUPPORT_PATH/$PYTHON_VER/iOS
pushd $MOBILE_FORGE_SUPPORT_PATH/$PYTHON_VER/iOS
tar zxf ../../../downloads/Python-${PYTHON_VER}-iOS-support.b${SUPPORT_REVISION}.tar.gz
popd
mkdir -p "$MOBILE_FORGE_SUPPORT_PATH/$PYTHON_VER/iOS"
pushd "$MOBILE_FORGE_SUPPORT_PATH/$PYTHON_VER/iOS" || exit
tar zxf "../../../downloads/Python-${PYTHON_VER}-iOS-support.b${SUPPORT_REVISION}.tar.gz"
popd || exit
fi
else
export MOBILE_FORGE_SUPPORT_PATH=$PYTHON_APPLE_SUPPORT/support
export MOBILE_FORGE_SUPPORT_PATH="$PYTHON_APPLE_SUPPORT/support"
fi
echo "Using $MOBILE_FORGE_SUPPORT_PATH as the support folder"

BUILD_PYTHON=$(which python$PYTHON_VER)
if [ $? -ne 0 ]; then
BUILD_PYTHON=$(which "python$PYTHON_VER")
if [ -z "$BUILD_PYTHON" ]; then
echo "Can't find a Python $PYTHON_VER binary on the path."
return
fi

if [ ! -e $MOBILE_FORGE_SUPPORT_PATH/$PYTHON_VER/iOS/Python.xcframework/ios-arm64/bin/python$PYTHON_VER ]; then
if [ ! -e "$MOBILE_FORGE_SUPPORT_PATH/$PYTHON_VER/iOS/Python.xcframework/ios-arm64/bin/python$PYTHON_VER" ]; then
echo "Support folder does not appear to contain a Python $PYTHON_VER iOS device binary."
return
fi

if [ ! -e $MOBILE_FORGE_SUPPORT_PATH/$PYTHON_VER/iOS/Python.xcframework/ios-arm64_x86_64-simulator/bin/python$PYTHON_VER ]; then
if [ ! -e "$MOBILE_FORGE_SUPPORT_PATH/$PYTHON_VER/iOS/Python.xcframework/ios-arm64_x86_64-simulator/bin/python$PYTHON_VER" ]; then
echo "Support folder does not appear to contain a Python $PYTHON_VER iOS simulator binary."
return
fi

if [ ! -d ./venv$PYTHON_VER ]; then
if [ ! -d "./venv$PYTHON_VER" ]; then
echo "Creating Python $PYTHON_VER virtual environment for build..."
echo "Using $BUILD_PYTHON as the build python"
$BUILD_PYTHON -m venv venv$PYTHON_VER
$BUILD_PYTHON -m venv "venv$PYTHON_VER"

source ./venv$PYTHON_VER/bin/activate
# shellcheck disable=SC1090
source "./venv$PYTHON_VER/bin/activate"

# Install basic environment artefacts
pip install -U pip
pip install -U setuptools
pip install -e . wheel
pip install -U setuptools wheel
pip install -e .

echo "Python $PYTHON_VERSION environment has been created."
echo "Python $PYTHON_VER environment has been created."
echo
echo "You can now build packages with forge; e.g.:"
echo
Expand All @@ -128,5 +134,6 @@ if [ ! -d ./venv$PYTHON_VER ]; then
echo
else
echo "Using existing Python $PYTHON_VER environment."
source ./venv$PYTHON_VER/bin/activate
# shellcheck disable=SC1090
source "./venv$PYTHON_VER/bin/activate"
fi

0 comments on commit f5207e1

Please sign in to comment.