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

bump requirements, fix tests and add get tentacles dict #140

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions octobot_tentacles_manager/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
)
from octobot_tentacles_manager.api.inspector import (
get_installed_tentacles_modules,
get_installed_tentacles_modules_dict,
get_tentacle_group,
get_tentacle_version,
get_tentacle_origin_package,
Expand Down
20 changes: 20 additions & 0 deletions octobot_tentacles_manager/api/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,32 @@

import octobot_tentacles_manager.constants as constants
import octobot_tentacles_manager.loaders as loaders
import octobot_tentacles_manager.enums as manager_enums


def get_installed_tentacles_modules() -> set:
return set(tentacle for tentacle in loaders.get_tentacle_classes().values())


def get_installed_tentacles_modules_dict() -> dict:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will it be used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be used with the react ui to manage installed tentacles
meanwhile i moved it to the react ui

I also updated the pull request - I removed create folder if it doesnt exist as its already fixed in master

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't you use get_installed_tentacles_modules to do it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its returning as a set and tentacle_type is an object which doesnt work with json without changing it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not converting to json in client (caller) side?

return {_tentacle.name: {
manager_enums.InstalledTentaclesModule.NAME.value:_tentacle.name,
manager_enums.InstalledTentaclesModule.IN_DEV_MODE.value:_tentacle.in_dev_mode,
manager_enums.InstalledTentaclesModule.ARTIFACT_NAME.value:_tentacle.ARTIFACT_NAME,
manager_enums.InstalledTentaclesModule.METADATA.value:_tentacle.metadata,
manager_enums.InstalledTentaclesModule.ORIGIN_PACKAGE.value:_tentacle.origin_package,
manager_enums.InstalledTentaclesModule.ORIGIN_REPOSITORY.value:_tentacle.origin_repository,
manager_enums.InstalledTentaclesModule.TENTACLE_CLASS_NAMES.value:_tentacle.tentacle_class_names,
manager_enums.InstalledTentaclesModule.TENTACLE_GROUP.value:_tentacle.tentacle_group,
manager_enums.InstalledTentaclesModule.TENTACLE_MODULE_PATH.value:_tentacle.tentacle_module_path,
manager_enums.InstalledTentaclesModule.TENTACLE_PATH.value:_tentacle.tentacle_path,
manager_enums.InstalledTentaclesModule.TENTACLE_ROOT_PATH.value:_tentacle.tentacle_root_path,
manager_enums.InstalledTentaclesModule.TENTACLE_ROOT_TYPE.value:_tentacle.tentacle_root_type,
manager_enums.InstalledTentaclesModule.TENTACLES_REQUIREMENTS.value:_tentacle.tentacles_requirements,
manager_enums.InstalledTentaclesModule.VERSION.value:_tentacle.version
} for _tentacle in loaders.get_tentacle_classes().values()}


def get_tentacle_group(klass) -> str:
return loaders.get_tentacle(klass).tentacle_group

Expand Down
16 changes: 16 additions & 0 deletions octobot_tentacles_manager/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ class ArtifactTypes(enum.Enum):
class UploaderTypes(enum.Enum):
S3 = "s3"
NEXUS = "nexus"

class InstalledTentaclesModule(enum.Enum):
NAME = "name"
IN_DEV_MODE = "in_dev_mode"
ARTIFACT_NAME = "artifact_name"
METADATA = "metadata"
ORIGIN_PACKAGE = "origin_package"
ORIGIN_REPOSITORY = "origin_repository"
TENTACLE_CLASS_NAMES = "tentacle_class_names"
TENTACLE_GROUP = "tentacle_group"
TENTACLE_MODULE_PATH = "tentacle_module_path"
TENTACLE_PATH = "tentacle_path"
TENTACLE_ROOT_PATH = "tentacle_root_path"
TENTACLE_ROOT_TYPE = "tentacle_root_type"
TENTACLES_REQUIREMENTS = "tentacles_requirements"
VERSION = "version"
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ aiofiles>=0.6.0, <0.7
aiohttp>=3.8.1

# Templating requirements
jinja2>=3.0.3
jinja2>=3.1.2

# artifact metadata
pyyaml>=6.0
Expand Down
8 changes: 4 additions & 4 deletions tests/configuration/test_tentacle_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import octobot_tentacles_manager.util as util
import octobot_tentacles_manager.constants as constants
from octobot_tentacles_manager.loaders.tentacle_loading import reload_tentacle_by_tentacle_class
from tests.workers.octobot_version import get_installation_context_octobot_version

# All test coroutines will be treated as marked.
pytestmark = pytest.mark.asyncio
Expand Down Expand Up @@ -101,11 +102,10 @@ async def test_fill_tentacle_config():

setup_config = configuration.TentaclesSetupConfiguration()
setup_config.fill_tentacle_config(available_tentacle, constants.TENTACLE_CONFIG_FILE_NAME)
assert setup_config.installation_context == {
constants.TENTACLE_INSTALLATION_CONTEXT_OCTOBOT_VERSION:
constants.TENTACLE_INSTALLATION_CONTEXT_OCTOBOT_VERSION_UNKNOWN
}
assert setup_config.installation_context == get_installation_context_octobot_version()

setup_config.installation_context[constants.TENTACLE_INSTALLATION_CONTEXT_OCTOBOT_VERSION] \
= constants.TENTACLE_INSTALLATION_CONTEXT_OCTOBOT_VERSION_UNKNOWN
assert not api.are_tentacles_up_to_date(setup_config,
constants.TENTACLE_INSTALLATION_CONTEXT_OCTOBOT_VERSION_UNKNOWN)
assert not api.are_tentacles_up_to_date(setup_config, '1.0.0')
Expand Down
12 changes: 12 additions & 0 deletions tests/workers/octobot_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import octobot_tentacles_manager.configuration as configuration
import octobot_tentacles_manager.constants as constants
import octobot_tentacles_manager.util as util


def get_installation_context_octobot_version() -> dict:
setup_config = configuration.TentaclesSetupConfiguration()
available_tentacle = util.load_tentacle_with_metadata(constants.TENTACLES_PATH)
setup_config.fill_tentacle_config(
available_tentacle, constants.TENTACLE_CONFIG_FILE_NAME
)
return setup_config.installation_context
13 changes: 4 additions & 9 deletions tests/workers/test_install_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from octobot_tentacles_manager.models.tentacle import Tentacle
from octobot_tentacles_manager.util.tentacle_fetching import fetch_and_extract_tentacles
from tests import event_loop, clean, fake_profiles, TEMP_DIR, OTHER_PROFILE
from tests.workers.octobot_version import get_installation_context_octobot_version

# All test coroutines will be treated as marked.
pytestmark = pytest.mark.asyncio
Expand Down Expand Up @@ -56,9 +57,7 @@ async def test_install_two_tentacles(clean):
with open(USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH, "r") as config_f:
ref_profile_config = json.load(config_f)
assert ref_profile_config == {
'installation_context': {
'octobot_version': 'unknown'
},
'installation_context': get_installation_context_octobot_version(),
'registered_tentacles': {
'OctoBot-Default-Tentacles': tentacles_path
},
Expand Down Expand Up @@ -95,9 +94,7 @@ async def test_install_one_tentacle_with_requirement(clean):
# test tentacles config
with open(USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH, "r") as config_f:
assert json.load(config_f) == {
'installation_context': {
'octobot_version': 'unknown'
},
'installation_context': get_installation_context_octobot_version(),
'registered_tentacles': {
'OctoBot-Default-Tentacles': UNKNOWN_TENTACLES_PACKAGE_LOCATION
},
Expand Down Expand Up @@ -132,9 +129,7 @@ async def test_install_all_tentacles(clean):
# test tentacles config
with open(USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH, "r") as config_f:
assert json.load(config_f) == {
'installation_context': {
'octobot_version': 'unknown'
},
'installation_context': get_installation_context_octobot_version(),
'registered_tentacles': {
'OctoBot-Default-Tentacles': tentacles_path
},
Expand Down
10 changes: 3 additions & 7 deletions tests/workers/test_uninstall_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH, DEFAULT_BOT_PATH, TENTACLE_CONFIG, TENTACLES_EVALUATOR_PATH, \
TENTACLES_EVALUATOR_REALTIME_PATH
from octobot_tentacles_manager.workers.install_worker import InstallWorker

from tests.workers.octobot_version import get_installation_context_octobot_version
from octobot_tentacles_manager.models.tentacle import Tentacle
from octobot_tentacles_manager.workers.uninstall_worker import UninstallWorker
from octobot_tentacles_manager.util.tentacle_fetching import fetch_and_extract_tentacles
Expand Down Expand Up @@ -55,9 +55,7 @@ async def test_uninstall_two_tentacles(clean):
assert tentacles_files_count < 67
with open(USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH, "r") as config_f:
assert json.load(config_f) == {
'installation_context': {
'octobot_version': 'unknown'
},
'installation_context': get_installation_context_octobot_version(),
'registered_tentacles': {
'OctoBot-Default-Tentacles': tentacles_path
},
Expand Down Expand Up @@ -144,9 +142,7 @@ async def test_uninstall_all_tentacles(clean):
assert tentacles_files_count == CLEAN_TENTACLES_ARCHITECTURE_FILES_FOLDERS_COUNT
with open(USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH, "r") as config_f:
assert json.load(config_f) == {
'installation_context': {
'octobot_version': 'unknown'
},
'installation_context': get_installation_context_octobot_version(),
'registered_tentacles': {},
'tentacle_activation': {
'Backtesting': {},
Expand Down
6 changes: 2 additions & 4 deletions tests/workers/test_update_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import os
from os import walk, path

import octobot_commons.constants as commons_constants
from octobot_commons.logging.logging_util import set_logging_level
from octobot_tentacles_manager.constants import USER_REFERENCE_TENTACLE_SPECIFIC_CONFIG_PATH, \
USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH, TENTACLES_PATH, DEFAULT_BOT_PATH, UNKNOWN_TENTACLES_PACKAGE_LOCATION, \
Expand All @@ -31,6 +30,7 @@
from octobot_tentacles_manager.models.tentacle import Tentacle
from octobot_tentacles_manager.util.tentacle_fetching import fetch_and_extract_tentacles
from tests import event_loop, clean, TEMP_DIR, OTHER_PROFILE
from tests.workers.octobot_version import get_installation_context_octobot_version

# All test coroutines will be treated as marked.
pytestmark = pytest.mark.asyncio
Expand Down Expand Up @@ -65,9 +65,7 @@ async def test_update_two_tentacles(clean):
# test tentacles config
with open(USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH, "r") as config_f:
assert json.load(config_f) == {
'installation_context': {
'octobot_version': 'unknown'
},
'installation_context': get_installation_context_octobot_version(),
'registered_tentacles': {
'OctoBot-Default-Tentacles': UNKNOWN_TENTACLES_PACKAGE_LOCATION
},
Expand Down