Skip to content

Commit

Permalink
[Install] Fixed installation process (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
Failxxx authored Feb 11, 2023
2 parents 84a9618 + 75dde6f commit d664bc8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
3 changes: 2 additions & 1 deletion docs/source/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ voxel
Voxels
voxels
vdb
VDB
VDB
pyopenvdb
6 changes: 3 additions & 3 deletions docs/source/users/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ Installation

* ``CLASSIC``: this is the basic and recommended configuration.
* ``ADVANCED``: configuration which will let you install other dependencies to use under-development features.
* `Force` (option): install python pyckages with the ``--force-reinstall`` flag on.
* `Force` (option): install python packages with the ``--force-reinstall`` flag on.

* Then, click on the ``install`` button.
* Then, click on the ``install`` button. The Blender UI will freeze for a moment, this is normal. Python packages are being downloaded and installed.

.. image:: /images/installation/run_install_process.png
:width: 55%
Expand All @@ -39,7 +39,7 @@ Installation


Reinstall python dependencies
=============================
-----------------------------

.. note::
If you need to reinstall the python dependencies or switch configuration, follow these instructions.
Expand Down
10 changes: 9 additions & 1 deletion nimphs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
from bpy.types import Scene, Object, TOPBAR_MT_file_import, VIEW3D_MT_editor_menus, VIEW3D_HT_tool_header

import os
import sys
import site
import json
from pathlib import Path

# Add user default folders where pip will install some of the dependencies
# This is because some folders may not be writable
sys.path.append(os.path.abspath(site.USER_SITE))
sys.path.append(os.path.join(os.path.abspath(Path(site.USER_SITE).parent), "Scripts"))

from . import auto_load

LOAD_INSTALLER = None
Expand All @@ -18,7 +25,7 @@
"name": "NIMPHS",
"description": "Numerous Instruments to Manipulate and Post-process Hydraulic Simulations",
"author": "Félix Olart, Thibault Oudart",
"version": (0, 4, 2),
"version": (0, 4, 3),
"blender": (3, 0, 0),
"location": "File > Import",
"warning": "This version is still in development.",
Expand Down Expand Up @@ -127,6 +134,7 @@ def register() -> None: # noqa: D103
def unregister() -> None: # noqa: D103

if LOAD_INSTALLER:

for cls in reversed(classes):
bpy.utils.unregister_class(cls)

Expand Down
20 changes: 17 additions & 3 deletions nimphs/operators/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,27 @@ def execute(self, context: Context) -> set:

settings = context.preferences.addons['nimphs'].preferences.settings

# Make sure we have pip available
args = [sys.executable, "-m", "ensurepip"]
subprocess.check_call(args)

# Upgrade pip
args = [sys.executable, "-m", "pip", "install", "--upgrade", "pip", "--user"]
subprocess.check_call(args)

# Try to install 'ADVANCED' packages first
if settings.configuration == 'ADVANCED':

try:
self.install_package('numba', force=settings.reinstall)
self.install_package('multiprocessing', force=settings.reinstall)
except Exception as exception:
message = ("\n\n"
"An error occurred during installation with 'ADVANCED' configuration.\n")

log.error(message + str(exception))

self.report({'ERROR'}, "An error occurred during installation. See console logs.")

return {'CANCELLED'}

# Then, install packages for the 'CLASSIC' configuration
Expand All @@ -88,6 +97,8 @@ def execute(self, context: Context) -> set:

log.error(message + str(exception))

self.report({'ERROR'}, "An error occurred during installation. See console logs.")

return {'CANCELLED'}

# Replace value inside json file to indicate installation is complete
Expand All @@ -109,9 +120,11 @@ def install_package(self, package: str, force: bool = False) -> None:
package (str): name of the python package.
force (bool, optional): force reinstall. Defaults to False.
"""
args = [sys.executable, "-m", "pip", "install", package]

args = [sys.executable, "-m", "pip", "install", package, "--upgrade", "--user"]
if force:
args.append("--force-reinstall")

subprocess.check_call(args)

def install_requirements(self, requirements: str, force: bool = False) -> None:
Expand All @@ -123,7 +136,8 @@ def install_requirements(self, requirements: str, force: bool = False) -> None:
force (bool, optional): force reinstall. Defaults to False.
"""

args = [sys.executable, "-m", "pip", "install", "-r", requirements, "-U"]
args = [sys.executable, "-m", "pip", "install", "-r", requirements, "--upgrade", "--user"]
if force:
args.append("--force-reinstall")

subprocess.check_call(args)
1 change: 0 additions & 1 deletion nimphs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Requirements for the 'CLASSIC' configuration.

pip
pyvista >= 0.35.1
matplotlib

0 comments on commit d664bc8

Please sign in to comment.