From fdd80ad956f765824fcd45e89a9241f3b981b3cf Mon Sep 17 00:00:00 2001 From: Wim Pomp Date: Wed, 26 Mar 2025 16:24:45 +0100 Subject: [PATCH] virtual environments --- README.md | 17 +++++++++++++---- matlab.service | 2 +- matlabhub/app.py | 11 +++++++---- pyproject.toml | 32 ++++++++++++++++++++++++++++++++ setup.py | 26 -------------------------- 5 files changed, 53 insertions(+), 35 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/README.md b/README.md index c884f9b..a22b675 100644 --- a/README.md +++ b/README.md @@ -2,21 +2,30 @@ Start proxied matlab instances from a webpage using Nginx. -## Preequisites +## Prerequisites Linux with Matlab and Python3 ## Installation -make matlabhub/config.py: +edit matlabhub/config.py: license_file: 'path_to_license.lic' port_range: [10000, 65536] + matlab-proxy-app: '/opt/matlabhub/venv/bin/matlab-proxy-app' # path to matlab-proxy-app in venv + +edit ExecStart to point to gunicorn in python venv in matlab.service: + + ExecStart=/opt/matlabhub/venv/bin/gunicorn --bind unix:/tmp/matlabhub.sock matlabhub.app:app install: - sudo apt install nginx screen - sudo pip install matlabhub + sudo apt install nginx screen xvfb + curl -LsSf https://astral.sh/uv/install.sh | sh + . .bashrc + uv venv venv --python 3.11 + . venv/bin/activate + pip install matlabhub sudo cp matlab /etc/nginx/sites-available/ sudo ln -s /etc/nginx/sites-available/matlab /etc/nginx/sites-enabled/matlab sudo cp matlab.service /lib/systemd/system/ diff --git a/matlab.service b/matlab.service index 5889671..ecf4943 100644 --- a/matlab.service +++ b/matlab.service @@ -6,7 +6,7 @@ Wants=network-online.target [Service] User=matlab-user Type=simple -ExecStart=/usr/local/bin/gunicorn --bind unix:/tmp/matlabhub.sock matlabhub.app:app +ExecStart=/opt/matlabhub/venv/bin/gunicorn --bind unix:/tmp/matlabhub.sock matlabhub.app:app ExecStop=/bin/kill -s STOP $MAINPID ExecReload=/bin/kill -s HUP $MAINPID TimeoutSec=0 diff --git a/matlabhub/app.py b/matlabhub/app.py index 993196e..780411a 100644 --- a/matlabhub/app.py +++ b/matlabhub/app.py @@ -1,12 +1,13 @@ import os -import sys +import random import re import socket import subprocess -import random +import sys +from time import sleep + import yaml from flask import Flask, redirect, render_template, request -from time import sleep with open(os.path.join(os.path.dirname(__file__), 'config.yml')) as conf_file: config = yaml.safe_load(conf_file) @@ -25,7 +26,9 @@ class Matlab: def start(self): command = f'screen -S {self.screen_name} -d -m env MWI_BASE_URL="/{self.port}" ' \ - f'MWI_APP_PORT={self.port} MLM_LICENSE_FILE={config["license_file"]} matlab-proxy-app' + f'MWI_APP_PORT={self.port} MLM_LICENSE_FILE={config["license_file"]} ' \ + 'MWI_ENABLE_TOKEN_AUTH="False" ' \ + f'{config["matlab-proxy-app"]}' subprocess.Popen(command, shell=True, start_new_session=True) def stop(self): diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..9829c6a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,32 @@ +[project] +name = "matlabhub" +version = "2025.3.0" +description = "matlabhub" +authors = [ + { name = "W. Pomp", email = "w.pomp@nki.nl" } +] +license = { text = "GPL-3.0-or-later"} +readme = "README.md" +keywords = ["matlab", "hub", "proxy-app"] +include = ["templates/*", "config.yml"] +requires-python = ">=3.8" + +dependencies = [ + "flask", + "gunicorn", + "matlab-proxy", + "pyyaml", +] + +[project.urls] +repository = "https://github.com/wimpomp/matlabhub" + +[project.scripts] +matlabhub = "matlabhub:main" + +[tool.isort] +line_length = 119 + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/setup.py b/setup.py deleted file mode 100644 index e9a67e6..0000000 --- a/setup.py +++ /dev/null @@ -1,26 +0,0 @@ -import setuptools - -with open('README.md', 'r') as fh: - long_description = fh.read() - -setuptools.setup( - name='matlabhub', - version='2022.7.0', - author='Wim Pomp @ Lenstra lab NKI', - author_email='w.pomp@nki.nl', - description='matlabhub', - long_description=long_description, - long_description_content_type='text/markdown', - url='https://github.com/wimpomp/matlabhub', - packages=['matlabhub'], - classifiers=[ - 'Programming Language :: Python :: 3', - 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', - 'Operating System :: OS Independent', - ], - python_requires='>=3.8', - install_requires=['matlab-proxy', 'flask', 'gunicorn', 'pyyaml'], - entry_points={'console_scripts': ['matlabhub=matlabhub:main'], }, - package_data={'': ['templates/*', 'config.yml']}, - include_package_data=True, -)