Skip to content

Commit

Permalink
chore: fix YQ actions + formats CI (bentoml#2129)
Browse files Browse the repository at this point in the history
  • Loading branch information
aarnphm committed Dec 14, 2021
1 parent 789d0e8 commit 9a5ff98
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
4 changes: 1 addition & 3 deletions .yamllint.yml
Expand Up @@ -26,7 +26,5 @@ rules:
indentation:
level: warning
indent-sequences: consistent
line-length:
level: warning
allow-non-breakable-inline-mappings: true
line-length: disable
truthy: disable
2 changes: 1 addition & 1 deletion hooks/pre-commit
Expand Up @@ -9,7 +9,7 @@ VALID_BRANCH_REGEX="^(style|chore|refactor|feat|internal|bugfix|improvement|libr
cd "$GIT_ROOT" || exit

# format setup.cfg
setup-cfg-fmt "$GIT_ROOT/setup.cfg"
setup-cfg-fmt --max-py-version 3.9 "$GIT_ROOT/setup.cfg"

# Run format scripts
# ./scripts/tools/formatter.sh || exit 1
Expand Down
33 changes: 25 additions & 8 deletions scripts/ci/run_tests.sh
Expand Up @@ -2,7 +2,7 @@

# Prerequisite:
# This scripts assumes BentoML and all its test dependencies are already installed:
#
#
# pip install -e .
# pip install requirements/tests-requirements.txt

Expand Down Expand Up @@ -132,19 +132,36 @@ parse_config() {
}

install_yq() {
set -ex
target_dir="$HOME/.local/bin"

mkdir -p "$target_dir"
export PATH=$target_dir:$PATH

YQ_VERSION=4.14.2
YQ_VERSION=4.16.1
echo "Trying to install yq..."
__shell=$(uname | tr '[:upper:]' '[:lower:]')
YQ_BINARY=yq_"$__shell"_amd64
curl -fsSLO https://github.com/mikefarah/yq/releases/download/v"$YQ_VERSION"/"$YQ_BINARY".tar.gz
echo "tar $YQ_BINARY.tar.gz and move to /usr/bin/yq..."
tar -zvxf "$YQ_BINARY.tar.gz" "./$YQ_BINARY" && mv "./$YQ_BINARY" "$target_dir"/yq
rm -f ./"$YQ_BINARY".tar.gz
shell=$(uname | tr '[:upper:]' '[:lower:]')
extensions=".tar.gz"
if [[ "$shell" =~ "mingw64" ]]; then
shell="windows"
extensions=".zip"
fi

YQ_BINARY=yq_"$shell"_amd64
YQ_EXTRACT="./$YQ_BINARY"
if [[ "$shell" == "windows" ]]; then
YQ_EXTRACT="$YQ_BINARY.exe"
fi
curl -fsSLO https://github.com/mikefarah/yq/releases/download/v"$YQ_VERSION"/"$YQ_BINARY""$extensions"
echo "tar $YQ_BINARY$extensions and move to /usr/bin/yq..."
if [[ $(uname | tr '[:upper:]' '[:lower:]') =~ "mingw64" ]]; then
unzip -qq "$YQ_BINARY$extensions" -d yq_dir && cd yq_dir
mv "$YQ_EXTRACT" "$target_dir"/yq && cd ..
rm -rf yq_dir
else
tar -zvxf "$YQ_BINARY$extensions" "$YQ_EXTRACT" && mv "$YQ_EXTRACT" "$target_dir"/yq
fi
rm -f ./"$YQ_BINARY""$extensions"
}


Expand Down
2 changes: 1 addition & 1 deletion scripts/tools/formatter.sh
Expand Up @@ -12,7 +12,7 @@ black --config ./pyproject.toml bentoml/ tests/ docker/

INFO "(black) Formatting VCS stubs..."

git ls-files -z -cm typings/** | xargs -0 -I {} black --config ./pyproject.toml --pyi {}
git ls-files -z -cm -- typings ':!:*.md' | xargs -0 -I {} -r sh -c 'echo "Processing "{}"..."; black --config ./pyproject.toml --pyi {}'

INFO "(isort) Reordering imports..."

Expand Down
18 changes: 3 additions & 15 deletions tests/integration/frameworks/test_detectron2_impl.py
@@ -1,4 +1,3 @@
import sys
import typing as t
from typing import TYPE_CHECKING

Expand All @@ -20,12 +19,6 @@
from bentoml._internal.models import ModelStore


if sys.version_info >= (3, 8):
from typing import Protocol
else:
from typing_extensions import Protocol


IMAGE_URL: str = "./tests/utils/_static/detectron2_sample.jpg"


Expand Down Expand Up @@ -70,11 +63,6 @@ def detectron_model_and_config() -> t.Tuple[torch.nn.Module, "CfgNode"]:
return model, cfg


class ImageArray(Protocol):
def __call__(self) -> "np.ndarray[t.Any, np.dtype[t.Any]]":
...


@pytest.fixture(scope="module", name="image_array")
def fixture_image_array() -> "np.ndarray[t.Any, np.dtype[t.Any]]":
return np.asarray(imageio.imread(IMAGE_URL))
Expand All @@ -95,7 +83,7 @@ def save_procedure(metadata: t.Dict[str, t.Any], _modelstore: "ModelStore") -> "
@pytest.mark.parametrize("metadata", [{"acc": 0.876}])
def test_detectron2_save_load(
metadata: t.Dict[str, t.Any],
image_array: ImageArray,
image_array: "np.ndarray[t.Any, np.dtype[t.Any]]",
modelstore: "ModelStore",
) -> None:
tag = save_procedure(metadata, _modelstore=modelstore)
Expand All @@ -120,7 +108,7 @@ def test_detectron2_save_load(


def test_detectron2_setup_run_batch(
image_array: ImageArray, modelstore: "ModelStore"
image_array: "np.ndarray[t.Any, np.dtype[t.Any]]", modelstore: "ModelStore"
) -> None:
tag = save_procedure({}, _modelstore=modelstore)
runner = bentoml.detectron.load_runner(tag, model_store=modelstore)
Expand All @@ -130,4 +118,4 @@ def test_detectron2_setup_run_batch(
image = torch.as_tensor(prepare_image(image_array))
res = runner.run_batch(image)
result = extract_result(res[0])
assert result["scores"][0] > 0.9
assert result["boxes"] is not None

0 comments on commit 9a5ff98

Please sign in to comment.