Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/koi-learning/koi-core into …
Browse files Browse the repository at this point in the history
…main
  • Loading branch information
hannesrichter committed Aug 3, 2022
2 parents 8f4f844 + bb4c65a commit 663dd55
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 11 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,16 @@
- fixed tests for role management
### 0.3.7
- added "last_modified" field to instances and models --> This needs koi_api version to be 0.3.3+!
### 0.3.8
- made koi_core compatible with Python3.6
- added tagged releases on github
### 0.3.9
- fixed the persistence functions
- using UUID as id for every object as hash() is salted for strings since Py3.3
## 0.4
- added `is_koi_reachable(base_url: str)`
- added `try_create_api_object_pool(...)`
### 0.4.1
- removed setup.py
- added pyproject.toml
- use of entrypoints instead of scripts
10 changes: 10 additions & 0 deletions koi_core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from koi_core.resources.pool import APIObjectPool, LocalOnlyObjectPool
from koi_core.exceptions import KoiInitializationError
import koi_core.control # noqa: F401
from koi_core.api import is_koi_reachable

_isInitialized = False

Expand Down Expand Up @@ -70,6 +71,15 @@ def create_local_object_pool():
return LocalOnlyObjectPool()


def try_create_api_object_pool(
host: str, username: str, password: str, persistance_file: Union[IOBase, str] = None
):
if is_koi_reachable(host):
return create_api_object_pool(host, username, password, persistance_file)
else:
return create_offline_object_pool(host, persistance_file)


def local_instance(path, parameter) -> Instance:
pool = create_local_object_pool()
model = pool.new_model()
Expand Down
18 changes: 11 additions & 7 deletions koi_core/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
# GNU Lesser General Public License is distributed along with this
# software and can be found at http://www.gnu.org/licenses/lgpl.html

from koi_core.api.common import BaseAPI, RequestsAPI
from .model import APIModels
from .instance import APIInstances
from .sample import APISamples
from .user import APIUsers
from .role import APIRoles
from .access import APIAccess
from koi_core.api.common import BaseAPI, RequestsAPI, is_reachable
from koi_core.api.model import APIModels
from koi_core.api.instance import APIInstances
from koi_core.api.sample import APISamples
from koi_core.api.user import APIUsers
from koi_core.api.role import APIRoles
from koi_core.api.access import APIAccess


def is_koi_reachable(host: str) -> bool:
return is_reachable(host)


class API(RequestsAPI):
Expand Down
8 changes: 8 additions & 0 deletions koi_core/api/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
T = TypeVar("T")


def is_reachable(base_url: str):
try:
ret = requests.get(base_url + "/health")
return ret.status_code == 200
except requests.exceptions.ConnectionError:
return False


class BearerAuth(requests.auth.AuthBase):
def __init__(self, token):
self.token = token
Expand Down
2 changes: 1 addition & 1 deletion koi_core/api/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from uuid import UUID
from typing import Iterable, Tuple

from .common import BaseAPI, _parse, _encode
from koi_core.api.common import BaseAPI, _parse, _encode
from koi_core.caching import CachingMeta
from koi_core.resources.ids import ModelId, InstanceId, DescriptorId

Expand Down
2 changes: 1 addition & 1 deletion koi_core/api/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from uuid import UUID
from typing import Tuple

from .common import BaseAPI, _parse, _encode
from koi_core.api.common import BaseAPI, _parse, _encode
from koi_core.caching import CachingMeta
from koi_core.resources.ids import ModelId

Expand Down
2 changes: 1 addition & 1 deletion koi_core/api/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from uuid import UUID
from typing import Tuple

from .common import BaseAPI, _parse, _encode
from koi_core.api.common import BaseAPI, _parse, _encode
from koi_core.caching import CachingMeta
from koi_core.resources.ids import InstanceId, SampleId, SampleDatumId, SampleLableId

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "koi-core"
version = "0.3.10"
version = "0.4.1"
description = "Runtime for the KOI-System including koi-worker"
readme = "README.md"
requires-python = ">=3.6"
Expand Down

0 comments on commit 663dd55

Please sign in to comment.