Skip to content

Commit

Permalink
Merge pull request #6 from Aquaveo/masterAquaveo
Browse files Browse the repository at this point in the history
changes to allow multiple organization with different labels, etc
  • Loading branch information
romer8 authored Dec 15, 2023
2 parents 4ce23f6 + 13fd0dc commit bca0c16
Show file tree
Hide file tree
Showing 47 changed files with 4,180 additions and 344 deletions.
Binary file added .coverage
Binary file not shown.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
python-version: '3.x'
- name: Install dependencies
run: python -m pip install --upgrade pyyaml
- name: Gen Build Command
run: |
python ./conda.recipes/getChannels.py > build_command.txt
- name: publish-to-conda
uses: rfun/conda-package-publish-action@master
uses: romer8/conda-package-publish-action@master
with:
subDir: "conda.recipes"
subDir: 'conda.recipes'
AnacondaToken: ${{ secrets.ANACONDA_TOKEN }}
Binary file added tethysapp/.coverage
Binary file not shown.
12 changes: 11 additions & 1 deletion tethysapp/app_store/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from tethys_sdk.base import TethysAppBase
from tethys_sdk.app_settings import CustomSetting
from tethys_sdk.app_settings import CustomSetting,JSONCustomSetting,SecretCustomSetting
from tethys_sdk.permissions import Permission, PermissionGroup


Expand Down Expand Up @@ -48,4 +48,14 @@ def custom_settings(self):
description='Sudo password for server',
required=False
),
JSONCustomSetting(
name='stores_settings',
description='Json Containing the different credentials for Github and Anaconda',
required=False
),
SecretCustomSetting(
name='encryption_key',
description='encryption_key for github token in the json',
required=False
),
)
4 changes: 2 additions & 2 deletions tethysapp/app_store/application_files/getChannels.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
channels.insert(0, "conda-forge")
for channel in channels:
channelString = channelString + " -c " + channel
buildCommand = "conda build" + channelString + " --output-folder . ."
buildCommand = "conda mambabuild" + channelString + " --output-folder . ."
print(buildCommand)
except Exception:
# print(e)
print("conda build -c conda-forge --output-folder . .")
print("conda mambabuild -c conda-forge --output-folder . .")
2 changes: 1 addition & 1 deletion tethysapp/app_store/application_files/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: |
python ./conda.recipes/getChannels.py > build_command.txt
- name: publish-to-conda
uses: tethysapp/conda-package-publish-action@master
uses: romer8/conda-package-publish-action@master
with:
subDir: 'conda.recipes'
AnacondaToken: ${{ secrets.ANACONDA_TOKEN }}
2 changes: 1 addition & 1 deletion tethysapp/app_store/application_files/main_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: |
python ./conda.recipes/getChannels.py > build_command.txt
- name: publish-to-conda
uses: tethysapp/conda-package-publish-action@master
uses: romer8/conda-package-publish-action@master
with:
subDir: 'conda.recipes'
AnacondaToken: $${{ secrets.ANACONDA_TOKEN }}
Expand Down
31 changes: 31 additions & 0 deletions tethysapp/app_store/application_files/setup_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from setuptools import setup, find_namespace_packages
from setup_helper import find_all_resource_files

# -- Apps Definition -- #
namespace = 'tethysapp'
app_package = "replace_app_package"
release_package = "tethysapp-" + app_package

# -- Python Dependencies -- #
dependencies = []

# -- Get Resource File -- #
resource_files = find_all_resource_files(app_package, namespace)


setup(
name=release_package,
version="replace_version",
description="replace_description",
long_description="replace_description",
keywords="replace_keywords",
author="replace_author",
author_email="replace_author_email",
url="replace_url",
license="replace_license",
packages=find_namespace_packages(),
package_data={"": resource_files},
include_package_data=True,
zip_safe=False,
install_requires=dependencies,
)
1 change: 1 addition & 0 deletions tethysapp/app_store/application_files/upload_command.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
anaconda upload --force --label $label_string noarch/*.tar.bz2
38 changes: 27 additions & 11 deletions tethysapp/app_store/begin_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from subprocess import call

from .helpers import check_all_present, get_app_instance_from_path, logger, send_notification
from .resource_helpers import get_resource
from .resource_helpers import get_resource, get_resource_new


def handle_property_not_present(prop):
Expand All @@ -24,7 +24,7 @@ def process_post_install_scripts(path):
# Currently only processing the pip install script, but need to add ability to process post scripts as well


def detect_app_dependencies(app_name, app_version, channel_layer, notification_method=send_notification):
def detect_app_dependencies(app_name, channel_layer, notification_method=send_notification):
"""
Method goes through the app.py and determines the following:
1.) Any services required
Expand All @@ -38,20 +38,25 @@ def detect_app_dependencies(app_name, app_version, channel_layer, notification_m
# Best method is to import the module and try and get the location from that path
# @TODO : Ensure that this works through multiple runs
import tethysapp
# store_pkg = importlib.import_module(app_channel)

call(['tethys', 'db', 'sync'])
cache.clear()
# clear_url_caches()
# After install we need to update the sys.path variable so we can see the new apps that are installed.
# We need to do a reload here of the sys.path and then reload the the tethysapp
# We need to do a reload here of the sys.path and then reload the tethysapp
# https://stackoverflow.com/questions/25384922/how-to-refresh-sys-path
import site
importlib.reload(site)
importlib.reload(tethysapp)
# importlib.reload(store_pkg)

# paths = list()
# paths = list(filter(lambda x: app_name in x, store_pkg.__path__))
# breakpoint()
paths = list(filter(lambda x: app_name in x, tethysapp.__path__))


if len(paths) < 1:
logger.error("Can't find the installed app location.")
return
Expand Down Expand Up @@ -105,22 +110,29 @@ def detect_app_dependencies(app_name, app_version, channel_layer, notification_m
return


def conda_install(app_metadata, app_version, channel_layer):
def conda_install(app_metadata, app_channel,app_label,app_version, channel_layer):

start_time = time.time()
send_notification("Mamba install may take a couple minutes to complete depending on how complicated the "
"environment is. Please wait....", channel_layer)

latest_version = app_metadata['metadata']['versions'][-1]
latest_version = app_metadata['latestVersion'][app_channel][app_label]
if not app_version:
app_version = latest_version

# Running the conda install as a subprocess to get more visibility into the running process
dir_path = os.path.dirname(os.path.realpath(__file__))
# breakpoint()
script_path = os.path.join(dir_path, "scripts", "conda_install.sh")

app_name = app_metadata['name'] + "=" + app_version
install_command = [script_path, app_name, app_metadata['metadata']['channel']]

label_channel = f'{app_channel}'

if app_label != 'main':
label_channel = f'{app_channel}/label/{app_label}'

install_command = [script_path, app_name, label_channel]

# Running this sub process, in case the library isn't installed, triggers a restart.

Expand Down Expand Up @@ -149,29 +161,33 @@ def conda_install(app_metadata, app_version, channel_layer):
send_notification("Mamba install found conflicts."
"Please try running the following command in your terminal's"
"conda environment to attempt a manual installation : "
"mamba install -c " + app_metadata['metadata']['channel'] + " " + app_name,
"mamba install -c " + label_channel + " " + app_name,
channel_layer)

send_notification("Mamba install completed in %.2f seconds." % (time.time() - start_time), channel_layer)


def begin_install(installData, channel_layer, app_workspace):

resource = get_resource(installData["name"], app_workspace)
# resource = get_resource(installData["name"], app_workspace)
# breakpoint()

send_notification("Starting installation of app: " + resource['name'], channel_layer)
resource = get_resource_new(installData["name"],installData['channel'],installData['label'], app_workspace)

send_notification("Starting installation of app: " + resource['name'] + " from store "+ installData['channel'] + " with label "+ installData['label'] , channel_layer)
send_notification("Installing Version: " + installData["version"], channel_layer)


try:
conda_install(resource, installData["version"], channel_layer)
conda_install(resource,installData['channel'],installData['label'], installData["version"], channel_layer)
except Exception as e:
logger.error("Error while running conda install")
logger.error(e)
send_notification("Error while Installing Conda package. Please check logs for details", channel_layer)
return

try:
detect_app_dependencies(resource['name'], installData["version"], channel_layer)
detect_app_dependencies(resource['name'], channel_layer)
except Exception as e:
logger.error(e)
send_notification("Error while checking package for services", channel_layer)
Expand Down
Loading

0 comments on commit bca0c16

Please sign in to comment.