Skip to content

Commit

Permalink
Applied suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
christophertubbs authored Sep 29, 2023
1 parent 438e1fd commit 4255f1b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 45 deletions.
41 changes: 22 additions & 19 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
#!/usr/bin/env bash

deactivate;
deactivate &> /dev/null

ACTIVATE_FILE='venv/bin/activate';
ENV_DIRS=("venv" "env" ".env" ".venv", "dmod_venv", "dmod_env")
ACTIVATED=false

if [ -f "$ACTIVATE_FILE" ];
POSSIBLE_ENV_DIRS=("venv" "env" ".env" ".venv", "dmod_venv", "dmod_env")
ACTIVATED=false

for item in "${POSSIBLE_ENV_DIRS[@]}"
do
if [ -f "${item}/bin/activate" ]
then
echo
echo "Virtual Environment, ${item}, found. Attempting to activate it."
# exit if virtual env could not be activated
source "${item}/bin/activate" || { echo "Failed to activate Virtual Environment: ${item}" && exit 1; }
ACTIVATED=true
fi
done

# create virtual env if one did not exist previously
if [ "${ACTIVATED}" = false ]
then
echo
echo "Virtual Environment found. Attempting to activate it."
echo
. venv/bin/activate;
else
echo
echo "Virtual Environment not found. Attempting to create it"
echo
python -m venv venv
python3 -m venv venv
echo
echo "Activating Virtual Environment"
echo
. venv/bin/activate;
fi

ACTIVATED=$?;

if [ $ACTIVATED != 0 ]; then
echo
echo "Could not activate a python virtual environment" >&2;
echo
exit $ACTIVATED;
source venv/bin/activate || { echo "Failed to activate Virtual Environment: venv" && exit 1; }
fi

echo
Expand Down
15 changes: 10 additions & 5 deletions python/lib/core/dmod/core/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import abc
import typing
from collections import defaultdict
import functools

from collections import defaultdict
from typing_extensions import Self

from ..enum import PydanticEnum
Expand Down Expand Up @@ -206,7 +207,7 @@ def add(self, text: str, value: _T, *, group: str = None, index: int = None) ->
TextValue(text=text, value=value, group=group, index=index)
)

@typing.overload
@functools.singledispatch
def __getitem__(self, index: slice) -> TextValues[_T]:
new_values = self.__class__()

Expand All @@ -215,9 +216,13 @@ def __getitem__(self, index: slice) -> TextValues[_T]:

return new_values

def __getitem__(self, index: int) -> TextValue[_T]:
@__getitem__.register
def _(self, index: int) -> TextValue[_T]:
return self.__values[index]

def __contains__(self, other: TextValue) -> bool:
return other in self.__values

@property
def options(self) -> TEXT_VALUE_TUPLES:
formed_options: TEXT_VALUE_TUPLES = list()
Expand Down Expand Up @@ -281,15 +286,15 @@ def __len__(self) -> int:
return len(self.__values)

def __str__(self):
return str([value for value in self.__values])
return str([str(value) for value in self.__values])

def __repr__(self):
return str(self.options)


class CommonEnum(typing.Generic[_T], PydanticEnum):
"""
Base enum class allowing for advanced
Base enum class allowing for advanced access to values
"""

@classmethod
Expand Down
5 changes: 2 additions & 3 deletions python/lib/core/dmod/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def parse_dates(cls, v):
def drop_microseconds(cls, v: datetime):
return v.replace(microsecond=0)

@validator("dataset_type")
@validator("dataset_type", always=True)
def set_default_dataset_type(cls, value: Union[str, DatasetType] = None) -> DatasetType:
if value is None:
value = DatasetType.UNKNOWN
Expand Down Expand Up @@ -180,8 +180,7 @@ def __init__(self, manager: DatasetManager = None, **kwargs):
def manager(self) -> Optional[DatasetManager]:
return self._manager

@manager.setter
def manager(self, value: DatasetManager = None):
def set_manager(self, value: DatasetManager = None):
self._manager = value if isinstance(value, DatasetManager) else None

if value is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from .template import TemplateManager

def get_metric_identifiers() -> typing.Tuple:
def get_metric_identifiers() -> typing.Tuple[str, ...]:
identifiers = list()

for metric in metrics.get_all_metrics():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ class RequestTrackingMixin:
)


class SessionTrackingMixin:
session_id: typing.Union[str, int, None] = Field(
default=None,
description="An optional ID used to track session information"
)


class TokenMixin:
token: typing.Union[str, bytes, None] = Field(
default=None,
description="An optional token used to identify a caller's ability to interact with the server"
)


class BaseResponse(BaseModel, abc.ABC):
"""
Represents the response to a message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ class SpecificationTemplateManager(TemplateManager):
"""
Object manager used to provide details about available templates defined within the Django DB instance
"""
def __init__(self, *args, **kwargs):
pass

def get_specification_types(self) -> typing.Sequence[typing.Tuple[str, str]]:
types: typing.List[typing.Tuple[str, str]] = list()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ def create_basic_credentials(
password = password.decode()

username_and_password = f"{username}:{password}".encode()

# Django strips the `HTTP_` prefix and turns it into the correct header name
return {"HTTP_AUTHORIZATION": f"Basic {base64.b64encode(username_and_password).decode()}"}


Expand Down

0 comments on commit 4255f1b

Please sign in to comment.