Skip to content

Commit 9143165

Browse files
authored
added models library python package (#1856)
added models library python package fixed isort configuration
1 parent bc7b1b0 commit 9143165

File tree

59 files changed

+886
-358
lines changed

Some content is hidden

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

59 files changed

+886
-358
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Makefile @pcrespov, @sanderegg
99
/ci/ @sanderegg, @pcrespov
1010
/docs/ @pcrespov
1111
/packages/pytest-simcore @pcrespov, @sanderegg
12+
/packages/models-library @sanderegg, @pcrespov
1213
/packages/service-library @pcrespov
1314
/scripts/demo @odeimaiz, @pcrespov
1415
/scripts/json-schema-to-openapi-schema @sanderegg

.github/workflows/ci-testing-deploy.yml

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ jobs:
339339
run: ./ci/github/unit-testing/python-linting.bash test
340340

341341
unit-test-postgres-database:
342-
name: Unit-testing postgres-database
342+
name: "[unit] postgres-database"
343343
runs-on: ${{ matrix.os }}
344344
strategy:
345345
matrix:
@@ -436,6 +436,55 @@ jobs:
436436
name: unit_servicelib_coverage
437437
path: codeclimate.unit_servicelib_coverage.json
438438

439+
unit-test-models-library:
440+
name: "[unit] models-library"
441+
runs-on: ${{ matrix.os }}
442+
strategy:
443+
matrix:
444+
python: [3.6]
445+
os: [ubuntu-20.04]
446+
fail-fast: false
447+
steps:
448+
- uses: actions/checkout@v2
449+
- name: setup docker
450+
run: |
451+
sudo ./ci/github/helpers/setup_docker_compose.bash
452+
./ci/github/helpers/setup_docker_experimental.bash
453+
./ci/github/helpers/setup_docker_buildx.bash
454+
echo ::set-env name=DOCKER_BUILDX::1
455+
- name: setup python environment
456+
uses: actions/setup-python@v2
457+
with:
458+
python-version: ${{ matrix.python }}
459+
- name: show system version
460+
run: ./ci/helpers/show_system_versions.bash
461+
- uses: actions/cache@v2
462+
name: getting cached data
463+
with:
464+
path: ~/.cache/pip
465+
key: ${{ runner.os }}-pip-models-library-${{ hashFiles('packages/models-library/requirements/ci.txt') }}
466+
restore-keys: |
467+
${{ runner.os }}-pip-models-library-
468+
${{ runner.os }}-pip-
469+
${{ runner.os }}-
470+
- name: install
471+
run: ./ci/github/unit-testing/models-library.bash install
472+
- name: test
473+
run: ./ci/github/unit-testing/models-library.bash test
474+
- uses: codecov/codecov-action@v1
475+
with:
476+
flags: unittests #optional
477+
- name: prepare codeclimate coverage file
478+
run: |
479+
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
480+
chmod +x ./cc-test-reporter
481+
./cc-test-reporter format-coverage -t coverage.py -o codeclimate.unit_modelslib_coverage.json coverage.xml
482+
- name: upload codeclimate coverage
483+
uses: actions/upload-artifact@v2
484+
with:
485+
name: unit_modelslib_coverage
486+
path: codeclimate.unit_modelslib_coverage.json
487+
439488
unit-test-simcore-sdk:
440489
name: "[unit] simcore-sdk"
441490
runs-on: ${{ matrix.os }}
@@ -737,7 +786,7 @@ jobs:
737786
build-test-images:
738787
# make PR faster by executing this one straight as PR cannot push to the registry anyway
739788
runs-on: ubuntu-20.04
740-
name: build docker test images
789+
name: "[build] docker images"
741790
steps:
742791
- uses: actions/checkout@v2
743792
- name: setup docker
@@ -1135,6 +1184,7 @@ jobs:
11351184
unit-test-director,
11361185
unit-test-sidecar,
11371186
unit-test-service-library,
1187+
unit-test-models-library,
11381188
unit-test-simcore-sdk,
11391189
unit-test-storage,
11401190
unit-test-webserver-isolated,
@@ -1164,6 +1214,9 @@ jobs:
11641214
- uses: actions/download-artifact@v1
11651215
with:
11661216
name: unit_servicelib_coverage
1217+
- uses: actions/download-artifact@v1
1218+
with:
1219+
name: unit_modelslib_coverage
11671220
- uses: actions/download-artifact@v1
11681221
with:
11691222
name: unit_simcoresdk_coverage
@@ -1200,6 +1253,7 @@ jobs:
12001253
unit_director_coverage/*.json \
12011254
unit_sidecar_coverage/*.json \
12021255
unit_servicelib_coverage/*.json \
1256+
unit_modelslib_coverage/*.json \
12031257
unit_simcoresdk_coverage/*.json \
12041258
unit_storage_coverage/*.json \
12051259
unit_webserver_isolated_coverage/*.json \
@@ -1215,7 +1269,7 @@ jobs:
12151269
run: |
12161270
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
12171271
chmod +x ./cc-test-reporter
1218-
./cc-test-reporter sum-coverage all_coverages/codeclimate.*.json --parts 14
1272+
./cc-test-reporter sum-coverage all_coverages/codeclimate.*.json --parts 15
12191273
- name: upload coverages
12201274
run: |
12211275
./cc-test-reporter upload-coverage
@@ -1232,6 +1286,7 @@ jobs:
12321286
unit-test-frontend,
12331287
unit-test-python-linting,
12341288
unit-test-service-library,
1289+
unit-test-models-library,
12351290
unit-test-simcore-sdk,
12361291
unit-test-storage,
12371292
unit-test-webserver-isolated,

.isort.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[*.py]
2+
profile=black
3+
4+
#custom
5+
float_to_top=True

.travis.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,27 @@ jobs:
277277
- bash ci/travis/unit-testing/service-library.bash after_failure
278278

279279
# test python, service-library ----------------------------------------------------------------------
280+
- stage: build / unit-testing
281+
name: models-library
282+
language: python
283+
python:
284+
- "3.6"
285+
sudo: required
286+
cache: pip
287+
before_install:
288+
- sudo bash ci/travis/unit-testing/service-library.bash before_install
289+
install:
290+
- bash ci/travis/unit-testing/service-library.bash install
291+
before_script:
292+
- bash ci/travis/unit-testing/service-library.bash before_script
293+
script:
294+
- bash ci/travis/unit-testing/service-library.bash script
295+
after_success:
296+
- bash ci/travis/unit-testing/service-library.bash after_success
297+
after_failure:
298+
- bash ci/travis/unit-testing/service-library.bash after_failure
299+
300+
# test python, simcore-sdk-library ----------------------------------------------------------------------
280301
- stage: build / unit-testing
281302
name: simcore-sdk
282303
language: python

.vscode/settings.template.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,9 @@
3434
"shellcheck.executablePath": "${workspaceFolder}/scripts/shellcheck.bash",
3535
"shellcheck.run": "onSave",
3636
"shellcheck.enableQuickFix": true,
37-
"python.formatting.provider": "black"
37+
"python.formatting.provider": "black",
38+
"python.sortImports.path": "${VIRTUAL_ENV}/bin/isort",
39+
"python.sortImports.args": [
40+
"--settings-path=${workspaceFolder}/.isort.cfg"
41+
]
3842
}

CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ FIXME: Compare shows single commit. SEE https://github.com/ITISFoundation/osparc
1515
- ``migration`` service that discovers postgres service and upgrades main database [#1714](https://github.com/ITISFoundation/osparc-simcore/pull/1714)
1616
- Every group can register official classifiers for studies and services. Diplayed as a tree in UI [#1670](https://github.com/ITISFoundation/osparc-simcore/pull/1670), [#1719](https://github.com/ITISFoundation/osparc-simcore/pull/1719) , [#1722](https://github.com/ITISFoundation/osparc-simcore/pull/1722)
1717
- GC tests are run in isolation with a template database [#1724](https://github.com/ITISFoundation/osparc-simcore/pull/1724)
18+
- Added models_library python package that contains all basic pydantic models for use in simcore [#1856](https://github.com/ITISFoundation/osparc-simcore/pull/1856)
1819

1920
### Changed
2021

@@ -32,23 +33,23 @@ FIXME: Compare shows single commit. SEE https://github.com/ITISFoundation/osparc
3233

3334
### Added
3435
- add traefik endpoint to api-gateway [#1555](https://github.com/ITISFoundation/osparc-simcore/pull/1555)
35-
- Shared project concurrency (frontend) [#1591](https://github.com/ITISFoundation/osparc-simcore/pull/1591)
36+
- Shared project concurrency (frontend) [#1591](https://github.com/ITISFoundation/osparc-simcore/pull/1591)
3637
- Homogenize studies and services [#1569](https://github.com/ITISFoundation/osparc-simcore/pull/1569)
3738
- UI Fine grained access - project locking and notification
3839
- Adds support for GPU scheduling of computational services [#1553](https://github.com/ITISFoundation/osparc-simcore/pull/1553)
3940

4041
### Changed
41-
- UI/UX improvements [#1657](https://github.com/ITISFoundation/osparc-simcore/pull/1657)
42+
- UI/UX improvements [#1657](https://github.com/ITISFoundation/osparc-simcore/pull/1657)
4243
- Improving storage performance [#1659](https://github.com/ITISFoundation/osparc-simcore/pull/1659)
4344
- Theming [#1656](https://github.com/ITISFoundation/osparc-simcore/pull/1656)
44-
- Reduce cardinality of metrics [#1593](https://github.com/ITISFoundation/osparc-simcore/pull/1593)
45+
- Reduce cardinality of metrics [#1593](https://github.com/ITISFoundation/osparc-simcore/pull/1593)
4546

4647
### Fixed
4748
- Platform stability: [#1645](https://github.com/ITISFoundation/osparc-simcore/pull/1645)
4849
- Fix, improves and re-activate e2e CI testing [#1594](https://github.com/ITISFoundation/osparc-simcore/pull/1594), [#1620](https://github.com/ITISFoundation/osparc-simcore/pull/1620), [#1631](https://github.com/ITISFoundation/osparc-simcore/pull/1631), [#1600](https://github.com/ITISFoundation/osparc-simcore/pull/1600)
4950
- Fixes defaults [#1640](https://github.com/ITISFoundation/osparc-simcore/pull/1640)
5051
- Upgrade storage service [#1585](https://github.com/ITISFoundation/osparc-simcore/pull/1585), [#1586](https://github.com/ITISFoundation/osparc-simcore/pull/1586)
51-
- UPgrade catalog service [#1582](https://github.com/ITISFoundation/osparc-simcore/pull/1582)
52+
- UPgrade catalog service [#1582](https://github.com/ITISFoundation/osparc-simcore/pull/1582)
5253
- Fixes on publish studies handling [#1632](https://github.com/ITISFoundation/osparc-simcore/pull/1632)
5354
- Invalidate cache before starting a study [#1602](https://github.com/ITISFoundation/osparc-simcore/pull/1602)
5455
- Some enhancements and bug fixes [#1608](https://github.com/ITISFoundation/osparc-simcore/pull/1608)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
3+
set -euo pipefail
4+
IFS=$'\n\t'
5+
6+
install() {
7+
bash ci/helpers/ensure_python_pip.bash
8+
pushd packages/models-library
9+
pip3 install -r requirements/ci.txt
10+
popd
11+
pip list -v
12+
}
13+
14+
test() {
15+
pytest --cov=models_library --durations=10 --cov-append \
16+
--color=yes --cov-report=term-missing --cov-report=xml --cov-config=.coveragerc \
17+
-v -m "not travis" packages/models-library/tests
18+
}
19+
20+
# Check if the function exists (bash specific)
21+
if declare -f "$1" >/dev/null; then
22+
# call arguments verbatim
23+
"$@"
24+
else
25+
# Show a helpful error
26+
echo "'$1' is not a known function name" >&2
27+
exit 1
28+
fi
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
3+
set -euo pipefail
4+
IFS=$'\n\t'
5+
6+
FOLDER_CHECKS=(packages/ models-library .travis.yml)
7+
8+
before_install() {
9+
if bash ci/travis/helpers/test-for-changes.bash "${FOLDER_CHECKS[@]}"; then
10+
bash ci/travis/helpers/update-docker.bash
11+
bash ci/travis/helpers/install-docker-compose.bash
12+
bash ci/helpers/show_system_versions.bash
13+
fi
14+
}
15+
16+
install() {
17+
if bash ci/travis/helpers/test-for-changes.bash "${FOLDER_CHECKS[@]}"; then
18+
bash ci/helpers/ensure_python_pip.bash
19+
pushd packages/models-library
20+
pip3 install -r requirements/ci.txt
21+
popd
22+
fi
23+
}
24+
25+
before_script() {
26+
if bash ci/travis/helpers/test-for-changes.bash "${FOLDER_CHECKS[@]}"; then
27+
pip list -v
28+
fi
29+
}
30+
31+
script() {
32+
if bash ci/travis/helpers/test-for-changes.bash "${FOLDER_CHECKS[@]}"; then
33+
pytest --cov=models_library --durations=10 --cov-append \
34+
--color=yes --cov-report=term-missing --cov-report=xml --cov-config=.coveragerc \
35+
-v -m "not travis" packages/models-library/tests
36+
else
37+
echo "No changes detected. Skipping unit-testing of models-library."
38+
fi
39+
}
40+
41+
after_success() {
42+
if bash ci/travis/helpers/test-for-changes.bash "${FOLDER_CHECKS[@]}"; then
43+
coveralls
44+
fi
45+
}
46+
47+
after_failure() {
48+
echo "failure..."
49+
}
50+
51+
# Check if the function exists (bash specific)
52+
if declare -f "$1" >/dev/null; then
53+
# call arguments verbatim
54+
"$@"
55+
else
56+
# Show a helpful error
57+
echo "'$1' is not a known function name" >&2
58+
exit 1
59+
fi

packages/models-library/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Targets for DEVELOPMENT of models Library
3+
#
4+
include ../../scripts/common.Makefile
5+
include ../../scripts/common-package.Makefile
6+
7+
.PHONY: requirements
8+
requirements: ## compiles pip requirements (.in -> .txt)
9+
@$(MAKE_C) requirements reqs
10+
11+
12+
.PHONY: install-dev install-prod install-ci
13+
install-dev install-prod install-ci: _check_venv_active ## install app in development/production or CI mode
14+
# installing in $(subst install-,,$@) mode
15+
python -m pip install -r requirements/$(subst install-,,$@).txt
16+
17+
18+
.PHONY: tests
19+
tests: ## runs unit tests
20+
# running unit tests
21+
@pytest -vv --exitfirst --failed-first --durations=10 --pdb $(CURDIR)/tests

packages/models-library/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# simcore pydantic models library
2+
3+
Contains the [pydantic](https://pydantic-docs.helpmanual.io/)-based models for use in the simcore platform. As a reminder pydantic allows creation of python classes that automatically validate their contents based on types. It also provides mechanism to generate json schemas describing the classes internals.
4+
5+
Requirements to be compatible with the library:
6+
7+
- be a pydantic-based model
8+
- not a model for use in a REST API (or at least not directly) only for a specific service (ServiceUpdate model for use in a PATCH REST call on the webserver has nothing to do in the library for example, but a base class for it is ok)
9+
10+
## Installation
11+
12+
```console
13+
make help
14+
make install-dev
15+
```
16+
17+
## Test
18+
19+
```console
20+
make help
21+
make test-dev
22+
```

0 commit comments

Comments
 (0)