Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop typeguard + backport apptainer version #139

Merged
merged 6 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Install grpc
uses: ewatercycle/setup-grpc@v4
with:
grpc-version: 1.27.2
grpc-version: 1.47.3
- name: Copy grpc to system default
run: |
sudo rsync -a $GRPC_ROOT/ /usr/local
Expand Down
8 changes: 1 addition & 7 deletions grpc4bmi/bmi_client_apptainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from packaging.specifiers import SpecifierSet
from packaging.version import Version
from typeguard import check_argument_types, qualified_name

from grpc4bmi.bmi_grpc_client import BmiClient
from grpc4bmi.exceptions import ApptainerVersionException, DeadContainerException
Expand All @@ -17,7 +16,7 @@

def check_apptainer_version_string(version_output: str) -> bool:
version = version_output.split(' ').pop()
local_version = Version(version)
local_version = Version(version.replace('.el', ''))
if local_version not in SpecifierSet(SUPPORTED_APPTAINER_VERSIONS):
raise ApptainerVersionException(f'Unsupported version ({version_output}) of apptainer found, '
f'supported versions {SUPPORTED_APPTAINER_VERSIONS}')
Expand Down Expand Up @@ -197,11 +196,6 @@ class BmiClientApptainer(BmiClient):
def __init__(self, image: str, work_dir: str, input_dirs: Iterable[str] = tuple(), delay=0, timeout=None,
capture_logs=True,
):
assert check_argument_types()
if type(input_dirs) == str:
msg = f'type of argument "input_dirs" must be collections.abc.Iterable; ' \
f'got {qualified_name(input_dirs)} instead'
raise TypeError(msg)
check_apptainer_version()
host = 'localhost'
port = BmiClient.get_unique_port(host)
Expand Down
6 changes: 0 additions & 6 deletions grpc4bmi/bmi_client_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Iterable

import docker
from typeguard import check_argument_types, qualified_name

from grpc4bmi.bmi_grpc_client import BmiClient
from grpc4bmi.exceptions import DeadContainerException
Expand Down Expand Up @@ -50,11 +49,6 @@ def __init__(self, image: str, work_dir: str, image_port=50051, host=None,
input_dirs: Iterable[str] = tuple(),
user=os.getuid(), remove=False, delay=5,
timeout=None):
assert check_argument_types()
if type(input_dirs) == str:
msg = f'type of argument "input_dirs" must be collections.abc.Iterable; ' \
f'got {qualified_name(input_dirs)} instead'
raise TypeError(msg)
port = BmiClient.get_unique_port()
client = docker.from_env()
volumes = {}
Expand Down
8 changes: 1 addition & 7 deletions grpc4bmi/bmi_client_singularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from packaging.specifiers import SpecifierSet
from packaging.version import Version
from typeguard import check_argument_types, qualified_name

from grpc4bmi.bmi_grpc_client import BmiClient
from grpc4bmi.exceptions import ApptainerVersionException, DeadContainerException, SingularityVersionException
Expand All @@ -18,7 +17,7 @@

def check_singularity_version_string(version_output: str) -> bool:
(app, _, version) = version_output.split(' ')
local_version = Version(version)
local_version = Version(version.replace('.el', ''))
if app == 'singularity' and local_version not in SpecifierSet(SUPPORTED_SINGULARITY_VERSIONS):
raise SingularityVersionException(f'Unsupported version ({version_output}) of singularity found, '
f'supported versions {SUPPORTED_SINGULARITY_VERSIONS}')
Expand Down Expand Up @@ -200,11 +199,6 @@ class BmiClientSingularity(BmiClient):
def __init__(self, image: str, work_dir: str, input_dirs: Iterable[str] = tuple(), delay=0, timeout=None,
capture_logs=True,
):
assert check_argument_types()
if type(input_dirs) == str:
msg = f'type of argument "input_dirs" must be collections.abc.Iterable; ' \
f'got {qualified_name(input_dirs)} instead'
raise TypeError(msg)
check_singularity_version()
host = 'localhost'
port = BmiClient.get_unique_port(host)
Expand Down
2 changes: 0 additions & 2 deletions grpc4bmi/bmi_grpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import basic_modeling_interface.bmi as bmi
import grpc
import numpy
from typeguard import check_argument_types

from . import bmi_pb2, bmi_pb2_grpc
from .constants import GRPC_MAX_MESSAGE_LENGTH
Expand Down Expand Up @@ -57,7 +56,6 @@ def get_unique_port(host=None):
return int(s.getsockname()[1])

def initialize(self, filename: Optional[str]):
assert check_argument_types()
fname = "" if filename is None else filename
self.stub.initialize(bmi_pb2.InitializeRequest(config_file=fname))

Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def read(fname):


setup(name="grpc4bmi",
version="0.2.16",
version="0.2.17",
author="Gijs van den Oord",
author_email="[email protected]",
description="Run your BMI implementation in a separate process and expose it as BMI-python with GRPC",
Expand All @@ -33,7 +33,6 @@ def read(fname):
"docker",
"basic-modeling-interface",
"packaging",
"typeguard",
],
extras_require={
'R': ['rpy2'],
Expand Down
15 changes: 2 additions & 13 deletions test/test_apptainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Test_check_apptainer_version_string:
('apptainer version 1.0.3'),
('apptainer version 1.1.0-rc.3'),
('apptainer version 1.1.2'),
# From snellius cluster at SURF.
('apptainer version 1.1.5-2.el8'),
])
def test_ok(self, test_input: str):
result = check_apptainer_version_string(test_input)
Expand Down Expand Up @@ -63,19 +65,6 @@ def test_same_inputdir_and_workdir(self, tmp_path):
with pytest.raises(ValueError, match=match):
BmiClientApptainer(image=IMAGE_NAME, input_dirs=(some_dir,), work_dir=some_dir)

def test_workdir_as_number(self):
with pytest.raises(TypeError, match='must be str'):
BmiClientApptainer(image=IMAGE_NAME, work_dir=42)

def test_inputdirs_as_str(self, tmp_path):
some_dir = str(tmp_path)
with pytest.raises(TypeError, match='must be collections.abc.Iterable; got str instead'):
BmiClientApptainer(image=IMAGE_NAME, input_dirs='old type', work_dir=some_dir)

def test_inputdirs_as_number(self, tmp_path):
some_dir = str(tmp_path)
with pytest.raises(TypeError, match='must be collections.abc.Iterable; got int instead'):
BmiClientApptainer(image=IMAGE_NAME, input_dirs=42, work_dir=some_dir)



Expand Down
9 changes: 0 additions & 9 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,6 @@ def test_initialize():
del client


def test_initialize_with_nonstring():
client, local = make_bmi_classes(False)
assert client is not None
with pytest.raises(TypeError, match='got int instead'):
client.initialize(42)
client.finalize()
del client


def test_update():
client, local = make_bmi_classes(True)
client.update()
Expand Down
14 changes: 0 additions & 14 deletions test/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,6 @@ def test_same_inputdir_and_workdir(self, tmp_path):
with pytest.raises(ValueError, match=match):
BmiClientDocker(image=walrus_docker_image, image_port=55555, input_dirs=(some_dir,), work_dir=some_dir)

def test_workdir_as_number(self):
with pytest.raises(TypeError, match='must be str'):
BmiClientDocker(image=walrus_docker_image, work_dir=42)

def test_inputdirs_as_str(self, tmp_path):
some_dir = str(tmp_path)
with pytest.raises(TypeError, match='must be collections.abc.Iterable; got str instead'):
BmiClientDocker(image=walrus_docker_image, input_dirs='old type', work_dir=some_dir)

def test_inputdirs_as_number(self, tmp_path):
some_dir = str(tmp_path)
with pytest.raises(TypeError, match='must be collections.abc.Iterable; got int instead'):
BmiClientDocker(image=walrus_docker_image, input_dirs=42, work_dir=some_dir)

def test_logs(self, walrus_model, capfd):
logs = walrus_model.logs()

Expand Down
16 changes: 2 additions & 14 deletions test/test_singularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,6 @@ def test_with_config_inside_image(self, walrus_model_with_config_inside_image):
# After initialization and update the forcings have been read from the scratch dir
assert len(model.get_value('Q')) == 1

def test_workdir_as_number(self):
with pytest.raises(TypeError, match='must be str'):
BmiClientSingularity(image=IMAGE_NAME, work_dir=42)

def test_inputdirs_as_str(self, tmp_path):
some_dir = str(tmp_path)
with pytest.raises(TypeError, match='must be collections.abc.Iterable; got str instead'):
BmiClientSingularity(image=IMAGE_NAME, input_dirs='old type', work_dir=some_dir)

def test_inputdirs_as_number(self, tmp_path):
some_dir = str(tmp_path)
with pytest.raises(TypeError, match='must be collections.abc.Iterable; got int instead'):
BmiClientSingularity(image=IMAGE_NAME, input_dirs=42, work_dir=some_dir)


class TestRedirectOutput:
EXPECTED = 'Hello from Docker!'
Expand Down Expand Up @@ -230,6 +216,8 @@ class Test_check_singularity_version_string:
('apptainer version 1.0.3'),
('apptainer version 1.1.0-rc.3'),
('apptainer version 1.1.2'),
# From snellius cluster at SURF.
('apptainer version 1.1.5-2.el8'),
])
def test_ok(self, test_input: str):
result = check_singularity_version_string(test_input)
Expand Down