Skip to content

Commit 7b11dd1

Browse files
authored
♻️🔨 Is638/dynamic sidecar refactoring (round 1) (ITISFoundation#3147)
1 parent 7d954f4 commit 7b11dd1

Some content is hidden

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

46 files changed

+480
-492
lines changed

.pre-commit-config.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,35 @@ repos:
66
- repo: https://github.com/pre-commit/pre-commit-hooks
77
rev: v4.2.0
88
hooks:
9-
- id: trailing-whitespace
10-
- id: end-of-file-fixer
11-
- id: check-yaml
129
- id: check-added-large-files
10+
args: ["--maxkb=1024"]
1311
- id: check-merge-conflict
12+
- id: check-yaml
13+
- id: detect-private-key
14+
- id: end-of-file-fixer
15+
- id: trailing-whitespace
1416
# NOTE: Keep order as pyupgrade (will update code) then pycln (remove unused imports), then isort (sort them) and black (final formatting)
1517
- repo: https://github.com/asottile/pyupgrade
1618
rev: v2.34.0
1719
hooks:
1820
- id: pyupgrade
1921
args:
2022
- "--py39-plus"
23+
name: upgrade code
2124
- repo: https://github.com/hadialqattan/pycln
2225
rev: v1.2.5
2326
hooks:
2427
- id: pycln
2528
args: [--all, --expand-stars]
29+
name: prune imports
2630
- repo: https://github.com/PyCQA/isort
2731
rev: 5.10.1
2832
hooks:
2933
- id: isort
34+
args: ["--profile", "black"]
35+
name: sort imports
3036
- repo: https://github.com/psf/black
3137
rev: 22.3.0
3238
hooks:
3339
- id: black
40+
name: format code

mypy.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ disallow_any_generics = True
1919
check_untyped_defs = True
2020
no_implicit_reexport = True
2121

22-
# for strict mypy: (this is the tricky one :-))
23-
disallow_untyped_defs = True
22+
# If True, it enforces things like `def __init__(self) -> CLASSNAME` or `def test_() -> None` which does not worth the effort
23+
disallow_untyped_defs = False
2424

2525
# removes all the missing imports stuff from external libraries which is annoying to the least
2626
ignore_missing_imports = True

packages/pytest-simcore/src/pytest_simcore/docker_swarm.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,16 @@
3131
# HELPERS --------------------------------------------------------------------------------
3232

3333

34-
class _NotInSwarmException(Exception):
35-
pass
36-
37-
3834
class _ResourceStillNotRemoved(Exception):
3935
pass
4036

4137

42-
def _in_docker_swarm(
43-
docker_client: docker.client.DockerClient, raise_error: bool = False
44-
) -> bool:
38+
def _is_docker_swarm_init(docker_client: docker.client.DockerClient) -> bool:
4539
try:
4640
docker_client.swarm.reload()
4741
inspect_result = docker_client.swarm.attrs
4842
assert type(inspect_result) == dict
4943
except APIError as error:
50-
if raise_error:
51-
raise _NotInSwarmException() from error
5244
return False
5345
return True
5446

@@ -147,6 +139,7 @@ def _fetch_and_print_services(
147139
def docker_client() -> Iterator[docker.client.DockerClient]:
148140
client = docker.from_env()
149141
yield client
142+
client.close()
150143

151144

152145
@pytest.fixture(scope="session")
@@ -164,14 +157,13 @@ def docker_swarm(
164157
wait=wait_fixed(2), stop=stop_after_delay(15), reraise=True
165158
):
166159
with attempt:
167-
if not _in_docker_swarm(docker_client):
160+
if not _is_docker_swarm_init(docker_client):
168161
print("--> initializing docker swarm...")
169162
docker_client.swarm.init(advertise_addr=get_localhost_ip())
170163
print("--> docker swarm initialized.")
171-
# if still not in swarm, raise an error to try and initialize again
172-
_in_docker_swarm(docker_client, raise_error=True)
173164

174-
assert _in_docker_swarm(docker_client) is True
165+
# if still not in swarm, raise an error to try and initialize again
166+
assert _is_docker_swarm_init(docker_client)
175167

176168
yield
177169

@@ -180,6 +172,8 @@ def docker_swarm(
180172
assert docker_client.swarm.leave(force=True)
181173
print("<-- docker swarm left.")
182174

175+
assert _is_docker_swarm_init(docker_client) is keep_docker_up
176+
183177

184178
@pytest.fixture(scope="module")
185179
def docker_stack(

packages/pytest-simcore/src/pytest_simcore/monkeypatch_extra.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
# pylint: disable=unused-argument
33
# pylint: disable=unused-variable
44

5+
import warnings
56
from typing import Iterator
67

78
import pytest
89
from _pytest.fixtures import FixtureRequest
910
from _pytest.monkeypatch import MonkeyPatch
1011

12+
warnings.warn(
13+
f"{__name__} is deprecated, we highly recommend to use pytest.monkeypatch at function-scope level."
14+
"Large scopes lead to complex problems during tests",
15+
DeprecationWarning,
16+
)
1117
# Some extras to overcome https://github.com/pytest-dev/pytest/issues/363
1218
# SEE https://github.com/pytest-dev/pytest/issues/363#issuecomment-289830794
1319

packages/pytest-simcore/src/pytest_simcore/repository_paths.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ def pylintrc(osparc_simcore_root_dir: Path) -> Path:
9696
@pytest.fixture(scope="session")
9797
def project_slug_dir() -> Path:
9898
raise NotImplementedError("Override fixture in project's tests/conftest.py")
99+
#
100+
# Implementation example
101+
# folder = CURRENT_DIR.parent
102+
# assert folder.exists()
103+
# assert any(folder.glob("src/simcore_service_dynamic_sidecar"))
104+
# return folder
105+
#
99106

100107

101108
@pytest.fixture(scope="session")

packages/settings-library/src/settings_library/utils_logging.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44

55

66
class MixinLoggingSettings:
7+
"""
8+
USAGE example in packages/settings-library/tests/test_utils_logging.py::test_mixin_logging
9+
"""
10+
711
@classmethod
812
def validate_log_level(cls, value: Any) -> str:
13+
"""Standard implementation for @validator("LOG_LEVEL")"""
914
try:
1015
getattr(logging, value.upper())
1116
except AttributeError as err:

services/director-v2/tests/unit/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def dynamic_service_create() -> DynamicServiceCreate:
6767
)
6868

6969

70-
@pytest.fixture(scope="session")
70+
@pytest.fixture
7171
def dynamic_sidecar_port() -> int:
7272
return 1222
7373

0 commit comments

Comments
 (0)