Skip to content

Commit 5f39835

Browse files
Guillaume De Saint MartinGuillaumeDSM
authored andcommitted
[Packaging] install tentacles in user-appdirs
1 parent a665e91 commit 5f39835

6 files changed

Lines changed: 717 additions & 14 deletions

File tree

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

octobot_pro/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1+
PROJECT_NAME = "OctoBot-Pro"
2+
AUTHOR = "Drakkar-Software"
3+
VERSION = "0.0.1" # major.minor.revision
4+
5+
16
def _use_module_local_tentacles():
27
import sys
38
import os
9+
import appdirs
410
if os.getenv("USE_CUSTOM_TENTACLES", "").lower() == "true":
511
# do not use octobot_pro/imports tentacles
612
# WARNING: in this case, all the required tentacles imports still have to work
713
# and therefore be bound to another tentacles folder
814
return
9-
# import tentacles from octobot_pro/imports directory
10-
internal_import_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "imports")
15+
# import tentacles from user-appdirs/imports directory
16+
dirs = appdirs.AppDirs(PROJECT_NAME, AUTHOR, VERSION)
17+
internal_import_path = os.path.join(dirs.user_data_dir, "imports")
1118
sys.path.insert(0, internal_import_path)
1219

1320

@@ -33,6 +40,3 @@ def _use_module_local_tentacles():
3340
from octobot_pro.constants import *
3441
from octobot_pro.api import *
3542
from octobot_pro.model import *
36-
37-
PROJECT_NAME = "OctoBot-Pro"
38-
VERSION = "0.0.1" # major.minor.revision

octobot_pro/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import octobot_tentacles_manager.api as api
2626

2727

28-
async def _install_all_tentacles(quite_mode) -> int:
28+
async def install_all_tentacles(quite_mode) -> int:
2929
octobot_pro_logging.enable_base_logger()
3030
error_count = 0
3131
logger = commons_logging.get_logger(f"{op.PROJECT_NAME}-CLI")
32-
install_path = octobot_mocks.get_module_install_path()
32+
install_path = octobot_mocks.get_module_appdir_path()
3333
tentacles_path = octobot_mocks.get_tentacles_path()
3434
tentacles_urls = octobot_mocks.get_public_tentacles_urls()
3535
async with aiohttp.ClientSession() as aiohttp_session:
@@ -52,7 +52,7 @@ def handle_octobot_pro_command(starting_args) -> int:
5252
print(f"{op.PROJECT_NAME} version {op.VERSION}")
5353
return 0
5454
if starting_args.install_tentacles:
55-
return asyncio.run(_install_all_tentacles(starting_args.quite))
55+
return asyncio.run(install_all_tentacles(starting_args.quite))
5656
print(f"No provided command. See --help to get more details on how to use {op.PROJECT_NAME}-CLI", file=sys.stderr)
5757
return -1
5858

octobot_pro/internal/octobot_mocks.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
22
import json
3+
import appdirs
34

5+
import octobot_pro
46
import octobot_pro.constants as constants
57
import octobot_tentacles_manager.api as octobot_tentacles_manager_api
68
import octobot_tentacles_manager.constants as octobot_tentacles_manager_constants
@@ -26,19 +28,24 @@ def get_module_config_path(file_name):
2628
return os.path.join(get_module_install_path(), constants.CONFIG_PATH, file_name)
2729

2830

29-
def get_internal_import_path():
30-
return os.path.join(get_module_install_path(), constants.ADDITIONAL_IMPORT_PATH)
31+
def get_module_appdir_path():
32+
dirs = appdirs.AppDirs(octobot_pro.PROJECT_NAME, octobot_pro.AUTHOR, octobot_pro.VERSION)
33+
return dirs.user_data_dir
3134

3235

33-
def get_imported_tentacles_path():
34-
import tentacles
35-
return os.path.dirname(os.path.abspath(tentacles.__file__))
36+
def get_internal_import_path():
37+
return os.path.join(get_module_appdir_path(), constants.ADDITIONAL_IMPORT_PATH)
3638

3739

3840
def get_tentacles_path():
3941
return os.path.join(get_internal_import_path(), octobot_tentacles_manager_constants.TENTACLES_PATH)
4042

4143

44+
def get_imported_tentacles_path():
45+
import tentacles
46+
return os.path.dirname(os.path.abspath(tentacles.__file__))
47+
48+
4249
def get_public_tentacles_urls():
4350
return [
4451
octobot_configuration_manager.get_default_tentacles_url()

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# Drakkar-Software requirements
22
OctoBot==0.4.27
3+
4+
# manage tentacles install path
5+
appdirs==1.4.4

setup.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
1+
import asyncio
2+
13
from setuptools import find_packages
24
from setuptools import setup
5+
from distutils.command.install import install
6+
37

48
# from octobot_pro import PROJECT_NAME, VERSION
59
# todo figure out how not to import octobot_pro.__init__.py here
610
PROJECT_NAME = "OctoBot-Pro"
711
VERSION = "0.0.1" # major.minor.revision
812

913

14+
def _post_install():
15+
import octobot_pro.cli
16+
asyncio.run(octobot_pro.cli.install_all_tentacles(True))
17+
18+
19+
class InstallWithPostInstallAction(install):
20+
def run(self):
21+
install.run(self)
22+
self.execute(_post_install, (), msg="Installing OctoBot-Pro tentacles")
23+
24+
1025
PACKAGES = find_packages(
1126
exclude=[
1227
"tests",
@@ -31,7 +46,7 @@
3146
author_email='drakkar-software@protonmail.com',
3247
description='Backtesting framework of the OctoBot Ecosystem',
3348
packages=PACKAGES,
34-
include_package_data=True,
49+
cmdclass={'install': InstallWithPostInstallAction},
3550
long_description=DESCRIPTION,
3651
long_description_content_type='text/markdown',
3752
tests_require=["pytest"],

0 commit comments

Comments
 (0)