Skip to content

Commit

Permalink
REF: Factor out getting local octue version
Browse files Browse the repository at this point in the history
skipci
  • Loading branch information
cortadocodes committed Feb 11, 2025
1 parent 9a86bce commit 0a49780
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 31 deletions.
4 changes: 0 additions & 4 deletions octue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@
from .log_handlers import apply_log_handler, should_use_octue_log_handler
from .runner import Runner


logger = logging.getLogger(__name__)


__all__ = ("Runner",)


REPOSITORY_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))


if should_use_octue_log_handler():
apply_log_handler(
logger_name=None, # Apply to the root logger.
Expand Down
6 changes: 2 additions & 4 deletions octue/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import copy
import functools
import importlib.metadata
import importlib.util
import json
import logging
import os
Expand All @@ -20,7 +18,7 @@
from octue.cloud.service_id import create_sruid, get_sruid_parts
from octue.cloud.storage import GoogleCloudStorageClient
from octue.configuration import ServiceConfiguration, load_service_and_app_configuration
from octue.definitions import MANIFEST_FILENAME, VALUES_FILENAME
from octue.definitions import LOCAL_SDK_VERSION, MANIFEST_FILENAME, VALUES_FILENAME
from octue.exceptions import ServiceAlreadyExists
from octue.log_handlers import apply_log_handler, get_remote_handler
from octue.resources import Child, Manifest, service_backends
Expand Down Expand Up @@ -56,7 +54,7 @@
show_default=True,
help="Forces a reset of analysis cache and outputs [For future use, currently not implemented]",
)
@click.version_option(version=importlib.metadata.version("octue"))
@click.version_option(version=LOCAL_SDK_VERSION)
def octue_cli(id, logger_uri, log_level, force_reset):
"""The CLI for the Octue SDK. Use it to start an Octue data service or digital twin locally or run an analysis on
one locally.
Expand Down
8 changes: 1 addition & 7 deletions octue/cloud/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import importlib.metadata

import octue.exceptions
import twined.exceptions
from octue.utils.exceptions import create_exceptions_mapping


LOCAL_SDK_VERSION = importlib.metadata.version("octue")

import twined.exceptions

EXCEPTIONS_MAPPING = create_exceptions_mapping(
globals()["__builtins__"],
Expand Down
4 changes: 2 additions & 2 deletions octue/cloud/emulators/_pub_sub.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from collections import defaultdict
import importlib.metadata
import json
import logging

import google.api_core

from octue.cloud.pub_sub import Subscription, Topic
from octue.cloud.pub_sub.service import PARENT_SENDER_TYPE, Service
from octue.definitions import LOCAL_SDK_VERSION
from octue.resources import Manifest
from octue.utils.dictionaries import make_minimal_dictionary
from octue.utils.encoders import OctueJSONEncoder
Expand Down Expand Up @@ -341,7 +341,7 @@ def ask(
memory=None,
ephemeral_storage=None,
timeout=86400,
parent_sdk_version=importlib.metadata.version("octue"),
parent_sdk_version=LOCAL_SDK_VERSION,
):
"""Put the question into the messages register, register the existence of the corresponding response topic, add
the response to the register, and return a MockFuture containing the answer subscription path.
Expand Down
11 changes: 3 additions & 8 deletions octue/cloud/events/handler.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import abc
import importlib.metadata
from datetime import datetime
import logging
import os
import re
import time
from datetime import datetime

from octue.cloud import EXCEPTIONS_MAPPING
from octue.cloud.events.validation import SERVICE_COMMUNICATION_SCHEMA, is_event_valid
from octue.definitions import GOOGLE_COMPUTE_PROVIDERS
from octue.definitions import GOOGLE_COMPUTE_PROVIDERS, LOCAL_SDK_VERSION
from octue.log_handlers import COLOUR_PALETTE
from octue.resources.manifest import Manifest


logger = logging.getLogger(__name__)


Expand All @@ -23,9 +21,6 @@
from octue.utils.colour import colourise


PARENT_SDK_VERSION = importlib.metadata.version("octue")


class AbstractEventHandler:
"""An abstract event handler for Octue service events that:
- Provide handlers for the Octue service event kinds (see https://strands.octue.com/octue/service-communication)
Expand Down Expand Up @@ -123,7 +118,7 @@ def _extract_and_validate_event(self, container):
event=event,
attributes=attributes,
recipient=recipient,
parent_sdk_version=PARENT_SDK_VERSION,
parent_sdk_version=LOCAL_SDK_VERSION,
child_sdk_version=child_sdk_version,
schema=self.schema,
):
Expand Down
2 changes: 1 addition & 1 deletion octue/cloud/events/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
import uuid

from octue.cloud import LOCAL_SDK_VERSION
from octue.definitions import LOCAL_SDK_VERSION
from octue.utils.dictionaries import make_minimal_dictionary


Expand Down
5 changes: 2 additions & 3 deletions octue/cloud/pub_sub/service.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import concurrent.futures
import copy
import functools
import importlib.metadata
import json
import logging
import uuid
Expand All @@ -11,7 +10,6 @@
from google.cloud import pubsub_v1
import jsonschema

from octue.cloud import LOCAL_SDK_VERSION
from octue.cloud.events import OCTUE_SERVICES_TOPIC_NAME
from octue.cloud.events.extraction import extract_and_convert_attributes
from octue.cloud.events.utils import make_attributes
Expand All @@ -29,6 +27,7 @@
validate_sruid,
)
from octue.compatibility import warn_if_incompatible
from octue.definitions import LOCAL_SDK_VERSION
import octue.exceptions
from octue.utils.dictionaries import make_minimal_dictionary
from octue.utils.encoders import OctueJSONEncoder
Expand Down Expand Up @@ -806,7 +805,7 @@ def _parse_question(self, question):
recipient=self.id,
# Don't assume the presence of specific attributes before validation.
parent_sdk_version=attributes.get("sender_sdk_version"),
child_sdk_version=importlib.metadata.version("octue"),
child_sdk_version=LOCAL_SDK_VERSION,
)

logger.info("%r parsed question %r successfully.", self, attributes["question_uuid"])
Expand Down
3 changes: 3 additions & 0 deletions octue/definitions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import importlib.metadata

VALUES_FILENAME = "values.json"
MANIFEST_FILENAME = "manifest.json"

Expand All @@ -17,3 +19,4 @@
RUN_STRANDS = ("input_values", "input_manifest", "credentials", "children")

GOOGLE_COMPUTE_PROVIDERS = {"GOOGLE_CLOUD_FUNCTION", "GOOGLE_KUEUE"}
LOCAL_SDK_VERSION = importlib.metadata.version("octue")
4 changes: 2 additions & 2 deletions octue/mixins/metadata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import importlib.metadata
from abc import abstractmethod

from octue.definitions import LOCAL_SDK_VERSION
from octue.mixins.hashable import Hashable


Expand Down Expand Up @@ -36,7 +36,7 @@ def metadata(self, include_id=True, include_sdk_version=True, **kwargs):
metadata = {name: getattr(self, name) for name in self._METADATA_ATTRIBUTES}

if include_sdk_version:
metadata["sdk_version"] = importlib.metadata.version("octue")
metadata["sdk_version"] = LOCAL_SDK_VERSION

if not include_id and "id" in metadata:
del metadata["id"]
Expand Down

0 comments on commit 0a49780

Please sign in to comment.