Skip to content

Commit

Permalink
♻️ Maintenance: diverse fixes (codestyle, openapi, dockerignore) (#2593)
Browse files Browse the repository at this point in the history
* fix missing openapi entries
* ignore mypy cache files in dockerignore
* fix call of codestyle recipe in packages
* director-v2 to restart when packages are updated
  • Loading branch information
sanderegg authored Oct 21, 2021
1 parent c215bf9 commit c194216
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 42 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ dask*-space/

# produced when mounting volumes on docker and pip installing
.local/

# mypy cache
**/.mypy_cache/
3 changes: 3 additions & 0 deletions api/specs/webserver/components/schemas/files.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ FileMetaData:
type: integer
parent_id:
type: string
entity_tag:
type: string
example:
file_uuid: "simcore-testing/105/1000/3"
location_id: "0"
Expand All @@ -71,6 +73,7 @@ FileMetaData:
last_modified: "2019-06-19T12:29:03.78852Z"
file_size: 73
parent_id: "N:collection:e263da07-2d89-45a6-8b0f-61061b913873"
entity_tag: a87ff679a2f3e71d9181a67b7542122c

FileMetaDataArray:
type: array
Expand Down
29 changes: 16 additions & 13 deletions ci/github/unit-testing/dynamic-sidecar.bash
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
#!/bin/bash
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes
set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes
IFS=$'\n\t'

install() {
bash ci/helpers/ensure_python_pip.bash;
pushd services/dynamic-sidecar; pip3 install -r requirements/ci.txt -r requirements/_tools.txt; popd;
pip list -v
bash ci/helpers/ensure_python_pip.bash
pushd services/dynamic-sidecar
pip3 install -r requirements/ci.txt -r requirements/_tools.txt
popd
pip list -v
}

codestyle(){
scripts/codestyle.bash ci simcore_service_dynamic_sidecar services/dynamic-sidecar
codestyle() {
pushd services/dynamic-sidecar
make codestyle-ci
popd
}

test() {
pytest --cov=simcore_service_dynamic_sidecar --durations=10 --cov-append \
--color=yes --cov-report=term-missing --cov-report=xml --cov-config=.coveragerc \
-v -m "not travis" services/dynamic-sidecar/tests/unit
pytest --cov=simcore_service_dynamic_sidecar --durations=10 --cov-append \
--color=yes --cov-report=term-missing --cov-report=xml --cov-config=.coveragerc \
-v -m "not travis" services/dynamic-sidecar/tests/unit
}

# Check if the function exists (bash specific)
if declare -f "$1" > /dev/null
then
if declare -f "$1" >/dev/null; then
# call arguments verbatim
"$@"
else
Expand Down
2 changes: 1 addition & 1 deletion packages/models-library/requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
--requirement _test.txt

# installs this repo's packages
../postgres-database/[migration]
../pytest-simcore/
../postgres-database/

# current module
.
2 changes: 1 addition & 1 deletion packages/models-library/requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
--requirement _tools.txt

# installs this repo's packages
--editable ../pytest-simcore/
--editable ../postgres-database/[migration]
--editable ../pytest-simcore/

# current module
--editable .
17 changes: 6 additions & 11 deletions scripts/codestyle.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ set -o pipefail
IFS=$'\n\t'

SRC_DIRECTORY_NAME=${2}
BASE_PATH_DIR=${3-MISSING_DIR}


# global config for entire repo
PYLINT_CONFIG="$(git rev-parse --show-toplevel)/.pylintrc"
MYPY_CONFIG="$(git rev-parse --show-toplevel)/mypy.ini"


# used for development (fails on pylint and mypy)
Expand All @@ -24,23 +22,20 @@ development() {
echo "pylint"
pylint --rcfile="$PYLINT_CONFIG" src/"$SRC_DIRECTORY_NAME" tests/
echo "mypy"
mypy --ignore-missing-imports --config-file "$MYPY_CONFIG" src/"$SRC_DIRECTORY_NAME" tests/
make mypy
}

# invoked by ci as test (also fails on isort and black)
ci() {
echo "checking codestyle in service=$BASE_PATH_DIR with source_directory=$SRC_DIRECTORY_NAME"
echo "enforcing codestyle to source_directory=$SRC_DIRECTORY_NAME"
echo "isort"
isort --check setup.py "$BASE_PATH_DIR"/src/"$SRC_DIRECTORY_NAME" "$BASE_PATH_DIR"/tests
isort --check setup.py src/"$SRC_DIRECTORY_NAME" tests
echo "black"
black --check "$BASE_PATH_DIR"/src/"$SRC_DIRECTORY_NAME" "$BASE_PATH_DIR"/tests
black --check src/"$SRC_DIRECTORY_NAME" tests
echo "pylint ..."
pylint --rcfile="$PYLINT_CONFIG" "$BASE_PATH_DIR"/src/"$SRC_DIRECTORY_NAME" "$BASE_PATH_DIR"/tests
pylint --rcfile="$PYLINT_CONFIG" src/"$SRC_DIRECTORY_NAME" tests/
echo "mypy ..."
# installing all missing stub packages (e.g. types-PyYAML, types-aiofiles, etc)
python3 -m pip install types-aiofiles types-PyYAML types-ujson
# runs mypy
mypy --config-file "$MYPY_CONFIG" --ignore-missing-imports "$BASE_PATH_DIR"/src/"$SRC_DIRECTORY_NAME" "$BASE_PATH_DIR"/tests
make --silent mypy
}

# Allows to call a function based on arguments passed to the script
Expand Down
3 changes: 3 additions & 0 deletions scripts/common-package.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
# NOTE $(CURDIR) in this file refers to the directory where this file is included

# Variable based on conventions (override if they do not apply)
PACKAGE_NAME = $(notdir $(CURDIR))
PY_PACKAGE_NAME = $(subst -,_,$(PACKAGE_NAME))
PACKAGE_VERSION := $(shell cat VERSION)
SRC_DIR = $(abspath $(CURDIR)/src/$(PY_PACKAGE_NAME))

export PACKAGE_VERSION

Expand Down
4 changes: 2 additions & 2 deletions scripts/common.Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ code-analysis: $(REPO_BASE_DIR)/.codeclimate.yml ## runs code-climate analysis


.PHONY: codestyle
codestyle: ## enforces codestyle (isort & black) finally runs pylint & mypy
@$(SCRIPTS_DIR)/codestyle.bash development $(shell basename "${SRC_DIR}")
codestyle codestyle-ci: ## enforces codestyle (isort & black) finally runs pylint & mypy
@$(SCRIPTS_DIR)/codestyle.bash $(if $(findstring -ci,$@),ci,development) $(shell basename "${SRC_DIR}")

.PHONY: github-workflow-job
github-workflow-job: ## runs a github workflow job using act locally, run using "make github-workflow-job job=JOB_NAME"
Expand Down
30 changes: 19 additions & 11 deletions scripts/mypy.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,35 @@ set -o pipefail
IFS=$'\n\t'


image_name="$(basename $0):latest"
image_name="$(basename "$0"):latest"


docker build --tag "$image_name" -<<EOF
docker buildx build --tag "$image_name" &>/dev/null -<<EOF
FROM python:3.8.10-slim-buster
RUN pip install --upgrade pip && pip install mypy pydantic[email]
RUN pip install --upgrade pip \
&& pip install mypy \
pydantic[email] \
types-aiofiles \
types-PyYAML \
types-ujson \
types-setuptools
ENTRYPOINT ["mypy"]
EOF


target_path=$(realpath ${1:-Please give target path as argument})
target_path=$(realpath "${1:-Please give target path as argument}")
cd "$(dirname "$0")"
default_mypy_config="$(dirname ${PWD})/mypy.ini"
mypy_config=$(realpath ${2:-${default_mypy_config}})
default_mypy_config="$(git rev-parse --show-toplevel)/mypy.ini"
mypy_config=$(realpath "${2:-${default_mypy_config}}")

echo mypying ${target_path} using config in ${mypy_config}...

echo $default_mypy_config
echo mypying "${target_path}" using config in "${mypy_config}"...
echo using "$(docker run --rm "$image_name" --version)"
docker run --rm \
-v ${mypy_config}:/config/mypy.ini \
-v ${target_path}:/src \
--volume /etc/passwd:/etc/passwd:ro \
--volume /etc/group:/etc/group:ro \
--user $(id -u):$(id -g) \
--volume "${mypy_config}":/config/mypy.ini \
--volume "${target_path}":/src \
--workdir=/src \
"$image_name" \
--config-file /config/mypy.ini \
Expand Down
3 changes: 2 additions & 1 deletion services/director-v2/docker/boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ if [ "${SC_BOOT_MODE}" = "debug-ptvsd" ]; then
exec uvicorn simcore_service_director_v2.main:the_app \
--reload \
--host 0.0.0.0 \
--reload-dir services/director-v2/src/simcore_service_director_v2
--reload-dir services/director-v2/src/simcore_service_director_v2 \
--reload-dir packages
else
exec uvicorn simcore_service_director_v2.main:the_app \
--host 0.0.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def get_app_state(request: Request) -> State:
return request.app.state # type: ignore
return request.app.state


def get_application_health(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def write_to_tmp_file(file_contents: str) -> AsyncGenerator[Path, None]:
try:
yield file_path
finally:
await aiofiles.os.remove(file_path)
await aiofiles.os.remove(file_path) # type: ignore


@asynccontextmanager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5276,6 +5276,8 @@ paths:
type: integer
parent_id:
type: string
entity_tag:
type: string
example:
file_uuid: simcore-testing/105/1000/3
location_id: '0'
Expand All @@ -5296,6 +5298,7 @@ paths:
last_modified: '2019-06-19T12:29:03.78852Z'
file_size: 73
parent_id: 'N:collection:e263da07-2d89-45a6-8b0f-61061b913873'
entity_tag: a87ff679a2f3e71d9181a67b7542122c
default:
description: Default http error response body
content:
Expand Down Expand Up @@ -5528,6 +5531,8 @@ paths:
type: integer
parent_id:
type: string
entity_tag:
type: string
example:
file_uuid: simcore-testing/105/1000/3
location_id: '0'
Expand All @@ -5548,6 +5553,7 @@ paths:
last_modified: '2019-06-19T12:29:03.78852Z'
file_size: 73
parent_id: 'N:collection:e263da07-2d89-45a6-8b0f-61061b913873'
entity_tag: a87ff679a2f3e71d9181a67b7542122c
patch:
summary: Update File Metadata
tags:
Expand Down Expand Up @@ -5608,6 +5614,8 @@ paths:
type: integer
parent_id:
type: string
entity_tag:
type: string
example:
file_uuid: simcore-testing/105/1000/3
location_id: '0'
Expand All @@ -5628,6 +5636,7 @@ paths:
last_modified: '2019-06-19T12:29:03.78852Z'
file_size: 73
parent_id: 'N:collection:e263da07-2d89-45a6-8b0f-61061b913873'
entity_tag: a87ff679a2f3e71d9181a67b7542122c
responses:
'200':
description: Returns file metadata
Expand Down Expand Up @@ -5674,6 +5683,8 @@ paths:
type: integer
parent_id:
type: string
entity_tag:
type: string
example:
file_uuid: simcore-testing/105/1000/3
location_id: '0'
Expand All @@ -5694,6 +5705,7 @@ paths:
last_modified: '2019-06-19T12:29:03.78852Z'
file_size: 73
parent_id: 'N:collection:e263da07-2d89-45a6-8b0f-61061b913873'
entity_tag: a87ff679a2f3e71d9181a67b7542122c
'/storage/locations/{location_id}/datasets/{dataset_id}/metadata':
get:
summary: Get Files Metadata
Expand Down Expand Up @@ -5759,6 +5771,8 @@ paths:
type: integer
parent_id:
type: string
entity_tag:
type: string
example:
file_uuid: simcore-testing/105/1000/3
location_id: '0'
Expand All @@ -5779,6 +5793,7 @@ paths:
last_modified: '2019-06-19T12:29:03.78852Z'
file_size: 73
parent_id: 'N:collection:e263da07-2d89-45a6-8b0f-61061b913873'
entity_tag: a87ff679a2f3e71d9181a67b7542122c
default:
description: Default http error response body
content:
Expand Down

0 comments on commit c194216

Please sign in to comment.