Skip to content

Commit 5f58a0f

Browse files
authored
Add 2nd layer of SDK (#19)
1 parent 89ae6cc commit 5f58a0f

File tree

411 files changed

+4942
-82383
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

411 files changed

+4942
-82383
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ branch = true
44

55
source =
66
cvat/apps/
7+
cvat-sdk/
78
cvat-cli/
89
utils/dataset_manifest
910

.github/workflows/black.yml

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,47 @@ jobs:
1414
PR_FILES_AM: ${{ steps.files.outputs.added_modified }}
1515
PR_FILES_RENAMED: ${{ steps.files.outputs.renamed }}
1616
run: |
17+
# If different modules use different Black configs,
18+
# we need to run Black for each python component group separately.
19+
# Otherwise, they all will use the same config.
20+
ENABLED_DIRS=("cvat-sdk" "cvat-cli" "tests/python/sdk" "tests/python/cli")
21+
22+
isValueIn () {
23+
# Checks if a value is in an array
24+
# https://stackoverflow.com/a/8574392
25+
# args: value, array
26+
local e match="$1"
27+
shift
28+
for e; do
29+
[[ "$e" == "$match" ]] && return 0;
30+
done
31+
return 1
32+
}
33+
34+
startswith () {
35+
# Inspired by https://stackoverflow.com/a/2172367
36+
# Checks if the first arg starts with the second one
37+
local value="$1"
38+
local beginning="$2"
39+
return $([[ $value == ${beginning}* ]])
40+
}
41+
1742
PR_FILES="$PR_FILES_AM $PR_FILES_RENAMED"
43+
UPDATED_DIRS=""
1844
for FILE in $PR_FILES; do
1945
EXTENSION="${FILE##*.}"
20-
DIRECTORY="${FILE%%/*}"
21-
if [[ "$EXTENSION" == "py" && "$DIRECTORY" == "cvat-cli" ]]; then
22-
CHANGED_FILES+=" $FILE"
46+
DIRECTORY="$(dirname $FILE)"
47+
if [[ "$EXTENSION" == "py" ]]; then
48+
for EDIR in ${ENABLED_DIRS[@]}; do
49+
if startswith "${DIRECTORY}/" "${EDIR}/" && ! isValueIn "${EDIR}" ${UPDATED_DIRS[@]};
50+
then
51+
UPDATED_DIRS+=" ${EDIR}"
52+
fi
53+
done
2354
fi
2455
done
2556
26-
if [[ ! -z $CHANGED_FILES ]]; then
57+
if [[ ! -z $UPDATED_DIRS ]]; then
2758
sudo apt-get --no-install-recommends install -y build-essential curl python3-dev python3-pip python3-venv
2859
python3 -m venv .env
2960
. .env/bin/activate
@@ -32,8 +63,11 @@ jobs:
3263
mkdir -p black_report
3364
3465
echo "Black version: "$(black --version)
35-
echo "The files will be checked: "$(echo $CHANGED_FILES)
36-
black --check --config ./cvat-cli/pyproject.toml $CHANGED_FILES > ./black_report/black_checks.txt || EXIT_CODE=$(echo $?) || true
66+
echo "The dirs will be checked: $UPDATED_DIRS"
67+
EXIT_CODE=0
68+
for DIR in $UPDATED_DIRS; do
69+
black --check $DIR >> ./black_report/black_checks.txt || EXIT_CODE=$(($? | $EXIT_CODE)) || true
70+
done
3771
deactivate
3872
exit $EXIT_CODE
3973
else

.github/workflows/full.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,20 @@ jobs:
164164
docker load --input /tmp/cvat_ui/image.tar
165165
docker image ls -a
166166
167-
- name: Running REST API tests
167+
- name: Running REST API and SDK tests
168168
run: |
169+
docker run --rm -v ${PWD}/cvat-sdk/schema/:/transfer \
170+
--entrypoint /bin/bash -u root cvat/server \
171+
-c 'python manage.py spectacular --file /transfer/schema.yml'
172+
pip3 install --user -r cvat-sdk/gen/requirements.txt
173+
cd cvat-sdk/
174+
gen/generate.sh
175+
cd ..
176+
169177
pip3 install --user cvat-sdk/
170-
pip3 install --user -r tests/rest_api/requirements.txt
171-
pytest tests/rest_api/ -s -v
178+
pip3 install --user cvat-cli/
179+
pip3 install --user -r tests/python/requirements.txt
180+
pytest tests/python -s -v
172181
173182
- name: Creating a log file from cvat containers
174183
if: failure()
@@ -226,7 +235,7 @@ jobs:
226235
while [[ $(curl -s -o /dev/null -w "%{http_code}" localhost:8181/health) != "200" && max_tries -gt 0 ]]; do (( max_tries-- )); sleep 5; done
227236
228237
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml run cvat_ci /bin/bash \
229-
-c 'python manage.py test cvat/apps cvat-cli -v 2'
238+
-c 'python manage.py test cvat/apps -v 2'
230239
231240
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml run cvat_ci /bin/bash \
232241
-c 'yarn --frozen-lockfile --ignore-scripts && yarn workspace cvat-core run test'

.github/workflows/isort.yml

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,47 @@ jobs:
1414
PR_FILES_AM: ${{ steps.files.outputs.added_modified }}
1515
PR_FILES_RENAMED: ${{ steps.files.outputs.renamed }}
1616
run: |
17+
# If different modules use different isort configs,
18+
# we need to run isort for each python component group separately.
19+
# Otherwise, they all will use the same config.
20+
ENABLED_DIRS=("cvat-sdk" "cvat-cli" "tests/python/sdk" "tests/python/cli")
21+
22+
isValueIn () {
23+
# Checks if a value is in an array
24+
# https://stackoverflow.com/a/8574392
25+
# args: value, array
26+
local e match="$1"
27+
shift
28+
for e; do
29+
[[ "$e" == "$match" ]] && return 0;
30+
done
31+
return 1
32+
}
33+
34+
startswith () {
35+
# Inspired by https://stackoverflow.com/a/2172367
36+
# Checks if the first arg starts with the second one
37+
local value="$1"
38+
local beginning="$2"
39+
return $([[ $value == ${beginning}* ]])
40+
}
41+
1742
PR_FILES="$PR_FILES_AM $PR_FILES_RENAMED"
43+
UPDATED_DIRS=""
1844
for FILE in $PR_FILES; do
1945
EXTENSION="${FILE##*.}"
20-
DIRECTORY="${FILE%%/*}"
21-
if [[ "$EXTENSION" == "py" && "$DIRECTORY" == "cvat-cli" ]]; then
22-
CHANGED_FILES+=" $FILE"
46+
DIRECTORY="$(dirname $FILE)"
47+
if [[ "$EXTENSION" == "py" ]]; then
48+
for EDIR in ${ENABLED_DIRS[@]}; do
49+
if startswith "${DIRECTORY}/" "${EDIR}/" && ! isValueIn "${EDIR}" ${UPDATED_DIRS[@]};
50+
then
51+
UPDATED_DIRS+=" ${EDIR}"
52+
fi
53+
done
2354
fi
2455
done
2556
26-
if [[ ! -z $CHANGED_FILES ]]; then
57+
if [[ ! -z $UPDATED_DIRS ]]; then
2758
sudo apt-get --no-install-recommends install -y build-essential curl python3-dev python3-pip python3-venv
2859
python3 -m venv .env
2960
. .env/bin/activate
@@ -32,8 +63,11 @@ jobs:
3263
mkdir -p isort_report
3364
3465
echo "isort version: "$(isort --version)
35-
echo "The files will be checked: "$(echo $CHANGED_FILES)
36-
isort --check --sp ./cvat-cli/pyproject.toml $CHANGED_FILES > ./isort_report/isort_checks.txt || EXIT_CODE=$(echo $?) || true
66+
echo "The dirs will be checked: $UPDATED_DIRS"
67+
EXIT_CODE=0
68+
for DIR in $UPDATED_DIRS; do
69+
isort --check $DIR >> ./isort_report/isort_checks.txt || EXIT_CODE=$(($? | $EXIT_CODE)) || true
70+
done
3771
deactivate
3872
exit $EXIT_CODE
3973
else

.github/workflows/main.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,17 @@ jobs:
133133
134134
- name: Running REST API tests
135135
run: |
136+
docker run --rm -v ${PWD}/cvat-sdk/schema/:/transfer \
137+
--entrypoint /bin/bash -u root cvat/server \
138+
-c 'python manage.py spectacular --file /transfer/schema.yml'
139+
pip3 install --user -r cvat-sdk/gen/requirements.txt
140+
cd cvat-sdk/
141+
gen/generate.sh
142+
cd ..
143+
136144
pip3 install --user cvat-sdk/
137-
pip3 install --user -r tests/rest_api/requirements.txt
138-
pytest tests/rest_api/ -k 'GET' -s
145+
pip3 install --user -r tests/python/requirements.txt
146+
pytest tests/python/rest_api -k 'GET' -s
139147
140148
- name: Creating a log file from cvat containers
141149
if: failure()
@@ -192,7 +200,7 @@ jobs:
192200
while [[ $(curl -s -o /dev/null -w "%{http_code}" localhost:8181/health) != "200" && max_tries -gt 0 ]]; do (( max_tries-- )); sleep 5; done
193201
194202
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml run cvat_ci /bin/bash \
195-
-c 'python manage.py test cvat/apps cvat-cli -k tasks_id -k lambda -k share -v 2'
203+
-c 'python manage.py test cvat/apps -k tasks_id -k lambda -k share -v 2'
196204
197205
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml run cvat_ci /bin/bash \
198206
-c 'yarn --frozen-lockfile --ignore-scripts && yarn workspace cvat-core run test'

.github/workflows/pylint.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ jobs:
1717
PR_FILES="$PR_FILES_AM $PR_FILES_RENAMED"
1818
for FILE in $PR_FILES; do
1919
EXTENSION="${FILE##*.}"
20-
DIRECTORY="${FILE%%/*}"
21-
if [[ "$EXTENSION" == 'py' && "$DIRECTORY" != 'cvat-sdk' ]]; then
20+
if [[ "$EXTENSION" == 'py' ]]; then
2221
CHANGED_FILES+=" $FILE"
2322
fi
2423
done

.github/workflows/schedule.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,21 @@ jobs:
222222
chmod +x ./opa
223223
./opa test cvat/apps/iam/rules
224224
225-
- name: REST API tests
225+
- name: REST API and SDK tests
226226
run: |
227+
docker run --rm -v ${PWD}/cvat-sdk/schema/:/transfer \
228+
--entrypoint /bin/bash -u root cvat/server \
229+
-c 'python manage.py spectacular --file /transfer/schema.yml'
230+
pip3 install --user -r cvat-sdk/gen/requirements.txt
231+
cd cvat-sdk/
232+
gen/generate.sh
233+
cd ..
234+
227235
pip3 install --user cvat-sdk/
228-
pip3 install --user -r tests/rest_api/requirements.txt
229-
pytest tests/rest_api/
230-
pytest tests/rest_api/ --stop-services
236+
pip3 install --user cvat-cli/
237+
pip3 install --user -r tests/python/requirements.txt
238+
pytest tests/python/
239+
pytest tests/python/ --stop-services
231240
232241
- name: Unit tests
233242
env:
@@ -239,7 +248,7 @@ jobs:
239248
while [[ $(curl -s -o /dev/null -w "%{http_code}" localhost:8181/health) != "200" && max_tries -gt 0 ]]; do (( max_tries-- )); sleep 5; done
240249
241250
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml run cvat_ci /bin/bash \
242-
-c 'coverage run -a manage.py test cvat/apps cvat-cli && mv .coverage ${CONTAINER_COVERAGE_DATA_DIR}'
251+
-c 'coverage run -a manage.py test cvat/apps && mv .coverage ${CONTAINER_COVERAGE_DATA_DIR}'
243252
244253
docker-compose -f docker-compose.yml -f docker-compose.dev.yml -f docker-compose.ci.yml run cvat_ci /bin/bash \
245254
-c 'yarn --frozen-lockfile --ignore-scripts && yarn workspace cvat-core run test'

0 commit comments

Comments
 (0)