diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dd79ca0..da6a552 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,6 +42,7 @@ jobs: - uses: codecov/codecov-action@v3 with: + token: ${{ secrets.CODECOV_TOKEN }} file: ./coverage.xml flags: unittests name: codecov-umbrella diff --git a/docs/img/ignore_bad_imports.png b/docs/img/ignore_bad_imports.png new file mode 100644 index 0000000..2ba1554 Binary files /dev/null and b/docs/img/ignore_bad_imports.png differ diff --git a/docs/img/venv_admin_page.png b/docs/img/venv_admin_page.png new file mode 100644 index 0000000..bba97ef Binary files /dev/null and b/docs/img/venv_admin_page.png differ diff --git a/docs/img/venv_change_form.png b/docs/img/venv_change_form.png new file mode 100644 index 0000000..5ad6e19 Binary files /dev/null and b/docs/img/venv_change_form.png differ diff --git a/docs/img/venv_set_script_venv.png b/docs/img/venv_set_script_venv.png new file mode 100644 index 0000000..cd551af Binary files /dev/null and b/docs/img/venv_set_script_venv.png differ diff --git a/docs/index.rst b/docs/index.rst index 0130574..76f7006 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -36,6 +36,7 @@ Getting Started configuration running_wooey scripts + venv_setup wooey_ui api api_keys diff --git a/docs/venv_setup.rst b/docs/venv_setup.rst new file mode 100644 index 0000000..5b96102 --- /dev/null +++ b/docs/venv_setup.rst @@ -0,0 +1,41 @@ +Virtual Environment Setup +========================= + +Virtual environments allow you to specify a python interpreter and a set of requirements to run a script in. + +Like with script addition, virtual environment setup is done via the Django admin. + +Adding a virtual environment +---------------------------- + +Virtual environments may be setup from the admin under the `Virtual Environments` section: + +.. image:: img/venv_admin_page.png + +To add a virtual environment, click the Add button and a form will be rendered for setting up a new virtual environment. + +.. image:: img/venv_change_form.png + +The fields are: + +* **name** What to call the virtual environment. Virtual environments can be reused across scripts if desired. + +* **python binary** The path to a python executable to create and use for running the virtual environment + +* **requirements** This is equivalent to the requirements.txt file for defining packages to install + +* **Venv directory** Where to store the virtual environment. The default location for this can be defined via the `WOOEY_VIRTUAL_ENVIRONMENT_DIRECTORY` setting. If not defined, this defaults to the system temporary directory folder. + +Lastly, to add the virtual environment to a script, from the script admin view, choose the virtual environment to run +the script in: + +.. image:: img/venv_set_script_venv.png + +Adding scripts with invalid imports +----------------------------------- + +Virtual environments are meant to have requirements that may not be present on the main Wooey server. Thus, some +scripts may fail to import because of dependency conflicts. To resolve this, a new option is available on scripts, +`ignore_bad_imports`, that may be set via the admin. + +.. image:: img/ignore_bad_imports.png diff --git a/wooey/tasks.py b/wooey/tasks.py index ac51fce..6dcb21b 100644 --- a/wooey/tasks.py +++ b/wooey/tasks.py @@ -11,6 +11,7 @@ from threading import Thread from django.utils.text import get_valid_filename from django.core.files import File from django.conf import settings +from django.utils.translation import gettext_lazy as _ from celery import app from celery.schedules import crontab @@ -143,6 +144,7 @@ def setup_venv(virtual_environment, job=None, stdout="", stderr=""): return_code = 0 if not os.path.exists(venv_path): + stdout += _("Setting up Virtual Environment\n########\n") venv_command = [ virtual_environment.python_binary, "-m", @@ -156,13 +158,22 @@ def setup_venv(virtual_environment, job=None, stdout="", stderr=""): ) if return_code: - raise Exception("VirtualEnv setup failed.\n{}\n{}".format(stdout, stderr)) + raise Exception( + _("VirtualEnv setup failed.\n{stdout}\n{stderr}").format( + stdout=stdout, stderr=stderr + ) + ) pip_setup = [venv_executable, "-m", "pip", "install", "-I", "pip"] + stdout += _("Installing Pip\n########\n") (stdout, stderr, return_code) = run_and_stream_command( pip_setup, cwd=None, job=job, stdout=stdout, stderr=stderr ) if return_code: - raise Exception("Pip setup failed.\n{}\n{}".format(stdout, stderr)) + raise Exception( + _("Pip setup failed.\n{stdout}\n{stderr}").format( + stdout=stdout, stderr=stderr + ) + ) requirements = virtual_environment.requirements if requirements: with tempfile.NamedTemporaryFile( @@ -177,12 +188,18 @@ def setup_venv(virtual_environment, job=None, stdout="", stderr=""): "-r", reqs_txt.name, ] + stdout += _("Installing Requirements\n########\n") (stdout, stderr, return_code) = run_and_stream_command( venv_command, cwd=None, job=job, stdout=stdout, stderr=stderr ) if return_code: - raise Exception("Requirements setup failed.\n{}\n{}".format(stdout, stderr)) + raise Exception( + _("Requirements setup failed.\n{stdout}\n{stderr}").format( + stdout=stdout, stderr=stderr + ) + ) os.remove(reqs_txt.name) + stdout += _("Virtual Environment Setup Complete\n########\n") return (venv_executable, stdout, stderr, return_code)