From 5c76810b37500ccfaa57bd90d5e5797028282752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Sun, 6 Nov 2022 14:21:26 +0100 Subject: [PATCH 01/26] [Tests] Added utility classes to setup the environment --- .gitignore | 1 + quantum_nodes/__init__.py | 2 +- scripts/utils.py | 173 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 scripts/utils.py diff --git a/.gitignore b/.gitignore index a8bc5fe..da5046e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ animation_nodes/ # Cache **/__pycache__ +cache/ # Blender *.pyc diff --git a/quantum_nodes/__init__.py b/quantum_nodes/__init__.py index 37ec480..82f62d3 100644 --- a/quantum_nodes/__init__.py +++ b/quantum_nodes/__init__.py @@ -23,7 +23,7 @@ "author": "Quantum Creative Group", "version": (0, 1, 2), "blender": (2, 93, 0), - "location": "Animation Nodes Editor", + "location": "Animation Nodes", "description": "Animation Nodes extension which implements quantum computing tools.", "warning": "This version is still in development.", "doc_url": "https://quantum-creative-group.github.io/quantum_nodes/", diff --git a/scripts/utils.py b/scripts/utils.py new file mode 100644 index 0000000..55a4faa --- /dev/null +++ b/scripts/utils.py @@ -0,0 +1,173 @@ +""" +Utility functions and classes to setup the unit testing environment. +""" +import os +import sys +import shutil +import fnmatch +import zipfile +import requests +import argparse +import subprocess + + +class TerminalDisplay: + """Usefull tools to better the messages displayed in the terminal.""" + + # List of colors which can be used to color texts in the terminal. + LIGHT_RED = '\033[91m' + LIGHT_GREEN = '\033[92m' + LIGHT_YELLOW = '\033[93m' + LIGHT_BLUE = '\033[94m' + LIGHT_MAGENTA = '\033[95m' + LIGHT_CYAN = '\033[96m' + + UNDERLINE = '\033[4m' + RESET = '\033[0m' + BOLD = '\033[1m' + + @classmethod + def centered_str(cls, message: str, char: str = "-") -> str: + """ + Generate a line full of 'char' with the given message at the center. + Args: + message (str): message to display. + char (str, optional): char with which to fill the line. Defaults to "-". + Returns: + str: generated line + """ + + terminal_size = shutil.get_terminal_size((80, 20)) + return message.center(terminal_size.columns, char) + + +class PackageAndAddonUtils: + """Utility methods to manage python packages and blender add-ons.""" + + @classmethod + def install_py_package(cls, package: str, force: bool = False) -> None: + """ + Install the given python package. + Args: + package (str): name of the package. + force (bool, optional): force reinstall. Defaults to False. + """ + args = [sys.executable, "-m", "pip", "install", package] + if force: + args.append("--force-reinstall") + subprocess.check_call(args) + + @classmethod + def install_py_requirements(cls, requirements: str, force: bool = False) -> None: + """ + Install python packages from the given requirements file. + Args: + requirements (str): path to the requirements file. + force (bool, optional): force reinstall. Defaults to False. + """ + args = [sys.executable, "-m", "pip", "install", "-r", requirements, "-U"] + if force: + args.append("--force-reinstall") + subprocess.check_call(args) + + @classmethod + def install_local_py_package(cls, path: str, force: bool = False) -> None: + """ + Install a local package. + Args: + path (str): path to the folder of the local package. + force (bool, optional): force reinstall. Defaults to False. + """ + args = [sys.executable, "-m", "pip", "install", "-e", path] + if force: + args.append("--force-reinstall") + subprocess.check_call(args) + + @classmethod + def download_blender_addon(cls, url: str, name: str, dest: str = "cache") -> str: + """ + Download the given blender add-on and put it in the destination folder. + Args: + url (str): base url to download the file. + name (str): name of the add-on's folder. + dest (str): destination of the downloaded file. Defaults to 'cache'. + Returns: + str: path to the zip file + """ + + filename = f"{name}.zip" + path = os.path.abspath(os.path.join(dest, filename)) + + if not os.path.exists(dest): + print(f"The given path does not exist: {dest}") + os.mkdir(dest) + print(f"Created destination folder: {dest}") + + if os.path.exists(os.path.join(dest, filename)): + print(f"Stop-Motion-OBJ - found: {path}") + return path + + # Else, download it and save it at the given destination + print(f"Downloading: {filename}") + response = requests.get(url) + open(os.path.join(dest, filename), "wb").write(response.content) + + return path + + +class FilesUtils: + """Methods to manage files and folders when setting up the unit testing environment.""" + + @classmethod + def zipdir(cls, path: str, ziph: zipfile.ZipFile) -> None: + """ + Zip the given folder. + Args: + path (str): path to the folder. + ziph (zipfile.ZipFile): zip file. + """ + + # Inspired from: https://www.tutorialspoint.com/How-to-zip-a-folder-recursively-using-Python + # ziph is zipfile handle + for root, dirs, files in os.walk(path): + for file in files: + ziph.write(os.path.join(root, file)) + + @classmethod + def remove_files_matching_pattern(cls, root_folder: str, exclude_folders: list[str] = [], + pattern: str = "*.zip") -> None: + """ + Remove files which name match the given pattern. + + Inspired from: + https://thispointer.com/python-how-to-remove-files-by-matching-pattern-wildcards-certain-extensions-only/ + + Args: + root_folder (str): root folder. + exclude_folders (list[str], optional): list of folders to exclude from this function. Defaults to []. + pattern (str, optional): pattern of the files to remove. Defaults to "*.zip". + """ + # Get a list of all files in directory + for rootDir, subdirs, filenames in os.walk(root_folder): + # Find the files that matches the given pattern + for filename in fnmatch.filter(filenames, pattern): + try: + if os.path.dirname(os.path.join(rootDir, filename)) not in exclude_folders: + os.remove(os.path.join(rootDir, filename)) + except OSError: + print("Error while deleting file") + + @classmethod + def remove_folders_matching_pattern(cls, root_folder: str, pattern: str = "__pycache__") -> None: + """ + Remove folders which name match the given pattern. + Args: + root_folder (str): root folder. + pattern (str, optional): pattern of the folders to remove. Defaults to "__pycache__". + """ + # Get a list of all files in directory + for rootDir, subdirs, filenames in os.walk(root_folder): + # Find the files that matches the given pattern + for subdir in subdirs: + if subdir == pattern: + shutil.rmtree(os.path.join(rootDir, subdir), ignore_errors=True) From 407c7ee2a52ab1094424c75d5596b6687e9fb11d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Sun, 6 Nov 2022 15:22:22 +0100 Subject: [PATCH 02/26] [Test] Added setup class for pytest --- requirements.txt | 3 ++ scripts/load.py | 120 +++++++++++++++++++++++++++++++++++++++++++++++ scripts/utils.py | 24 ++++++++++ 3 files changed, 147 insertions(+) create mode 100644 scripts/load.py diff --git a/requirements.txt b/requirements.txt index dab7cc9..4f84f9b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,6 +10,9 @@ sphinx-rtd-theme sphinxcontrib-spelling fake-bpy-module-latest +blender-addon-tester +pytest + scipy numpy pillow diff --git a/scripts/load.py b/scripts/load.py new file mode 100644 index 0000000..d8bd2fd --- /dev/null +++ b/scripts/load.py @@ -0,0 +1,120 @@ +"""Run the test suite inside blender.""" +import os +import sys +from pathlib import Path + +# Make utils.py functions available in this file +sys.path.append(os.path.abspath(".")) + +from scripts.utils import TerminalDisplay as TERM +from scripts.utils import PackageAndAddonUtils as PAU + +print(f"{TERM.LIGHT_BLUE}{TERM.centered_str(' LOAD PYTEST ', '=')}{TERM.RESET}") +print("Running file:", __file__, "from Blender.") + +# +---------------------------------------------------------+ +# + GET TEST SUITE CONFIGURATION FROM ENVIRONMENT VARIABLES + +# +---------------------------------------------------------+ + +# Make sure to have BLENDER_ADDON_TO_TEST set as an environment variable first +ADDON = os.environ.get("BLENDER_ADDON_TO_TEST", False) +if not ADDON: + print("ERROR: no add-on to test was found in the 'BLENDER_ADDON_TO_TEST' environment variable.") + sys.exit(1) + +# Set any value to the BLENDER_ADDON_COVERAGE_REPORTING environment variable to enable it +COVERAGE_REPORTING = os.environ.get("BLENDER_ADDON_COVERAGE_REPORTING", False) + +# The Pytest tests/ path can be overridden through the BLENDER_ADDON_TESTS_PATH environment variable +default_tests_dir = Path(ADDON).parent.joinpath("tests") +TESTS_PATH = os.environ.get("BLENDER_ADDON_TESTS_PATH", default_tests_dir.as_posix()) + +# +----------------------+ +# + INSTALL REQUIREMENTS + +# +----------------------+ + +try: + import PIL + import scipy + import numpy + import qiskit + import qiskit_finance + import qiskit_machine_learning + + import pytest + import blender_addon_tester + +except Exception as e: + print(f"{TERM.LIGHT_YELLOW}Missing module...{TERM.RESET}", e) + print(f"{TERM.LIGHT_YELLOW}Trying to install missing dependencies...{TERM.RESET}") + try: + PAU.install_py_requirements(os.path.join(os.path.abspath("."), "requirements.txt"), force=True) + except Exception as e: + print(e) + sys.exit(1) + +# Import unit testing utils functions +import blender_addon_tester.addon_helper as BAT + + +class SetupPlugin: + """Setup class for pytest.""" + + def __init__(self, addon: str): + """ + Init method of the class. + Args: + addon (sstr): absolute path to the addon (zip file) + """ + + self.root = Path(__file__).parent.parent + self.addon = addon + self.addon_dir = "local_addon" + self.bpy_module = None + self.zfile = None + + def pytest_configure(self, config: dict): + """ + Configure pytest. + Args: + config (dict): configuration + """ + + print("PyTest configure...") + + self.bpy_module, self.zfile = BAT.zip_addon(self.addon, self.addon_dir) + BAT.change_addon_dir(self.bpy_module, self.addon_dir) + BAT.install_addon( + os.environ.get( + PAU.ANIMATION_NODES["module"], None), os.environ.get( + PAU.ANIMATION_NODES["path"], None) + ) + BAT.install_addon(self.bpy_module, self.zfile) + config.cache.set("bpy_module", self.bpy_module) + + print("PyTest configure successful!") + + def pytest_unconfigure(self): + """Unconfigure pytest.""" + + print("PyTest unconfigure...") + + BAT.cleanup(self.addon, self.bpy_module, self.addon_dir) + BAT.cleanup(self.addon, os.environ.get(PAU.ANIMATION_NODES["module"], None), self.addon_dir) + + print("PyTest unconfigure successful!") + + +try: + import pytest + + pytest_main_args = ["-x", TESTS_PATH] + if COVERAGE_REPORTING is not False: + pytest_main_args += ["--cov", "--cov-report", "term", "--cov-report", "xml"] + exit_val = pytest.main(pytest_main_args, plugins=[SetupPlugin(ADDON)]) + +except Exception as e: + print(e) + exit_val = 1 + +sys.exit(exit_val) diff --git a/scripts/utils.py b/scripts/utils.py index 55a4faa..1805a54 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -10,6 +10,25 @@ import argparse import subprocess +# Parser for test.py +parser = argparse.ArgumentParser(description="Add-on test suite") +parser.add_argument( + "-b", + metavar="Blender version", + type=str, + nargs='?', + default="3.0.0", + help="Version of Blender to test." +) +parser.add_argument( + "-os", + metavar="Targeted operating system", + type=str, + nargs='?', + default="ubuntu", + help="Targeted operating system on which to run the test suite." +) + class TerminalDisplay: """Usefull tools to better the messages displayed in the terminal.""" @@ -44,6 +63,11 @@ def centered_str(cls, message: str, char: str = "-") -> str: class PackageAndAddonUtils: """Utility methods to manage python packages and blender add-ons.""" + ANIMATION_NODES = { + "module": "ANIMATION_NODES_MODULE", + "path": "" + } + @classmethod def install_py_package(cls, package: str, force: bool = False) -> None: """ From c49c0196cc9abd6d9af925cc4f400a0f1b820c1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Sun, 6 Nov 2022 20:45:13 +0100 Subject: [PATCH 03/26] [Test] WIP: writing test script --- scripts/test.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ scripts/utils.py | 28 +++++++++++++++++--- 2 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 scripts/test.py diff --git a/scripts/test.py b/scripts/test.py new file mode 100644 index 0000000..531f5b6 --- /dev/null +++ b/scripts/test.py @@ -0,0 +1,67 @@ +"""Script to run the test suite for a given os and blender version.""" +import os +import sys +import zipfile +from pathlib import Path + +from scripts.utils import PackageAndAddonUtils as PAU +from scripts.utils import TerminalDisplay as TERM +from scripts.utils import FilesUtils +from scripts.utils import parser + +print(f"{TERM.LIGHT_BLUE}{TERM.centered_str(' TEST SUITE: START ', '=')}{TERM.RESET}") + +# Check that blender-addon-tester is installed +try: + import blender_addon_tester as BAT +except Exception as e: + print(e) + sys.exit(1) + +if __name__ == "__main__": + + args = parser.parse_args() + + if args.b is None: + print(f"{TERM.LIGHT_RED}ERROR: -b option is None.{TERM.RESET}") + parser.parse_args(['-h']) + + blender = args.b + + if args.os is None: + print(f"{TERM.LIGHT_RED}ERROR: -os option is None.{TERM.RESET}") + parser.parse_args(['-h']) + + system = args.os + + if not ['macos-latest', 'ubuntu-latest', 'windows-latest'] in system: + print(f"{TERM.LIGHT_RED}ERROR: -os option must be one of\ + ['macos-latest', 'ubuntu-latest', 'windows-latest'].{TERM.RESET}") + parser.parse_args(['-h']) + + module = "quantum_nodes" + here = Path(__file__).parent + addon = os.path.join(os.path.abspath('.'), module) + cache = os.path.abspath(here.joinpath("../cache").as_posix()) + python = PAU.get_python_version(blender) + + try: + # Cleanup '__pychache__' folders in the module folder + FilesUtils.remove_folders_matching_pattern(addon) + + # Download addons on which this add-on depends + PAU.ANIMATION_NODES["path"] = PAU.download_blender_addon(f"{PAU.ANIMATION_NODES[system]}_py{python}.zip", + PAU.ANIMATION_NODES['module'], cache) + os.environ[f"{PAU.ANIMATION_NODES['module']}_module"] = PAU.ANIMATION_NODES['module'] + os.environ[f"{PAU.ANIMATION_NODES['module']}_path"] = PAU.ANIMATION_NODES['path'] + + # Zip addon + print(f"Zipping addon - path: {PAU.ANIMATION_NODES['path']}") + zipf = zipfile.ZipFile(module + ".zip", 'w', zipfile.ZIP_DEFLATED) + FilesUtils.zipdir("./" + module, zipf) + zipf.close() + addon = os.path.join(os.path.abspath("."), module + ".zip") + + except Exception as e: + print(e) + exit_val = 1 diff --git a/scripts/utils.py b/scripts/utils.py index 1805a54..56e6f04 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -64,10 +64,30 @@ class PackageAndAddonUtils: """Utility methods to manage python packages and blender add-ons.""" ANIMATION_NODES = { - "module": "ANIMATION_NODES_MODULE", - "path": "" + "module": "animation_nodes", + "path": "", + "windows-latest": "https://github.com/JacquesLucke/animation_nodes/releases/download/master-cd-build/animation_nodes_v2_3_windows", + "ubuntu-latest": "https://github.com/JacquesLucke/animation_nodes/releases/download/master-cd-build/animation_nodes_v2_3_ubuntu", + "macos-latest": "https://github.com/JacquesLucke/animation_nodes/releases/download/master-cd-build/animation_nodes_v2_3_macOS", } + @classmethod + def get_python_version(cls, blender: str) -> str: + """ + Get the python version used by the given blender version. + + Args: + blender (str): blender version (format: major.minor.patch). + + Returns: + str: python version used by Blender (MajorMinor). + """ + + if ["2.9", "3.0"] in blender: + return "39" + if ["3.1, 3.2, 3.3"]: + return "310" + @classmethod def install_py_package(cls, package: str, force: bool = False) -> None: """ @@ -108,13 +128,13 @@ def install_local_py_package(cls, path: str, force: bool = False) -> None: subprocess.check_call(args) @classmethod - def download_blender_addon(cls, url: str, name: str, dest: str = "cache") -> str: + def download_blender_addon(cls, url: str, name: str, dest: str) -> str: """ Download the given blender add-on and put it in the destination folder. Args: url (str): base url to download the file. name (str): name of the add-on's folder. - dest (str): destination of the downloaded file. Defaults to 'cache'. + dest (str): destination of the downloaded file. Returns: str: path to the zip file """ From d06251df962f85c6de23398b4c2c1a45dd37ecae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Fri, 11 Nov 2022 14:37:19 +0100 Subject: [PATCH 04/26] [Test] WIP: test script is almost working --- pytest.ini | 3 +++ scripts/load.py | 15 ++++++++++----- scripts/test.py | 33 ++++++++++++++++++++++++++++----- scripts/utils.py | 13 ++++++++----- tests/test.py | 7 +++++++ 5 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 pytest.ini create mode 100644 tests/test.py diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..62d5d56 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +testpaths=tests/ +norecursedirs=tests/helpers \ No newline at end of file diff --git a/scripts/load.py b/scripts/load.py index d8bd2fd..922a43a 100644 --- a/scripts/load.py +++ b/scripts/load.py @@ -8,6 +8,7 @@ from scripts.utils import TerminalDisplay as TERM from scripts.utils import PackageAndAddonUtils as PAU +from scripts.utils import FilesUtils print(f"{TERM.LIGHT_BLUE}{TERM.centered_str(' LOAD PYTEST ', '=')}{TERM.RESET}") print("Running file:", __file__, "from Blender.") @@ -85,9 +86,8 @@ def pytest_configure(self, config: dict): self.bpy_module, self.zfile = BAT.zip_addon(self.addon, self.addon_dir) BAT.change_addon_dir(self.bpy_module, self.addon_dir) BAT.install_addon( - os.environ.get( - PAU.ANIMATION_NODES["module"], None), os.environ.get( - PAU.ANIMATION_NODES["path"], None) + os.environ.get(f"{PAU.ANIMATION_NODES['module']}_module", None), + os.environ.get(f"{PAU.ANIMATION_NODES['module']}_path", None) ) BAT.install_addon(self.bpy_module, self.zfile) config.cache.set("bpy_module", self.bpy_module) @@ -99,8 +99,13 @@ def pytest_unconfigure(self): print("PyTest unconfigure...") - BAT.cleanup(self.addon, self.bpy_module, self.addon_dir) - BAT.cleanup(self.addon, os.environ.get(PAU.ANIMATION_NODES["module"], None), self.addon_dir) + BAT.cleanup(None, self.bpy_module, self.addon_dir) + BAT.cleanup(None, os.environ.get(f"{PAU.ANIMATION_NODES['module']}_module", None), self.addon_dir) + + # Cleanup zip files + print("Cleaning up - zip files") + exclude = [os.path.abspath("./cache")] + FilesUtils.remove_files_matching_pattern(self.root, exclude_folders=exclude, pattern="*.zip") print("PyTest unconfigure successful!") diff --git a/scripts/test.py b/scripts/test.py index 531f5b6..d775af7 100644 --- a/scripts/test.py +++ b/scripts/test.py @@ -34,9 +34,9 @@ system = args.os - if not ['macos-latest', 'ubuntu-latest', 'windows-latest'] in system: - print(f"{TERM.LIGHT_RED}ERROR: -os option must be one of\ - ['macos-latest', 'ubuntu-latest', 'windows-latest'].{TERM.RESET}") + if not any(system == supported_os for supported_os in ['macos-latest', 'ubuntu-latest', 'windows-latest']): + print(f"{TERM.LIGHT_RED}ERROR: -os option must be one of: \ +['macos-latest', 'ubuntu-latest', 'windows-latest'].{TERM.RESET}") parser.parse_args(['-h']) module = "quantum_nodes" @@ -51,12 +51,12 @@ # Download addons on which this add-on depends PAU.ANIMATION_NODES["path"] = PAU.download_blender_addon(f"{PAU.ANIMATION_NODES[system]}_py{python}.zip", - PAU.ANIMATION_NODES['module'], cache) + f"{PAU.ANIMATION_NODES['module']}_py{python}", cache) os.environ[f"{PAU.ANIMATION_NODES['module']}_module"] = PAU.ANIMATION_NODES['module'] os.environ[f"{PAU.ANIMATION_NODES['module']}_path"] = PAU.ANIMATION_NODES['path'] # Zip addon - print(f"Zipping addon - path: {PAU.ANIMATION_NODES['path']}") + print(f"Zipping folder: {addon}") zipf = zipfile.ZipFile(module + ".zip", 'w', zipfile.ZIP_DEFLATED) FilesUtils.zipdir("./" + module, zipf) zipf.close() @@ -65,3 +65,26 @@ except Exception as e: print(e) exit_val = 1 + + # Custom configuration + config = { + "blender_load_tests_script": os.path.abspath(here.joinpath("load.py").as_posix()), + "coverage": False, + "tests": os.path.abspath(here.joinpath("../tests").as_posix()), + "blender_cache": os.path.abspath(here.joinpath("../cache").as_posix()) + } + + try: + # Setup custom blender cache (where the blender versions will be downloaded and extracted) + # The blender_addon_tester module raises an error when passed as a key in the config dict + if config.get("blender_cache", None): + os.environ["BLENDER_CACHE"] = config["blender_cache"] + config.pop("blender_cache") + + exit_val = BAT.test_blender_addon(addon_path=addon, blender_revision=blender, config=config) + except Exception as e: + print(e) + exit_val = 1 + + print(f"{TERM.LIGHT_BLUE}{TERM.centered_str(' RUN TESTS END ', '=')}{TERM.RESET}") + sys.exit(exit_val) diff --git a/scripts/utils.py b/scripts/utils.py index 56e6f04..572b4fe 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -26,7 +26,7 @@ type=str, nargs='?', default="ubuntu", - help="Targeted operating system on which to run the test suite." + help="Targeted operating system on which to run the test suite. Must be one of: ['macos-latest', 'ubuntu-latest', 'windows-latest']." ) @@ -83,11 +83,14 @@ def get_python_version(cls, blender: str) -> str: str: python version used by Blender (MajorMinor). """ - if ["2.9", "3.0"] in blender: + if any(version in blender for version in ["2.9", "3.0"]): return "39" - if ["3.1, 3.2, 3.3"]: + + if any(version in blender for version in ["3.1, 3.2, 3.3"]): return "310" + raise ValueError(f"Unable to determine which python version is used by the given blender version ({blender})") + @classmethod def install_py_package(cls, package: str, force: bool = False) -> None: """ @@ -148,11 +151,11 @@ def download_blender_addon(cls, url: str, name: str, dest: str) -> str: print(f"Created destination folder: {dest}") if os.path.exists(os.path.join(dest, filename)): - print(f"Stop-Motion-OBJ - found: {path}") + print(f"{name} - found: {path}") return path # Else, download it and save it at the given destination - print(f"Downloading: {filename}") + print(f"Downloading: {filename} ({url})") response = requests.get(url) open(os.path.join(dest, filename), "wb").write(response.content) diff --git a/tests/test.py b/tests/test.py new file mode 100644 index 0000000..c51fbea --- /dev/null +++ b/tests/test.py @@ -0,0 +1,7 @@ +import bpy +import pytest + + +def test_hello_world(): + + assert "HelloWorld" is True From 492c04ba45713ca3135232f10c1d4d2516c942bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Fri, 11 Nov 2022 18:18:32 +0100 Subject: [PATCH 05/26] [Test] Fixed small issues --- .gitignore | 1 + scripts/test.py | 2 +- scripts/utils.py | 2 +- tests/{test.py => test_hello_world.py} | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) rename tests/{test.py => test_hello_world.py} (61%) diff --git a/.gitignore b/.gitignore index da5046e..0d1c5ff 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ docs/source/developers_manual/code/ animation_nodes/ # Cache +.pytest_cache/ **/__pycache__ cache/ diff --git a/scripts/test.py b/scripts/test.py index d775af7..3fa01af 100644 --- a/scripts/test.py +++ b/scripts/test.py @@ -86,5 +86,5 @@ print(e) exit_val = 1 - print(f"{TERM.LIGHT_BLUE}{TERM.centered_str(' RUN TESTS END ', '=')}{TERM.RESET}") + print(f"{TERM.LIGHT_BLUE}{TERM.centered_str(' TEST SUITE: END ', '=')}{TERM.RESET}") sys.exit(exit_val) diff --git a/scripts/utils.py b/scripts/utils.py index 572b4fe..04c8690 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -67,7 +67,7 @@ class PackageAndAddonUtils: "module": "animation_nodes", "path": "", "windows-latest": "https://github.com/JacquesLucke/animation_nodes/releases/download/master-cd-build/animation_nodes_v2_3_windows", - "ubuntu-latest": "https://github.com/JacquesLucke/animation_nodes/releases/download/master-cd-build/animation_nodes_v2_3_ubuntu", + "ubuntu-latest": "https://github.com/JacquesLucke/animation_nodes/releases/download/master-cd-build/animation_nodes_v2_3_linux", "macos-latest": "https://github.com/JacquesLucke/animation_nodes/releases/download/master-cd-build/animation_nodes_v2_3_macOS", } diff --git a/tests/test.py b/tests/test_hello_world.py similarity index 61% rename from tests/test.py rename to tests/test_hello_world.py index c51fbea..f7d6862 100644 --- a/tests/test.py +++ b/tests/test_hello_world.py @@ -4,4 +4,4 @@ def test_hello_world(): - assert "HelloWorld" is True + assert "HelloWorld" == True From 711e11f1d1149cfcd7d989f1df6f7d459c5aae50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Fri, 11 Nov 2022 19:03:34 +0100 Subject: [PATCH 06/26] [Test] Fixed issues + added unit-testing script --- .github/workflows/unit-testing.yml | 58 ++++++++++++++++++++++++++++++ scripts/load.py | 3 ++ scripts/utils.py | 24 ++++++++----- tests/test_hello_world.py | 2 +- 4 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/unit-testing.yml diff --git a/.github/workflows/unit-testing.yml b/.github/workflows/unit-testing.yml new file mode 100644 index 0000000..46cfe9a --- /dev/null +++ b/.github/workflows/unit-testing.yml @@ -0,0 +1,58 @@ +name: Unit testing +on: + pull_request: # Run in pull requests + + workflow_dispatch: # Allow to run this workflow manually + + push: + branches: # Run when there is a push to master + - "master" + +jobs: + Unit-testing: + runs-on: {{ matrix.os }} + strategy: + max-parallel: 4 + fail-fast: false + matrix: + blender-version: + [ + "2.93.0", + "3.0.0", + "3.0.1", + "3.1.0", + "3.1.1", + "3.1.2", + "3.2.0", + "3.2.1", + "3.2.2", + "3.3.0", + "3.3.1" + ] + env: + BLENDER_CACHE: ${{ github.workspace }}/cache # The place where blender releases are downloaded + BLENDER_VERSION: ${{ matrix.blender-version }} + steps: + - uses: actions/checkout@v2.5.0 + + - uses: actions/setup-python@v4.3.0 + with: + python-version: "3.10" + + - uses: syphar/restore-virtualenv@v1.2 + id: cache-virtualenv + with: + requirement_files: requirements.txt + + - name: Cache Blender release download + uses: actions/cache@v3.0.11 + with: + path: ${{ env.BLENDER_CACHE }} + key: ${{ matrix.os }}-blender-${{ matrix.blender-version }} + + - name: Install dependencies + if: steps.cache-virtualenv.outputs.cache-hit != 'true' + run: pip install -r requirements.txt + + - name: Run test suite (Blender ${{ matrix.blender-version }}, ${{ matrix.os }}) + run: python -m scripts.run_tests.py -b ${{ matrix.blender-version }} -os ${{ matrix.os }} \ No newline at end of file diff --git a/scripts/load.py b/scripts/load.py index 922a43a..20bf18e 100644 --- a/scripts/load.py +++ b/scripts/load.py @@ -1,4 +1,5 @@ """Run the test suite inside blender.""" + import os import sys from pathlib import Path @@ -64,6 +65,7 @@ class SetupPlugin: def __init__(self, addon: str): """ Init method of the class. + Args: addon (sstr): absolute path to the addon (zip file) """ @@ -77,6 +79,7 @@ def __init__(self, addon: str): def pytest_configure(self, config: dict): """ Configure pytest. + Args: config (dict): configuration """ diff --git a/scripts/utils.py b/scripts/utils.py index 04c8690..121c120 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -1,6 +1,5 @@ -""" -Utility functions and classes to setup the unit testing environment. -""" +"""Utility functions and classes to setup the unit testing environment.""" + import os import sys import shutil @@ -26,12 +25,12 @@ type=str, nargs='?', default="ubuntu", - help="Targeted operating system on which to run the test suite. Must be one of: ['macos-latest', 'ubuntu-latest', 'windows-latest']." + help="Targeted operating system on which to run the test suite. Must be one of: ['macos-latest', 'ubuntu-latest', 'windows-latest']." # noqa: E501 ) class TerminalDisplay: - """Usefull tools to better the messages displayed in the terminal.""" + """Useful tools to better the messages displayed in the terminal.""" # List of colors which can be used to color texts in the terminal. LIGHT_RED = '\033[91m' @@ -49,9 +48,11 @@ class TerminalDisplay: def centered_str(cls, message: str, char: str = "-") -> str: """ Generate a line full of 'char' with the given message at the center. + Args: message (str): message to display. char (str, optional): char with which to fill the line. Defaults to "-". + Returns: str: generated line """ @@ -66,9 +67,9 @@ class PackageAndAddonUtils: ANIMATION_NODES = { "module": "animation_nodes", "path": "", - "windows-latest": "https://github.com/JacquesLucke/animation_nodes/releases/download/master-cd-build/animation_nodes_v2_3_windows", - "ubuntu-latest": "https://github.com/JacquesLucke/animation_nodes/releases/download/master-cd-build/animation_nodes_v2_3_linux", - "macos-latest": "https://github.com/JacquesLucke/animation_nodes/releases/download/master-cd-build/animation_nodes_v2_3_macOS", + "windows-latest": "https://github.com/JacquesLucke/animation_nodes/releases/download/master-cd-build/animation_nodes_v2_3_windows", # noqa: E501 + "ubuntu-latest": "https://github.com/JacquesLucke/animation_nodes/releases/download/master-cd-build/animation_nodes_v2_3_linux", # noqa: E501 + "macos-latest": "https://github.com/JacquesLucke/animation_nodes/releases/download/master-cd-build/animation_nodes_v2_3_macOS", # noqa: E501 } @classmethod @@ -95,6 +96,7 @@ def get_python_version(cls, blender: str) -> str: def install_py_package(cls, package: str, force: bool = False) -> None: """ Install the given python package. + Args: package (str): name of the package. force (bool, optional): force reinstall. Defaults to False. @@ -108,6 +110,7 @@ def install_py_package(cls, package: str, force: bool = False) -> None: def install_py_requirements(cls, requirements: str, force: bool = False) -> None: """ Install python packages from the given requirements file. + Args: requirements (str): path to the requirements file. force (bool, optional): force reinstall. Defaults to False. @@ -121,6 +124,7 @@ def install_py_requirements(cls, requirements: str, force: bool = False) -> None def install_local_py_package(cls, path: str, force: bool = False) -> None: """ Install a local package. + Args: path (str): path to the folder of the local package. force (bool, optional): force reinstall. Defaults to False. @@ -134,10 +138,12 @@ def install_local_py_package(cls, path: str, force: bool = False) -> None: def download_blender_addon(cls, url: str, name: str, dest: str) -> str: """ Download the given blender add-on and put it in the destination folder. + Args: url (str): base url to download the file. name (str): name of the add-on's folder. dest (str): destination of the downloaded file. + Returns: str: path to the zip file """ @@ -169,6 +175,7 @@ class FilesUtils: def zipdir(cls, path: str, ziph: zipfile.ZipFile) -> None: """ Zip the given folder. + Args: path (str): path to the folder. ziph (zipfile.ZipFile): zip file. @@ -208,6 +215,7 @@ def remove_files_matching_pattern(cls, root_folder: str, exclude_folders: list[s def remove_folders_matching_pattern(cls, root_folder: str, pattern: str = "__pycache__") -> None: """ Remove folders which name match the given pattern. + Args: root_folder (str): root folder. pattern (str, optional): pattern of the folders to remove. Defaults to "__pycache__". diff --git a/tests/test_hello_world.py b/tests/test_hello_world.py index f7d6862..a18908d 100644 --- a/tests/test_hello_world.py +++ b/tests/test_hello_world.py @@ -4,4 +4,4 @@ def test_hello_world(): - assert "HelloWorld" == True + assert "HelloWorld" == "test_fail" From bd26009dde199bab3e65768f5bc4cf89dce1ec55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Fri, 11 Nov 2022 19:31:50 +0100 Subject: [PATCH 07/26] [Test] Fixed missing 'matrix.os' definition --- .github/workflows/unit-testing.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-testing.yml b/.github/workflows/unit-testing.yml index 46cfe9a..a5ca04d 100644 --- a/.github/workflows/unit-testing.yml +++ b/.github/workflows/unit-testing.yml @@ -10,7 +10,7 @@ on: jobs: Unit-testing: - runs-on: {{ matrix.os }} + runs-on: ${{ matrix.os }} strategy: max-parallel: 4 fail-fast: false @@ -28,7 +28,8 @@ jobs: "3.2.2", "3.3.0", "3.3.1" - ] + ], + os: ["ubuntu-latest", "windows-latest"] env: BLENDER_CACHE: ${{ github.workspace }}/cache # The place where blender releases are downloaded BLENDER_VERSION: ${{ matrix.blender-version }} From bb173e0a2702e65737783509b04f31cd6773e538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Fri, 11 Nov 2022 19:33:20 +0100 Subject: [PATCH 08/26] [Test] Fixed wrong 'matrix.os' definition --- .github/workflows/unit-testing.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/unit-testing.yml b/.github/workflows/unit-testing.yml index a5ca04d..185fe22 100644 --- a/.github/workflows/unit-testing.yml +++ b/.github/workflows/unit-testing.yml @@ -15,7 +15,7 @@ jobs: max-parallel: 4 fail-fast: false matrix: - blender-version: + - blender-version: [ "2.93.0", "3.0.0", @@ -28,8 +28,8 @@ jobs: "3.2.2", "3.3.0", "3.3.1" - ], - os: ["ubuntu-latest", "windows-latest"] + ] + - os: ["ubuntu-latest", "windows-latest"] env: BLENDER_CACHE: ${{ github.workspace }}/cache # The place where blender releases are downloaded BLENDER_VERSION: ${{ matrix.blender-version }} From e3c772ce7f84d90b8d73d27d84151f74c2a33ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Fri, 11 Nov 2022 19:35:12 +0100 Subject: [PATCH 09/26] [Test] Fixed missing 'matrix.os' definition --- .github/workflows/unit-testing.yml | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/.github/workflows/unit-testing.yml b/.github/workflows/unit-testing.yml index 185fe22..56e61d6 100644 --- a/.github/workflows/unit-testing.yml +++ b/.github/workflows/unit-testing.yml @@ -15,21 +15,8 @@ jobs: max-parallel: 4 fail-fast: false matrix: - - blender-version: - [ - "2.93.0", - "3.0.0", - "3.0.1", - "3.1.0", - "3.1.1", - "3.1.2", - "3.2.0", - "3.2.1", - "3.2.2", - "3.3.0", - "3.3.1" - ] - - os: ["ubuntu-latest", "windows-latest"] + - blender-version: ["2.93.0", "3.0.0", "3.0.1", "3.1.0", "3.1.1", "3.1.2", "3.2.0", "3.2.1", "3.2.2", "3.3.0", "3.3.1"] + - os: ["ubuntu-latest", "windows-latest"] env: BLENDER_CACHE: ${{ github.workspace }}/cache # The place where blender releases are downloaded BLENDER_VERSION: ${{ matrix.blender-version }} From 8c3124b8c802a1cb9f8f0ade135a3c05dded8b87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Fri, 11 Nov 2022 19:37:42 +0100 Subject: [PATCH 10/26] [Test] Fixed missing 'matrix.os' definition --- .github/workflows/unit-testing.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/unit-testing.yml b/.github/workflows/unit-testing.yml index 56e61d6..ab434a3 100644 --- a/.github/workflows/unit-testing.yml +++ b/.github/workflows/unit-testing.yml @@ -15,8 +15,8 @@ jobs: max-parallel: 4 fail-fast: false matrix: - - blender-version: ["2.93.0", "3.0.0", "3.0.1", "3.1.0", "3.1.1", "3.1.2", "3.2.0", "3.2.1", "3.2.2", "3.3.0", "3.3.1"] - - os: ["ubuntu-latest", "windows-latest"] + blender-version: ["2.93.0", "3.0.0", "3.0.1", "3.1.0", "3.1.1", "3.1.2", "3.2.0", "3.2.1", "3.2.2", "3.3.0", "3.3.1",] + os: ["ubuntu-latest", "windows-latest",] env: BLENDER_CACHE: ${{ github.workspace }}/cache # The place where blender releases are downloaded BLENDER_VERSION: ${{ matrix.blender-version }} From 7906948634946d8f132b5cd57aed026f8b7c9bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Fri, 11 Nov 2022 19:39:06 +0100 Subject: [PATCH 11/26] [Test] Fixed wrong test file name in python command --- .github/workflows/unit-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-testing.yml b/.github/workflows/unit-testing.yml index ab434a3..ac08999 100644 --- a/.github/workflows/unit-testing.yml +++ b/.github/workflows/unit-testing.yml @@ -43,4 +43,4 @@ jobs: run: pip install -r requirements.txt - name: Run test suite (Blender ${{ matrix.blender-version }}, ${{ matrix.os }}) - run: python -m scripts.run_tests.py -b ${{ matrix.blender-version }} -os ${{ matrix.os }} \ No newline at end of file + run: python -m scripts.test.py -b ${{ matrix.blender-version }} -os ${{ matrix.os }} \ No newline at end of file From e594effe86a9ab1fb29b66a09ab8ce6c0f30c30d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Fri, 11 Nov 2022 19:40:36 +0100 Subject: [PATCH 12/26] [Test] Fixed wrong test file name in python command --- .github/workflows/unit-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-testing.yml b/.github/workflows/unit-testing.yml index ac08999..c7aabe7 100644 --- a/.github/workflows/unit-testing.yml +++ b/.github/workflows/unit-testing.yml @@ -43,4 +43,4 @@ jobs: run: pip install -r requirements.txt - name: Run test suite (Blender ${{ matrix.blender-version }}, ${{ matrix.os }}) - run: python -m scripts.test.py -b ${{ matrix.blender-version }} -os ${{ matrix.os }} \ No newline at end of file + run: python -m scripts.test -b ${{ matrix.blender-version }} -os ${{ matrix.os }} \ No newline at end of file From cdfbfa4ed625634b693b183c3d9c85377949d1be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Sat, 12 Nov 2022 17:00:01 +0100 Subject: [PATCH 13/26] [Doc] Added new tutorial for dev env linux --- docs/source/developers_manual/addon/linux.rst | 177 +++++++++++++++++- docs/source/spelling_wordlist.txt | 3 +- scripts/setup_animation_nodes.sh | 26 +++ tests/test_hello_world.py | 4 +- 4 files changed, 198 insertions(+), 12 deletions(-) create mode 100644 scripts/setup_animation_nodes.sh diff --git a/docs/source/developers_manual/addon/linux.rst b/docs/source/developers_manual/addon/linux.rst index f2ad7e4..f645444 100644 --- a/docs/source/developers_manual/addon/linux.rst +++ b/docs/source/developers_manual/addon/linux.rst @@ -3,24 +3,181 @@ Linux ===== +.. note:: -.. _dev-env-dependencies-contrib-addon: + This tutorial will help you to setup a full development environment for ubuntu. -Dependencies -############ +.. _linux-dev-env-downloads-contrib-addon: -.. important:: - We recommend you to setup an anaconda environment and link it to Blender. +Downloads +######### -Install using ``pip install -r requirements.txt`` +.. _linux-dev-env-downloads-blender-contrib-addon: +Blender +******* -.. _dev-env-ide-contrib-addon: +* | First, we need to download a portable version of Blender. + | Download a version from here: https://www.blender.org/download/. + + +.. _linux-dev-env-downloads-animation-nodes-contrib-addon: + +Animation Nodes +*************** + +* | Before downloading Animation Nodes, we need to know which python version is shipped with the + | chosen Blender version. We can get it by looking at the files (from the archive) located + | at: ``blender[...]/[X.Y]/python/bin/``. + | For Blender >= 2.93.0, it will probably be something between python 3.9 and 3.10. + +* | Once we know that, we have to download the add-on from the release page of + | Animation Nodes (take latest): https://github.com/JacquesLucke/animation_nodes/releases/tag/master-cd-build. + + +.. _linux-dev-env-downloads-quantum-nodes-contrib-addon: + +Quantum Nodes +************* + +* Make a fork of the repository: https://github.com/Quantum-Creative-Group/quantum_nodes/fork. +* Then, clone the forked repository on your computer. + + +.. _linux-dev-env-downloads-ide-contrib-addon: IDE -### +*** + +* We recommend to use `Visual Studio Code `_. +* See :ref:`tools-dev-addon` for more information. + + +.. _linux-dev-env-installations-contrib-addon: + +Installations +############# + + +.. note:: + + Since Blender comes with its own python environment, we will use this one as our development environment too. + + +.. _linux-dev-env-installations-blender-contrib-addon: + +Blender +******* + +* | Decompress the downloaded archive which contains the blender version. + | We can place these files where we want. However, we recommend to place them in the ``/opt/`` folder. + +* Run Blender at least one time to make sure it works fine. + + +.. _linux-dev-env-installations-python-contrib-addon: + +Python dependencies +******************* + +We need to run the installation from the python distribution of Blender. For that, we need the path to the python +executable. We can find it here: ``path/to/blender/files/ .... /[X.Y]/python/bin/python3.X``. + +.. note:: + + | Since we will need to reference this several times, we can add an alias in the ``.bash_aliases`` file located + | in the ``home/[username]/`` directory (create the file if it does not exist). + | Example: ``alias pythonb=/opt/blender-3.0.1-linux-x64/3.0/python/bin/python3.9`` + +* Go to the ``quantum_nodes/`` directory. +* Run ``path/to/blender/files/ .... /[X.Y]/python/bin/python3.X -m pip install -r requirements.txt``. + + +.. _linux-dev-env-installations-animation-nodes-contrib-addon: + +Animation Nodes +*************** + +In this part we will install the add-on for Blender and copy the content of the ``animation_nodes/`` folder in the +blender python distribution so it will be available for our different scripts (documentation build and test suite). + +Installation in Blender: + +* Install the add-on inside Blender (as in the :ref:`installation guide `). +* Make sure it works fine. + +Installation for the IDE and the python scripts: + +* Extract the ``animation_nodes/`` folder from the archive. +* | Run the following bash script ``scripts/setup_animation_nodes.sh``. You need to provide several information in order + | to run the script correctly. + | -> The path to the ``site-packages/`` folder in the python distribution shipped with Blender. + | -> The path to the ``animation_nodes/`` folder previously extracted. + | -> The path to the ``quantum_nodes/`` folder. + | Example: + | ``bash scripts/setup_animation_nodes.sh /opt/blender-3.0.1-linux-x64/3.0/python/lib/python3.9/site-packages/ ~/Documents/animation_nodes/ ~/Documents/quantum_nodes/`` + + +.. _linux-dev-env-build-and-test-contrib-addon: + +Build and test +############## + +.. note:: + + Before following the next instructions, please install and configure the recommended Visual Studio Code + extensions cited in :ref:`this section `. + + +.. _linux-dev-env-build-and-test-run-from-vscode-contrib-addon: + +Run Quantum Nodes from Visual Studio Code +***************************************** + +The `Blender Development` extension let us to quickly run Blender with the modifications made to the add-on +on which we are currently working. It runs Blender in a sort of 'debug' mode to test our add-on. + +* In VSCode, hit ``ctrl + shift + p`` and type ``blender start``. Then, hit ``enter``. +* If no blender executable was previously set, follow the instructions given by the extension. +* Wait for Blender to start. +* Once ready, edit code in live and save files to apply changes (it reloads the add-on automatically). + + +.. _linux-dev-env-build-and-test-build-documentation-contrib-addon: + +Build the documentation +*********************** + +Generate automatic code documentation: + + +.. note:: + + This step is not mandatory to build the documentation. You can skip it if you don't need this part + in your local build. + + +* Go in the ``quantum_nodes/docs/`` folder. +* | Run: + | ``path/to/blender/files/ .... /[X.Y]/python/bin/sphinx-apidoc -t "_templates/" --implicit-namespaces -d 1 -f -M -T -o source/developers_manual/code/ ../quantum_nodes "/*animation_nodes/*" "/*lib/*"`` + | Next commands are optional: + | ``sed -i "1s/.*/Code documentation/" source/developers_manual/code/quantum_nodes.rst`` + | ``sed -i "2s/.*/==================/" source/developers_manual/code/quantum_nodes.rst`` + +Build the documentation: + +* Go in the ``quantum_nodes/docs/`` folder. +* Run: ``make html SPHINXBUILD=path/to/blender/files/ .... /[X.Y]/python/bin/sphinx-build`` +* The build is then available in the following folder: ``quantum_nodes/docs/build/``. + + +.. _linux-dev-env-build-and-test-run-test-suite-contrib-addon: + +Run the test suite +****************** -* We recommend you to use `Visual Studio Code `_. -* See :ref:`tools-dev-addon` for more information. \ No newline at end of file +* Go in the ``quantum_nodes/`` folder. +* Run: ``path/to/blender/files/ .... /[X.Y]/python/bin/python3.X -m scripts.test -b [blender version] -os [operating system]`` +* Example: ``path/to/blender/files/ .... /[X.Y]/python/bin/python3.X -m scripts.test -b 3.0.0 -os ubuntu-latest`` \ No newline at end of file diff --git a/docs/source/spelling_wordlist.txt b/docs/source/spelling_wordlist.txt index ff8fffd..f99f4c7 100644 --- a/docs/source/spelling_wordlist.txt +++ b/docs/source/spelling_wordlist.txt @@ -27,4 +27,5 @@ addon namespace qasm statevector -uncorrectable \ No newline at end of file +uncorrectable +ubuntu \ No newline at end of file diff --git a/scripts/setup_animation_nodes.sh b/scripts/setup_animation_nodes.sh new file mode 100644 index 0000000..3abf2d8 --- /dev/null +++ b/scripts/setup_animation_nodes.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +SITE_PACKAGES=$1 +ANIMATION_NODES=$2 +QUANTUM_NODES=$3 + +echo "---------- SETUP ANIMATION NODES: START ---------" + +echo "STEP 1: replace __init__.py file" + +rm $ANIMATION_NODES/__init__.py +cp $QUANTUM_NODES/docs/_static/animation_nodes_init_replacement_file.txt $ANIMATION_NODES/__init__.py + +echo "STEP 2: edit preferences.py" + +find $ANIMATION_NODES/ -type f -name "*.py" -exec sed -i 's/return bpy.app.version/return bpy.app.version if bpy.app.version is not None else (2, 93, 0)/g' {} + + +echo "STEP 3: remove '@persistent' decorators" + +find $ANIMATION_NODES/ -type f -name "*.py" -exec sed -i 's/@persistent/#@persistent/g' {} + + +echo "STEP 4: move animation_nodes to 'site-packages/'" + +sudo cp -r $ANIMATION_NODES $SITE_PACKAGES + +echo "----------- SETUP ANIMATION NODES: END ----------" diff --git a/tests/test_hello_world.py b/tests/test_hello_world.py index a18908d..0b558bb 100644 --- a/tests/test_hello_world.py +++ b/tests/test_hello_world.py @@ -4,4 +4,6 @@ def test_hello_world(): - assert "HelloWorld" == "test_fail" + variable = "HelloWorld" + + assert "HelloWorld" == variable From d370917e41e8ff2f4a8d4071faf024c87d2228fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Sat, 12 Nov 2022 17:18:25 +0100 Subject: [PATCH 14/26] [Test] Reduced number of unit tests --- .github/workflows/unit-testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-testing.yml b/.github/workflows/unit-testing.yml index c7aabe7..7b15b5a 100644 --- a/.github/workflows/unit-testing.yml +++ b/.github/workflows/unit-testing.yml @@ -15,7 +15,7 @@ jobs: max-parallel: 4 fail-fast: false matrix: - blender-version: ["2.93.0", "3.0.0", "3.0.1", "3.1.0", "3.1.1", "3.1.2", "3.2.0", "3.2.1", "3.2.2", "3.3.0", "3.3.1",] + blender-version: ["2.93.11", "3.3.1",] os: ["ubuntu-latest", "windows-latest",] env: BLENDER_CACHE: ${{ github.workspace }}/cache # The place where blender releases are downloaded From e6634c62da5a38fd077fa6f94c66fcce0c639119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Sat, 12 Nov 2022 17:22:08 +0100 Subject: [PATCH 15/26] [Test] Fixed wrong list of versions in get_python_version --- scripts/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/utils.py b/scripts/utils.py index 121c120..7118a8e 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -87,7 +87,7 @@ def get_python_version(cls, blender: str) -> str: if any(version in blender for version in ["2.9", "3.0"]): return "39" - if any(version in blender for version in ["3.1, 3.2, 3.3"]): + if any(version in blender for version in ["3.1", "3.2", "3.3"]): return "310" raise ValueError(f"Unable to determine which python version is used by the given blender version ({blender})") From afdae53260c74963c4f31c23980b001bf6c756b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Sun, 27 Nov 2022 13:55:59 +0100 Subject: [PATCH 16/26] [Test] Applied temporary fix to windows issue in unit tests --- scripts/load.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/load.py b/scripts/load.py index 20bf18e..8710880 100644 --- a/scripts/load.py +++ b/scripts/load.py @@ -62,7 +62,7 @@ class SetupPlugin: """Setup class for pytest.""" - def __init__(self, addon: str): + def __init__(self, addon: str, addon_dir: str = os.path.abspath("./local_addon/")): """ Init method of the class. @@ -72,7 +72,7 @@ def __init__(self, addon: str): self.root = Path(__file__).parent.parent self.addon = addon - self.addon_dir = "local_addon" + self.addon_dir = addon_dir self.bpy_module = None self.zfile = None @@ -102,14 +102,21 @@ def pytest_unconfigure(self): print("PyTest unconfigure...") - BAT.cleanup(None, self.bpy_module, self.addon_dir) - BAT.cleanup(None, os.environ.get(f"{PAU.ANIMATION_NODES['module']}_module", None), self.addon_dir) - # Cleanup zip files print("Cleaning up - zip files") exclude = [os.path.abspath("./cache")] FilesUtils.remove_files_matching_pattern(self.root, exclude_folders=exclude, pattern="*.zip") + BAT.cleanup(None, self.bpy_module, os.path.join(self.addon_dir, "addons", self.bpy_module)) + + # TODO: find a better fix to "[WinError 5] Access denied: + # '[....]\\local_addon\\addons\\animation_nodes\\algorithms\\hashing\\murmurhash3.cp39-win_amd64.pyd'" + try: + an_path = os.environ.get(f"{PAU.ANIMATION_NODES['module']}_module", None) + BAT.cleanup(None, an_path, os.path.join(self.addon_dir, "addons", an_path)) + except BaseException as exception: + print(f"{TERM.LIGHT_YELLOW}WARNING: failed to clean animation_nodes directory ({an_path}).{TERM.RESET}") + print("PyTest unconfigure successful!") From 2b3344ecd4c0c39d0d48db839812ff73874546da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Sun, 27 Nov 2022 14:05:12 +0100 Subject: [PATCH 17/26] [Test] Fixed small issues --- scripts/load.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/load.py b/scripts/load.py index 8710880..d3d9965 100644 --- a/scripts/load.py +++ b/scripts/load.py @@ -67,7 +67,8 @@ def __init__(self, addon: str, addon_dir: str = os.path.abspath("./local_addon/" Init method of the class. Args: - addon (sstr): absolute path to the addon (zip file) + addon (str): absolute path to the addon (zip file). + addon_dir (str, optional): absolute path to the local addon path. Defaults to: os.path.abspath("./local_addon/"). """ self.root = Path(__file__).parent.parent @@ -81,7 +82,7 @@ def pytest_configure(self, config: dict): Configure pytest. Args: - config (dict): configuration + config (dict): configuration. """ print("PyTest configure...") @@ -112,10 +113,11 @@ def pytest_unconfigure(self): # TODO: find a better fix to "[WinError 5] Access denied: # '[....]\\local_addon\\addons\\animation_nodes\\algorithms\\hashing\\murmurhash3.cp39-win_amd64.pyd'" try: - an_path = os.environ.get(f"{PAU.ANIMATION_NODES['module']}_module", None) - BAT.cleanup(None, an_path, os.path.join(self.addon_dir, "addons", an_path)) + an_module = os.environ.get(f"{PAU.ANIMATION_NODES['module']}_module", None) + an_local_addon_path = os.path.join(self.addon_dir, "addons", an_module) + BAT.cleanup(None, an_module, an_local_addon_path) except BaseException as exception: - print(f"{TERM.LIGHT_YELLOW}WARNING: failed to clean animation_nodes directory ({an_path}).{TERM.RESET}") + print(f"{TERM.LIGHT_YELLOW}WARNING: failed to clean animation_nodes directory ({an_local_addon_path}).{TERM.RESET}") print("PyTest unconfigure successful!") From 4deda53bd375df9b2e962d15941d0a45a404303c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Sun, 27 Nov 2022 14:15:47 +0100 Subject: [PATCH 18/26] [Test] Fiixed small issue --- scripts/load.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/load.py b/scripts/load.py index d3d9965..34c61a5 100644 --- a/scripts/load.py +++ b/scripts/load.py @@ -68,7 +68,8 @@ def __init__(self, addon: str, addon_dir: str = os.path.abspath("./local_addon/" Args: addon (str): absolute path to the addon (zip file). - addon_dir (str, optional): absolute path to the local addon path. Defaults to: os.path.abspath("./local_addon/"). + addon_dir (str, optional): absolute path to the local addon path. + Defaults to: os.path.abspath("./local_addon/"). """ self.root = Path(__file__).parent.parent @@ -117,7 +118,9 @@ def pytest_unconfigure(self): an_local_addon_path = os.path.join(self.addon_dir, "addons", an_module) BAT.cleanup(None, an_module, an_local_addon_path) except BaseException as exception: - print(f"{TERM.LIGHT_YELLOW}WARNING: failed to clean animation_nodes directory ({an_local_addon_path}).{TERM.RESET}") + print(f"{TERM.LIGHT_YELLOW}WARNING: failed to clean animation_nodes \ +directory ({an_local_addon_path}).{TERM.RESET}") + print(exception) print("PyTest unconfigure successful!") From 6e8aa500db8805b8edac54b37ef3356502a1ce52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Sun, 27 Nov 2022 15:43:36 +0100 Subject: [PATCH 19/26] [Test] Added 'local_addon' in .gitignore --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0d1c5ff..55eaba4 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,7 @@ cache/ # Blender *.pyc -*.blend[1-9] \ No newline at end of file +*.blend[1-9] + +# Tests +local_addon/ \ No newline at end of file From db8816ac8ba919ab15239f601e585aad029a4c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Sun, 12 Feb 2023 14:04:29 +0100 Subject: [PATCH 20/26] [Doc] Updated make.bat script. Now can build doc on windows. --- docs/Makefile | 2 +- docs/make.bat | 23 ++++++++++------------- docs/replace_matching_string_in_files.ps1 | 23 +++++++++++++++++++++++ 3 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 docs/replace_matching_string_in_files.ps1 diff --git a/docs/Makefile b/docs/Makefile index 2faefb6..e67895c 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,4 +1,4 @@ -# Minimal makefile for Sphinx documentation +# Makefile for Sphinx documentation # You can set these variables from the command line, and also # from the environment for the first two. diff --git a/docs/make.bat b/docs/make.bat index 9534b01..90ec63a 100644 --- a/docs/make.bat +++ b/docs/make.bat @@ -4,28 +4,25 @@ pushd %~dp0 REM Command file for Sphinx documentation -if "%SPHINXBUILD%" == "" ( +if "%2" == "" ( set SPHINXBUILD=sphinx-build +) else ( + set SPHINXBUILD=%2 ) + set SOURCEDIR=source set BUILDDIR=build +set MODULE=quantum_nodes if "%1" == "" goto help -%SPHINXBUILD% >NUL 2>NUL -if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.http://sphinx-doc.org/ - exit /b 1 -) +move "../%MODULE%/__init__.py" "../%MODULE%/___init__.py" +powershell -ExecutionPolicy ByPass -command ". replace_matching_string_in_files.ps1 -find '@persistent' -replace '#@persistent';" %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +powershell -ExecutionPolicy ByPass -command ". replace_matching_string_in_files.ps1 -find '#@persistent' -replace '@persistent';" +move "../%MODULE%/___init__.py" "../%MODULE%/__init__.py" goto end :help diff --git a/docs/replace_matching_string_in_files.ps1 b/docs/replace_matching_string_in_files.ps1 new file mode 100644 index 0000000..2f77443 --- /dev/null +++ b/docs/replace_matching_string_in_files.ps1 @@ -0,0 +1,23 @@ +# Replace matching strings with another string in the given list of files +param( + [string]$folder = "../quantum_nodes/", + [string]$find = "@persistent", + [string]$replace = "#@persistent" +) + +[array]$files = Get-ChildItem -Path $folder -Include *.py -Recurse -Force | select -expand fullname + +function Replace-Strings-In-Files { + + param( + [array]$files, + [string]$find, + [string]$replace + ) + + ForEach ($file in $files) { + (Get-Content -Path $file -Raw) -replace $find, $replace | Set-Content -Path $file -NoNewLine + } +} + +Replace-Strings-In-Files $files $find $replace \ No newline at end of file From aaff2b6f97d71b73da5010285ecf3e9de655bce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Sun, 12 Feb 2023 14:29:01 +0100 Subject: [PATCH 21/26] [CI/CD] Updated actions plugins versions --- .github/workflows/docs.yml | 16 ++++++++-------- .github/workflows/style.yml | 4 ++-- .github/workflows/unit-testing.yml | 10 +++++----- .pre-commit-config.yaml | 4 ++-- scripts/test.py | 3 +-- scripts/utils.py | 4 ++-- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 5129b6c..aeb7c19 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -24,13 +24,13 @@ jobs: name: Build documentation runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.5.0 + - uses: actions/checkout@v3.3.0 - - uses: actions/setup-python@v4.3.0 + - uses: actions/setup-python@v4.5.0 with: python-version: "3.10" - - uses: syphar/restore-virtualenv@v1.2 + - uses: syphar/restore-virtualenv@v1.3 id: cache-virtualenv with: requirement_files: requirements.txt @@ -45,7 +45,7 @@ jobs: run: pip install -r requirements.txt - name: Cache docs build directory - uses: actions/cache@v3.0.11 + uses: actions/cache@v3.2.5 if: env.USE_CACHE == 'true' with: path: docs/build/ @@ -53,7 +53,7 @@ jobs: - name: Cache animation nodes source code id: animation-nodes-source-code - uses: actions/cache@v3.0.11 + uses: actions/cache@v3.2.5 if: env.USE_CACHE == 'true' with: path: animation_nodes/ @@ -94,7 +94,7 @@ jobs: cp -r docs/build/html build_docs zip -r build_docs build_docs - - uses: actions/upload-artifact@v3.1.1 + - uses: actions/upload-artifact@v3.1.2 if: env.DEPLOY == 'true' with: name: build_docs @@ -106,9 +106,9 @@ jobs: needs: build if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags') steps: - - uses: actions/checkout@v2.5.0 + - uses: actions/checkout@v3.3.0 - - uses: actions/download-artifact@v3.0.1 + - uses: actions/download-artifact@v3.0.2 with: name: build_docs path: . diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 504574a..6c838bc 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -14,9 +14,9 @@ jobs: stylecheck: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.5.0 + - uses: actions/checkout@v3.3.0 - - uses: actions/setup-python@v4.3.0 + - uses: actions/setup-python@v4.5.0 with: python-version: "3.10" diff --git a/.github/workflows/unit-testing.yml b/.github/workflows/unit-testing.yml index 7b15b5a..cad34f3 100644 --- a/.github/workflows/unit-testing.yml +++ b/.github/workflows/unit-testing.yml @@ -15,25 +15,25 @@ jobs: max-parallel: 4 fail-fast: false matrix: - blender-version: ["2.93.11", "3.3.1",] + blender-version: ["2.93.11", "3.4.1",] os: ["ubuntu-latest", "windows-latest",] env: BLENDER_CACHE: ${{ github.workspace }}/cache # The place where blender releases are downloaded BLENDER_VERSION: ${{ matrix.blender-version }} steps: - - uses: actions/checkout@v2.5.0 + - uses: actions/checkout@v3.3.0 - - uses: actions/setup-python@v4.3.0 + - uses: actions/setup-python@v4.5.0 with: python-version: "3.10" - - uses: syphar/restore-virtualenv@v1.2 + - uses: syphar/restore-virtualenv@v1.3 id: cache-virtualenv with: requirement_files: requirements.txt - name: Cache Blender release download - uses: actions/cache@v3.0.11 + uses: actions/cache@v3.2.5 with: path: ${{ env.BLENDER_CACHE }} key: ${{ matrix.os }}-blender-${{ matrix.blender-version }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fd6efc0..9bcad7a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pycqa/flake8 - rev: 5.0.4 + rev: 6.0.0 hooks: - id: flake8 additional_dependencies: [ @@ -16,7 +16,7 @@ repos: ] - repo: https://github.com/pycqa/pydocstyle - rev: 6.1.1 + rev: 6.3.0 hooks: - id: pydocstyle exclude: quantum_nodes/lib/quantumblur.py diff --git a/scripts/test.py b/scripts/test.py index 3fa01af..08ce169 100644 --- a/scripts/test.py +++ b/scripts/test.py @@ -35,8 +35,7 @@ system = args.os if not any(system == supported_os for supported_os in ['macos-latest', 'ubuntu-latest', 'windows-latest']): - print(f"{TERM.LIGHT_RED}ERROR: -os option must be one of: \ -['macos-latest', 'ubuntu-latest', 'windows-latest'].{TERM.RESET}") + print(f"{TERM.LIGHT_RED}ERROR: -os option must be one of: ['macos-latest', 'ubuntu-latest', 'windows-latest'].{TERM.RESET}") # noqa: E501 parser.parse_args(['-h']) module = "quantum_nodes" diff --git a/scripts/utils.py b/scripts/utils.py index 7118a8e..6a9c896 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -21,11 +21,11 @@ ) parser.add_argument( "-os", - metavar="Targeted operating system", + metavar="Operating system", type=str, nargs='?', default="ubuntu", - help="Targeted operating system on which to run the test suite. Must be one of: ['macos-latest', 'ubuntu-latest', 'windows-latest']." # noqa: E501 + help="Operating system on which to run tests: ['macos-latest', 'ubuntu-latest', 'windows-latest']." ) From 4df9cdf807766ea8340c8315ecc6756a11236c18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Sun, 12 Feb 2023 15:29:10 +0100 Subject: [PATCH 22/26] [Tests] Try to fix python modules not found unit test env install --- .pre-commit-config.yaml | 4 ++-- quantum_nodes/__init__.py | 28 +++++++++------------------- scripts/load.py | 8 +++++++- scripts/requirements.txt | 14 ++++++++++++++ scripts/utils.py | 9 ++++++--- 5 files changed, 38 insertions(+), 25 deletions(-) create mode 100644 scripts/requirements.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9bcad7a..2bee47b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,10 +1,10 @@ repos: - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 + rev: 5.0.4 hooks: - id: flake8 additional_dependencies: [ - "flake8-quotes==3.3.1", + "flake8-quotes==3.3.2", ] - repo: https://github.com/codespell-project/codespell diff --git a/quantum_nodes/__init__.py b/quantum_nodes/__init__.py index 82f62d3..7163655 100644 --- a/quantum_nodes/__init__.py +++ b/quantum_nodes/__init__.py @@ -1,22 +1,7 @@ -""" -Copyright (C) 2021-2022 Quantum Creative Group.\ -contact@quantum-nodes.com. - -Created by Quantum-Creative-Group - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -""" +import os +import sys +import site +from pathlib import Path bl_info = { "name": "Quantum Nodes", @@ -31,6 +16,11 @@ "category": "Node", } +# 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")) + import addon_utils from . import auto_load diff --git a/scripts/load.py b/scripts/load.py index 34c61a5..f213b6f 100644 --- a/scripts/load.py +++ b/scripts/load.py @@ -2,8 +2,14 @@ import os import sys +import site 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")) + # Make utils.py functions available in this file sys.path.append(os.path.abspath(".")) @@ -50,7 +56,7 @@ print(f"{TERM.LIGHT_YELLOW}Missing module...{TERM.RESET}", e) print(f"{TERM.LIGHT_YELLOW}Trying to install missing dependencies...{TERM.RESET}") try: - PAU.install_py_requirements(os.path.join(os.path.abspath("."), "requirements.txt"), force=True) + PAU.install_py_requirements(os.path.join(os.path.abspath("./scripts"), "requirements.txt")) except Exception as e: print(e) sys.exit(1) diff --git a/scripts/requirements.txt b/scripts/requirements.txt new file mode 100644 index 0000000..e074c00 --- /dev/null +++ b/scripts/requirements.txt @@ -0,0 +1,14 @@ +# Requirements for unit tests +wheel +pyenchant +myst-parser + +blender-addon-tester +pytest + +scipy +numpy +pillow +qiskit +qiskit-finance +qiskit-machine-learning \ No newline at end of file diff --git a/scripts/utils.py b/scripts/utils.py index 6a9c896..a875881 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -87,7 +87,7 @@ def get_python_version(cls, blender: str) -> str: if any(version in blender for version in ["2.9", "3.0"]): return "39" - if any(version in blender for version in ["3.1", "3.2", "3.3"]): + if any(version in blender for version in ["3.1", "3.2", "3.3", "3.4"]): return "310" raise ValueError(f"Unable to determine which python version is used by the given blender version ({blender})") @@ -101,7 +101,8 @@ def install_py_package(cls, package: str, force: bool = False) -> None: package (str): name of the package. force (bool, optional): force reinstall. Defaults to False. """ - args = [sys.executable, "-m", "pip", "install", package] + + args = [sys.executable, "-m", "pip", "install", package, "--user"] if force: args.append("--force-reinstall") subprocess.check_call(args) @@ -115,7 +116,8 @@ def install_py_requirements(cls, requirements: str, force: bool = False) -> None requirements (str): path to the requirements file. 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) @@ -129,6 +131,7 @@ def install_local_py_package(cls, path: str, force: bool = False) -> None: path (str): path to the folder of the local package. force (bool, optional): force reinstall. Defaults to False. """ + args = [sys.executable, "-m", "pip", "install", "-e", path] if force: args.append("--force-reinstall") From 2c14349b9eb73a8f0f9cb95eecc7ecb17a2f3376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Sun, 12 Feb 2023 16:59:49 +0100 Subject: [PATCH 23/26] [Test] Add user scripts and site-packages folder to sys.path --- scripts/load.py | 10 +++------- scripts/test.py | 2 ++ scripts/utils.py | 11 +++++++++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/scripts/load.py b/scripts/load.py index f213b6f..2f9ea95 100644 --- a/scripts/load.py +++ b/scripts/load.py @@ -2,14 +2,8 @@ import os import sys -import site 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")) - # Make utils.py functions available in this file sys.path.append(os.path.abspath(".")) @@ -41,6 +35,8 @@ # + INSTALL REQUIREMENTS + # +----------------------+ +PAU.load_default_user_folders() + try: import PIL import scipy @@ -56,7 +52,7 @@ print(f"{TERM.LIGHT_YELLOW}Missing module...{TERM.RESET}", e) print(f"{TERM.LIGHT_YELLOW}Trying to install missing dependencies...{TERM.RESET}") try: - PAU.install_py_requirements(os.path.join(os.path.abspath("./scripts"), "requirements.txt")) + PAU.install_py_requirements(os.path.join(os.path.abspath("./scripts"), "requirements.txt"), force=True) except Exception as e: print(e) sys.exit(1) diff --git a/scripts/test.py b/scripts/test.py index 08ce169..2bac24c 100644 --- a/scripts/test.py +++ b/scripts/test.py @@ -11,6 +11,8 @@ print(f"{TERM.LIGHT_BLUE}{TERM.centered_str(' TEST SUITE: START ', '=')}{TERM.RESET}") +PAU.load_default_user_folders() + # Check that blender-addon-tester is installed try: import blender_addon_tester as BAT diff --git a/scripts/utils.py b/scripts/utils.py index a875881..a4a71be 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -2,12 +2,14 @@ import os import sys +import site import shutil import fnmatch import zipfile import requests import argparse import subprocess +from pathlib import Path # Parser for test.py parser = argparse.ArgumentParser(description="Add-on test suite") @@ -72,6 +74,15 @@ class PackageAndAddonUtils: "macos-latest": "https://github.com/JacquesLucke/animation_nodes/releases/download/master-cd-build/animation_nodes_v2_3_macOS", # noqa: E501 } + @classmethod + def load_default_user_folders(cls): + # Add user default folders where pip will install some of the dependencies + # This is because some folders may not be writable + USER_SITE = site.getusersitepackages() + sys.path.append(os.path.abspath(USER_SITE)) + sys.path.append(os.path.join(os.path.abspath(Path(USER_SITE).parent), "Scripts")) + print(sys.path) + @classmethod def get_python_version(cls, blender: str) -> str: """ From 1fba4b0e7d16fc96b5c4763681d56dae54b0cade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Sun, 12 Feb 2023 17:46:00 +0100 Subject: [PATCH 24/26] [Tests] Reload list of available python modules during setup tests suite --- scripts/load.py | 5 +++-- scripts/test.py | 2 +- scripts/utils.py | 6 ++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/load.py b/scripts/load.py index 2f9ea95..00ab453 100644 --- a/scripts/load.py +++ b/scripts/load.py @@ -35,7 +35,7 @@ # + INSTALL REQUIREMENTS + # +----------------------+ -PAU.load_default_user_folders() +PAU.reload_available_modues() try: import PIL @@ -52,7 +52,8 @@ print(f"{TERM.LIGHT_YELLOW}Missing module...{TERM.RESET}", e) print(f"{TERM.LIGHT_YELLOW}Trying to install missing dependencies...{TERM.RESET}") try: - PAU.install_py_requirements(os.path.join(os.path.abspath("./scripts"), "requirements.txt"), force=True) + PAU.install_py_requirements(os.path.join(os.path.abspath("./scripts"), "requirements.txt")) + PAU.reload_available_modues() except Exception as e: print(e) sys.exit(1) diff --git a/scripts/test.py b/scripts/test.py index 2bac24c..2a688c6 100644 --- a/scripts/test.py +++ b/scripts/test.py @@ -11,7 +11,7 @@ print(f"{TERM.LIGHT_BLUE}{TERM.centered_str(' TEST SUITE: START ', '=')}{TERM.RESET}") -PAU.load_default_user_folders() +PAU.reload_available_modues() # Check that blender-addon-tester is installed try: diff --git a/scripts/utils.py b/scripts/utils.py index a4a71be..6f5d284 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -10,6 +10,7 @@ import argparse import subprocess from pathlib import Path +from importlib import invalidate_caches # Parser for test.py parser = argparse.ArgumentParser(description="Add-on test suite") @@ -75,13 +76,14 @@ class PackageAndAddonUtils: } @classmethod - def load_default_user_folders(cls): + def reload_available_modues(cls): # Add user default folders where pip will install some of the dependencies # This is because some folders may not be writable USER_SITE = site.getusersitepackages() sys.path.append(os.path.abspath(USER_SITE)) sys.path.append(os.path.join(os.path.abspath(Path(USER_SITE).parent), "Scripts")) - print(sys.path) + # Force to reload list of available modules and packages + invalidate_caches() @classmethod def get_python_version(cls, blender: str) -> str: From 204501b9889f2d3bef1e2da5363d1febe78116d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Sun, 19 Feb 2023 11:29:01 +0100 Subject: [PATCH 25/26] [Docs] Updated instructions developers manual --- .../source/developers_manual/manual/index.rst | 100 ++++++++++++++++-- .../source/developers_manual/manual/linux.rst | 34 ------ docs/source/developers_manual/manual/mac.rst | 4 - .../source/developers_manual/manual/tools.rst | 61 ----------- .../developers_manual/manual/windows.rst | 45 -------- 5 files changed, 90 insertions(+), 154 deletions(-) delete mode 100644 docs/source/developers_manual/manual/linux.rst delete mode 100644 docs/source/developers_manual/manual/mac.rst delete mode 100644 docs/source/developers_manual/manual/tools.rst delete mode 100644 docs/source/developers_manual/manual/windows.rst diff --git a/docs/source/developers_manual/manual/index.rst b/docs/source/developers_manual/manual/index.rst index ee32df1..af33d9b 100644 --- a/docs/source/developers_manual/manual/index.rst +++ b/docs/source/developers_manual/manual/index.rst @@ -2,24 +2,31 @@ Contribute to the manual ======================== -.. _dev-env-contrib-manual: +* :ref:`development-environment-contrib-manual` +* :ref:`tools-contrib-manual` +* :ref:`guidelines-contrib-manual` +* :ref:`git-workflow-contrib-manual` + +.. _development-environment-contrib-manual: Development environment *********************** -.. toctree:: - :maxdepth: 1 - linux - windows - mac - tools +Install dependencies +-------------------- + + +.. important:: + Make sure to install the dependencies in an appropriate python environment. + For example, you can use the one which comes with Blender. -.. _intructions-linux-contrib-manual: +| Run: ``pip install -r requirements.txt`` + Contribute -********** +---------- .. note:: @@ -32,7 +39,80 @@ Contribute * Wait for your modifications to be reviewed and accepted -.. _guidelines-contrib-addon: +Build the manual +---------------- + +* Clone the `quantum_nodes `_ repository. + +* | Open a terminal and go in the ``docs`` folder: ``cd docs`` + | Then type: ``make html`` (or ``make.bat html`` on Windows) + | Visualize the html in ``build/html`` + + +.. _tools-contrib-manual: + +Tools +***** + +Here is a list of tools which will help you to write documentation. + +#. :ref:`tools-vs-code-extensions` + #. :ref:`tools-pydocstring-generator-vscode` + #. :ref:`tools-rst-vscode` + + +.. _tools-vs-code-extensions: + +VSCode extensions +----------------- + + +.. _tools-pydocstring-generator-vscode: + +Python Docstring Generator +########################## + + +.. note:: + Automatically generates the right docstring format for methods / functions / classes ... + + +* Install `python docstring generator `_ + +* Select the ``sphinx`` format for the auto docstring functionality + +.. image:: /images/contrib-tools/docstring_format.png + :width: 85% + :alt: Python Docstring Generator, auto docstring sphinx + :align: center + :class: img-rounded + +| + +.. _tools-rst-vscode: + +reStructuredText Syntax highlighting +#################################### + + +.. note:: + Syntax highlighting and document symbols for reStructuredText + + +* Install `reStructuredText syntax highlighting `_ +* This extension uses `Esbonio `_ +* Select the right output for sphinx-build in the settings: + +.. image:: /images/contrib-tools/esbonio_output_sphinx_build.png + :width: 85% + :alt: reStructuredText syntax highlighting, set output path sphinx-build + :align: center + :class: img-rounded + +| + + +.. _guidelines-contrib-manual: Guidelines ********** diff --git a/docs/source/developers_manual/manual/linux.rst b/docs/source/developers_manual/manual/linux.rst deleted file mode 100644 index d5180cf..0000000 --- a/docs/source/developers_manual/manual/linux.rst +++ /dev/null @@ -1,34 +0,0 @@ -Linux -===== - - -.. important:: - This tutorial is written for Ubuntu - - -.. _dev-env-ide-contrib-manual: - -IDE -### - -* We recommend you to use `Visual Studio Code `_. -* See :ref:`tools-contrib-manual` for more information. - - -.. _dependencies-linux-contrib-manual: - -Dependencies -############ - -| Install using: ``pip install -r requirements.txt`` - - -.. _build-linux-contrib-manual: - -Build the manual -################ - -* Clone the repository next to the `quantum_nodes` repository. - -* | Open a terminal and enter: ``make html spelling`` - | Visualize the html in ``build/html`` \ No newline at end of file diff --git a/docs/source/developers_manual/manual/mac.rst b/docs/source/developers_manual/manual/mac.rst deleted file mode 100644 index 10b210f..0000000 --- a/docs/source/developers_manual/manual/mac.rst +++ /dev/null @@ -1,4 +0,0 @@ -Mac -=== - -TODO \ No newline at end of file diff --git a/docs/source/developers_manual/manual/tools.rst b/docs/source/developers_manual/manual/tools.rst deleted file mode 100644 index 3f06d3e..0000000 --- a/docs/source/developers_manual/manual/tools.rst +++ /dev/null @@ -1,61 +0,0 @@ -.. _tools-contrib-manual: - -Tools -===== - -Here is a list of tools which will help you to write documentation. - -#. :ref:`vs-code-extensions` - #. :ref:`pydocstring-generator-vscode` - #. :ref:`rst-vscode` - - -.. _vs-code-extensions: - -VSCode extensions -################# - - -.. _pydocstring-generator-vscode: - -Python Docstring Generator -************************** - - -.. note:: - Automatically generates the right docstring format for methods / functions / classes ... - - -* Install `python docstring generator `_ - -* Select the ``sphinx`` format for the auto docstring functionality - -.. image:: /images/contrib-tools/docstring_format.png - :width: 85% - :alt: Python Docstring Generator, auto docstring sphinx - :align: center - :class: img-rounded - -| - -.. _rst-vscode: - -reStructuredText Syntax highlighting -************************************ - - -.. note:: - Syntax highlighting and document symbols for reStructuredText - - -* Install `reStructuredText syntax highlighting `_ -* This extension uses `Esbonio `_ -* Select the right output for sphinx-build in the settings: - -.. image:: /images/contrib-tools/esbonio_output_sphinx_build.png - :width: 85% - :alt: reStructuredText syntax highlighting, set output path sphinx-build - :align: center - :class: img-rounded - -| \ No newline at end of file diff --git a/docs/source/developers_manual/manual/windows.rst b/docs/source/developers_manual/manual/windows.rst deleted file mode 100644 index 77c292d..0000000 --- a/docs/source/developers_manual/manual/windows.rst +++ /dev/null @@ -1,45 +0,0 @@ -Windows -======= - - -#. :ref:`install-dependencies-windows-contrib-manual` -#. :ref:`intructions-windows-contrib-manual` -#. :ref:`build-windows-contrib-manual` - - -.. _install-dependencies-windows-contrib-manual: - -Install dependencies -#################### - - -.. important:: - Make sure to install the dependencies in the right anaconda environment. - - -| ``pip install -r requirements.txt`` - -.. _intructions-windows-contrib-manual: - -Contribute -########## - - -.. note:: - Click `here `_ to learn about the forking workflow on Github. - - -* Fork the repository: https://github.com/Quantum-Creative-Group/quantum_nodes -* Do your modifications -* Once you are ready, open a new `pull request `_ -* Wait for your modifications to be reviewed and accepted - -.. _build-windows-contrib-manual: - -Build the manual -################ - -* Clone the repository next to the `quantum_nodes` repository. - -* | Open a terminal and enter: ``make html spelling`` - | Visualize the html in ``build/html`` \ No newline at end of file From 5729948bb0d46bf76a59666d4f252b4bc1eae673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix?= Date: Sun, 19 Feb 2023 19:07:19 +0100 Subject: [PATCH 26/26] [Docs] New tutorials to setup dev-env (add-on + manual) --- docs/replace_matching_string_in_files.ps1 | 4 +- docs/source/developers_manual/addon/index.rst | 48 --- docs/source/developers_manual/addon/linux.rst | 183 ---------- docs/source/developers_manual/addon/mac.rst | 6 - docs/source/developers_manual/addon/tools.rst | 28 -- .../developers_manual/addon/windows.rst | 6 - docs/source/developers_manual/index.rst | 47 ++- .../source/developers_manual/instructions.rst | 317 ++++++++++++++++++ .../source/developers_manual/manual/index.rst | 254 -------------- docs/source/developers_manual/tools.rst | 75 +++++ scripts/setup_animation_nodes.ps1 | 29 ++ 11 files changed, 465 insertions(+), 532 deletions(-) delete mode 100644 docs/source/developers_manual/addon/index.rst delete mode 100644 docs/source/developers_manual/addon/linux.rst delete mode 100644 docs/source/developers_manual/addon/mac.rst delete mode 100644 docs/source/developers_manual/addon/tools.rst delete mode 100644 docs/source/developers_manual/addon/windows.rst create mode 100644 docs/source/developers_manual/instructions.rst delete mode 100644 docs/source/developers_manual/manual/index.rst create mode 100644 docs/source/developers_manual/tools.rst create mode 100644 scripts/setup_animation_nodes.ps1 diff --git a/docs/replace_matching_string_in_files.ps1 b/docs/replace_matching_string_in_files.ps1 index 2f77443..9aa46c1 100644 --- a/docs/replace_matching_string_in_files.ps1 +++ b/docs/replace_matching_string_in_files.ps1 @@ -7,7 +7,7 @@ param( [array]$files = Get-ChildItem -Path $folder -Include *.py -Recurse -Force | select -expand fullname -function Replace-Strings-In-Files { +function Find-And-Replace-Strings { param( [array]$files, @@ -20,4 +20,4 @@ function Replace-Strings-In-Files { } } -Replace-Strings-In-Files $files $find $replace \ No newline at end of file +Find-And-Replace-Strings $files $find $replace \ No newline at end of file diff --git a/docs/source/developers_manual/addon/index.rst b/docs/source/developers_manual/addon/index.rst deleted file mode 100644 index f8ba235..0000000 --- a/docs/source/developers_manual/addon/index.rst +++ /dev/null @@ -1,48 +0,0 @@ -Contribute to Quantum Nodes -=========================== - - -.. _dev-env-contrib-addon: - -Development environment -####################### - - -.. toctree:: - :maxdepth: 1 - :glob: - - linux - windows - mac - tools - - -.. _instructions-contrib-addon: - -Contribute -########## - - -.. note:: - Click `here `_ to learn about the forking workflow on Github. - - -* Fork our `git repository `_ -* Do your modifications -* Open a new `pull request `_ -* Wait for your modifications to be reviewed and accepted - - -.. _git-workflow-contrib-addon: - -Git workflow -############ - -.. image:: https://miro.medium.com/max/560/1*UH5ozOBwkaFhWA1mrJkVIQ.png - :alt: Git workflow - :align: center - :width: 80% - :class: img-rounded - -| \ No newline at end of file diff --git a/docs/source/developers_manual/addon/linux.rst b/docs/source/developers_manual/addon/linux.rst deleted file mode 100644 index f645444..0000000 --- a/docs/source/developers_manual/addon/linux.rst +++ /dev/null @@ -1,183 +0,0 @@ -.. _linux-contrib-addon: - -Linux -===== - -.. note:: - - This tutorial will help you to setup a full development environment for ubuntu. - - -.. _linux-dev-env-downloads-contrib-addon: - -Downloads -######### - - -.. _linux-dev-env-downloads-blender-contrib-addon: - -Blender -******* - -* | First, we need to download a portable version of Blender. - | Download a version from here: https://www.blender.org/download/. - - -.. _linux-dev-env-downloads-animation-nodes-contrib-addon: - -Animation Nodes -*************** - -* | Before downloading Animation Nodes, we need to know which python version is shipped with the - | chosen Blender version. We can get it by looking at the files (from the archive) located - | at: ``blender[...]/[X.Y]/python/bin/``. - | For Blender >= 2.93.0, it will probably be something between python 3.9 and 3.10. - -* | Once we know that, we have to download the add-on from the release page of - | Animation Nodes (take latest): https://github.com/JacquesLucke/animation_nodes/releases/tag/master-cd-build. - - -.. _linux-dev-env-downloads-quantum-nodes-contrib-addon: - -Quantum Nodes -************* - -* Make a fork of the repository: https://github.com/Quantum-Creative-Group/quantum_nodes/fork. -* Then, clone the forked repository on your computer. - - -.. _linux-dev-env-downloads-ide-contrib-addon: - -IDE -*** - -* We recommend to use `Visual Studio Code `_. -* See :ref:`tools-dev-addon` for more information. - - -.. _linux-dev-env-installations-contrib-addon: - -Installations -############# - - -.. note:: - - Since Blender comes with its own python environment, we will use this one as our development environment too. - - -.. _linux-dev-env-installations-blender-contrib-addon: - -Blender -******* - -* | Decompress the downloaded archive which contains the blender version. - | We can place these files where we want. However, we recommend to place them in the ``/opt/`` folder. - -* Run Blender at least one time to make sure it works fine. - - -.. _linux-dev-env-installations-python-contrib-addon: - -Python dependencies -******************* - -We need to run the installation from the python distribution of Blender. For that, we need the path to the python -executable. We can find it here: ``path/to/blender/files/ .... /[X.Y]/python/bin/python3.X``. - -.. note:: - - | Since we will need to reference this several times, we can add an alias in the ``.bash_aliases`` file located - | in the ``home/[username]/`` directory (create the file if it does not exist). - | Example: ``alias pythonb=/opt/blender-3.0.1-linux-x64/3.0/python/bin/python3.9`` - -* Go to the ``quantum_nodes/`` directory. -* Run ``path/to/blender/files/ .... /[X.Y]/python/bin/python3.X -m pip install -r requirements.txt``. - - -.. _linux-dev-env-installations-animation-nodes-contrib-addon: - -Animation Nodes -*************** - -In this part we will install the add-on for Blender and copy the content of the ``animation_nodes/`` folder in the -blender python distribution so it will be available for our different scripts (documentation build and test suite). - -Installation in Blender: - -* Install the add-on inside Blender (as in the :ref:`installation guide `). -* Make sure it works fine. - -Installation for the IDE and the python scripts: - -* Extract the ``animation_nodes/`` folder from the archive. -* | Run the following bash script ``scripts/setup_animation_nodes.sh``. You need to provide several information in order - | to run the script correctly. - | -> The path to the ``site-packages/`` folder in the python distribution shipped with Blender. - | -> The path to the ``animation_nodes/`` folder previously extracted. - | -> The path to the ``quantum_nodes/`` folder. - | Example: - | ``bash scripts/setup_animation_nodes.sh /opt/blender-3.0.1-linux-x64/3.0/python/lib/python3.9/site-packages/ ~/Documents/animation_nodes/ ~/Documents/quantum_nodes/`` - - -.. _linux-dev-env-build-and-test-contrib-addon: - -Build and test -############## - -.. note:: - - Before following the next instructions, please install and configure the recommended Visual Studio Code - extensions cited in :ref:`this section `. - - -.. _linux-dev-env-build-and-test-run-from-vscode-contrib-addon: - -Run Quantum Nodes from Visual Studio Code -***************************************** - -The `Blender Development` extension let us to quickly run Blender with the modifications made to the add-on -on which we are currently working. It runs Blender in a sort of 'debug' mode to test our add-on. - -* In VSCode, hit ``ctrl + shift + p`` and type ``blender start``. Then, hit ``enter``. -* If no blender executable was previously set, follow the instructions given by the extension. -* Wait for Blender to start. -* Once ready, edit code in live and save files to apply changes (it reloads the add-on automatically). - - -.. _linux-dev-env-build-and-test-build-documentation-contrib-addon: - -Build the documentation -*********************** - -Generate automatic code documentation: - - -.. note:: - - This step is not mandatory to build the documentation. You can skip it if you don't need this part - in your local build. - - -* Go in the ``quantum_nodes/docs/`` folder. -* | Run: - | ``path/to/blender/files/ .... /[X.Y]/python/bin/sphinx-apidoc -t "_templates/" --implicit-namespaces -d 1 -f -M -T -o source/developers_manual/code/ ../quantum_nodes "/*animation_nodes/*" "/*lib/*"`` - | Next commands are optional: - | ``sed -i "1s/.*/Code documentation/" source/developers_manual/code/quantum_nodes.rst`` - | ``sed -i "2s/.*/==================/" source/developers_manual/code/quantum_nodes.rst`` - -Build the documentation: - -* Go in the ``quantum_nodes/docs/`` folder. -* Run: ``make html SPHINXBUILD=path/to/blender/files/ .... /[X.Y]/python/bin/sphinx-build`` -* The build is then available in the following folder: ``quantum_nodes/docs/build/``. - - -.. _linux-dev-env-build-and-test-run-test-suite-contrib-addon: - -Run the test suite -****************** - -* Go in the ``quantum_nodes/`` folder. -* Run: ``path/to/blender/files/ .... /[X.Y]/python/bin/python3.X -m scripts.test -b [blender version] -os [operating system]`` -* Example: ``path/to/blender/files/ .... /[X.Y]/python/bin/python3.X -m scripts.test -b 3.0.0 -os ubuntu-latest`` \ No newline at end of file diff --git a/docs/source/developers_manual/addon/mac.rst b/docs/source/developers_manual/addon/mac.rst deleted file mode 100644 index b40cacd..0000000 --- a/docs/source/developers_manual/addon/mac.rst +++ /dev/null @@ -1,6 +0,0 @@ -.. _mac-contrib-addon: - -Mac -=== - -TODO \ No newline at end of file diff --git a/docs/source/developers_manual/addon/tools.rst b/docs/source/developers_manual/addon/tools.rst deleted file mode 100644 index ae2cc88..0000000 --- a/docs/source/developers_manual/addon/tools.rst +++ /dev/null @@ -1,28 +0,0 @@ -.. _tools-dev-addon: - -Tools -===== - -Here is a list of tools which will help you to develop. - -* :ref:`vs-code-extensions-addon` - * :ref:`blender-vscode` - - -.. _vs-code-extensions-addon: - -VSCode extensions -################# - - -.. _blender-vscode: - -Blender Development -******************* - - -.. note:: - Tools to simplify Blender development. Developed by `Jacques Lucke `_. - - -* Install `blender development `_ \ No newline at end of file diff --git a/docs/source/developers_manual/addon/windows.rst b/docs/source/developers_manual/addon/windows.rst deleted file mode 100644 index 4c170fb..0000000 --- a/docs/source/developers_manual/addon/windows.rst +++ /dev/null @@ -1,6 +0,0 @@ -.. _windows-contrib-addon: - -Windows -======= - -TODO \ No newline at end of file diff --git a/docs/source/developers_manual/index.rst b/docs/source/developers_manual/index.rst index 90e5f3d..266e991 100644 --- a/docs/source/developers_manual/index.rst +++ b/docs/source/developers_manual/index.rst @@ -1,9 +1,46 @@ -Developers manual -================= +Contribute to Quantum Nodes +=========================== + + +.. _dev-env-contrib-addon: + +Development environment +####################### + .. toctree:: :maxdepth: 1 + :glob: + + instructions + tools + + +.. _contribute-contrib-addon: + +Contribute +########## + + +.. note:: + Click `here `_ to learn about the forking workflow on Github. + + +* Fork our `git repository `_ +* Do your modifications +* Open a new `pull request `_ +* Wait for your modifications to be reviewed and accepted + + +.. _git-workflow-contrib-addon: + +Git workflow +############ + +.. image:: https://miro.medium.com/max/560/1*UH5ozOBwkaFhWA1mrJkVIQ.png + :alt: Git workflow + :align: center + :width: 80% + :class: img-rounded - addon/index - manual/index - code/quantum_nodes \ No newline at end of file +| \ No newline at end of file diff --git a/docs/source/developers_manual/instructions.rst b/docs/source/developers_manual/instructions.rst new file mode 100644 index 0000000..d55aef2 --- /dev/null +++ b/docs/source/developers_manual/instructions.rst @@ -0,0 +1,317 @@ +.. _instructions-contrib-addon: + +Instructions +============ + +.. note:: + + This tutorial will help you to setup a full development environment. + + +#. :ref:`dev-env-downloads-contrib-addon` +#. :ref:`dev-env-installations-contrib-addon` +#. :ref:`dev-env-build-and-test-contrib-addon` +#. :ref:`guidelines-contrib-manual` + +Glossary +######## + +#. | ``pythonblender``: path to python executable which comes with blender. + | Example: ``C:\Users\felix\Documents\blender-3.0.1-windows-x64\3.0\python\bin\python.exe``. +#. | ``sphinx-apidoc``: path to sphinx-apidoc executable. + | Example: ``C:\Users\felix\AppData\Roaming\Python\Python39\Scripts\sphinx-apidoc``. +#. | ``sphinx-build``: path to sphinx-build executable. + | Example: ``C:\Users\felix\AppData\Roaming\Python\Python39\Scripts\sphinx-build``. + +.. _dev-env-downloads-contrib-addon: + +Downloads +######### + + +.. _dev-env-downloads-blender-contrib-addon: + +Blender +******* + +* | First, we need to download a portable version of Blender. + | Download a version from here: https://download.blender.org/release/. + + +.. _dev-env-downloads-animation-nodes-contrib-addon: + +Animation Nodes +*************** + +* | Before downloading Animation Nodes, we need to know which python version is shipped with the + | chosen Blender version. We can get it by looking at the files (from the archive) located + | at: ``blender[...]/[X.Y]/python/bin/``. + | For Blender >= 2.93.0, it will probably be something between python 3.9 and 3.10. + +* | Once we know that, we have to download the add-on from the release page of + | Animation Nodes (take latest): https://github.com/JacquesLucke/animation_nodes/releases/tag/master-cd-build. + + +.. _dev-env-downloads-quantum-nodes-contrib-addon: + +Quantum Nodes +************* + +* Make a fork of the repository: https://github.com/Quantum-Creative-Group/quantum_nodes/fork. +* Then, clone the forked repository on your computer. + + +.. _dev-env-downloads-ide-contrib-addon: + +IDE +*** + +* We recommend to use `Visual Studio Code `_. +* See :ref:`tools-dev-addon` for more information. + + +.. _dev-env-installations-contrib-addon: + +Installations +############# + + +.. note:: + + Since Blender comes with its own python environment, we will use this one as our development environment too. + + +.. _dev-env-installations-blender-contrib-addon: + +Blender +******* + +* | Decompress the downloaded archive which contains the blender version. + | We can place these files where we want. + | ``Linux`` : We recommend you to place them in the ``/opt/`` folder. + | ``Windows`` : We recommend you to place them in the ``Documents/`` folder. + | ``Mac`` : [TODO]. + +* Run Blender at least one time to make sure it works fine. + + +.. _dev-env-installations-python-contrib-addon: + +Python dependencies +******************* + + +* Go to the ``quantum_nodes/`` directory. +* Run ``pythonblender -m pip install -r requirements.txt``. + + +.. _dev-env-installations-animation-nodes-contrib-addon: + +Animation Nodes +*************** + +In this part we will install the add-on for Blender and copy the content of the ``animation_nodes/`` folder in the +blender python distribution so it will be available for our different scripts (documentation build and test suite). + +Installation in Blender: + +* Install the add-on inside Blender (as in the :ref:`installation guide `). +* Make sure it works fine. + +Installation for the IDE and the python scripts: + +* | Extract the ``animation_nodes/`` folder from the archive. + | ``Linux`` : Run the following bash script ``scripts/setup_animation_nodes.sh``. + | ``Windows`` : Run the following bash script ``scripts/setup_animation_nodes.ps1``. + | ``Mac`` : [TODO] +* | You need to provide several information in order to run the script correctly: + | -> The path to the ``site-packages/`` folder in the python distribution shipped with Blender. + | -> The path to the ``animation_nodes/`` folder previously extracted. + | -> The path to the ``quantum_nodes/`` folder. + | Examples: + | ``Linux`` : ``bash scripts/setup_animation_nodes.sh /opt/blender-3.0.1-linux-x64/3.0/python/lib/python3.9/site-packages/ ~/Documents/animation_nodes/ ~/Documents/quantum_nodes/`` + | ``Windows`` : ``scripts/setup_animation_nodes.ps1 -site_packages C:\Users\felix\Documents\blender-3.0.1-windows-x64\3.0\python\lib\site-packages\ -animation_nodes C:\Users\felix\Documents\quantum_nodes\animation_nodes - C:\Users\felix\Documents\quantum_nodes`` + | ``Mac`` : [TODO] + + +.. _dev-env-build-and-test-contrib-addon: + +Build and test +############## + +.. note:: + + Before following the next instructions, please install and configure the recommended Visual Studio Code + extensions cited in :ref:`this section `. + + +.. _dev-env-build-and-test-run-from-vscode-contrib-addon: + +Run Quantum Nodes from Visual Studio Code +***************************************** + +The `Blender Development` extension let us to quickly run Blender with the modifications made to the add-on +on which we are currently working. It runs Blender in a sort of 'debug' mode to test our add-on. + +* In VSCode, hit ``ctrl + shift + p`` and type ``blender start``. Then, hit ``enter``. +* If no blender executable was previously set, follow the instructions given by the extension. +* Wait for Blender to start. +* Once ready, edit code in live and save files to apply changes (it reloads the add-on automatically). + + +.. _dev-env-build-and-test-build-documentation-contrib-addon: + +Build the documentation +*********************** + +Generate automatic code documentation: + + +.. note:: + + This step is not mandatory to build the documentation. You can skip it if you don't need this part + in your local build. + + +* Go in the ``quantum_nodes/docs/`` folder. +* | Run: ``sphinx-apidoc -t "_templates/" --implicit-namespaces -d 1 -f -M -T -o source/developers_manual/code/ ../quantum_nodes "/*animation_nodes/*" "/*lib/*"`` + + +Build the documentation: + +* | Go in the ``quantum_nodes/docs/`` folder. + | Run (``Linux``) : ``make html SPHINXBUILD=sphinx-build`` + | Run (``Windows``) : ``make.bat html SPHINXBUILD=sphinx-build`` + | Run (``Mac``) : [TODO] +* The build is then available in the following folder: ``quantum_nodes/docs/build/``. + + +.. _dev-env-build-and-test-run-test-suite-contrib-addon: + +Run the test suite +****************** + +* | From root of the repository, run: ``pythonblender -m scripts.test -b [blender version] -os [operating system]`` + | Example (``Linux``) : ``pythonblender -m scripts.test -b 3.0.0 -os ubuntu-latest`` + | Example (``Windows``) : ``pythonblender -m scripts.test -b 3.0.0 -os windows-latest`` + | Example (``Mac``) : [TODO] + + +.. _guidelines-contrib-manual: + +Guidelines manual +################# + + +File architecture +***************** + +.. raw:: html + +
+    docs/
+    ├── _static/
+    │   ├── animation_nodes_init_replacement_file.txt
+    │   ├── css/
+    │   └── images/
+    │
+    ├── _templates/
+    │   ├── modules.rst_t
+    │   ├── packages.rst_t
+    │   └── toc.rst_t
+    │
+    ├── build/
+    │
+    ├── source/
+    │   ├── conf.py
+    │   ├── index.rst
+    │   ├── MethodNameFilter.py
+    │   ├── spelling_wordlist.txt
+    │   │
+    │   ├── [chapter]/
+    │   │   ├── index.rst
+    │   │   ├── file.rst
+    │   │   ├── [subchapter]/
+    │   │   ├── ...
+    │   │   └── [subchapter]/
+    │   │
+    │   ├── ...
+    │   └── [chapter]/
+    │       └── ...
+    │
+    └── ...
+    

+ + +Add a new chapter +***************** + +#. Create a new folder + * If your chapter is a new section, create a new folder under ``source/`` + * If your chapter is a subchapter, create a new folder under ``source/parent_chapter/`` + * Your chapter may be a subsubchapter. No problem, keep the same logic as described before + * Give it a short and precise name (snake_case naming style) + +#. Create a new ``index.rst`` file in your chapter + * This file is the "welcome page" of your chapter + * Here you can add links to any subchapters and so on ... + +#. If you need to add custom css to your pages + * Create a new folder under ``docs/_static/css/`` + * Give it the same name as your chapter + * Insert your css files + * | Once this is done, add your path to the ``html_css_files`` variable in ``config.py`` + +In a more visual way, here is the architecture of a section/chapter: + +.. raw:: html + +
+    ├── index.rst
+    ├── my_subchapter/
+    │   ├── index.rst
+    │   ├── my_subsubchapter/
+    │   ├── file.rst
+    │   └── ...
+    ├── file.rst
+    └── ...
+    

+ +So, at the end, here is what the global architecture should look like + +.. raw:: html + +
+    docs/
+    ├── _static/
+    │   ├── animation_nodes_init_replacement_file.txt
+    │   ├── css/
+    │   └── images/
+    │
+    ├── _templates/
+    │   ├── modules.rst_t
+    │   ├── packages.rst_t
+    │   └── toc.rst_t
+    │
+    ├── build/
+    │
+    ├── source/
+    │   ├── conf.py
+    │   ├── index.rst
+    │   ├── MethodNameFilter.py
+    │   ├── spelling_wordlist.txt
+    │   │
+    │   ├── my_chapter/
+    │   │   ├── index.rst
+    │   │   ├── my_subchapter/
+    │   │   │   ├── index.rst
+    │   │   │   ├── my_subsubchapter/
+    │   │   │   ├── file.rst
+    │   │   │   └── ...
+    │   │   ├── file.rst
+    │   │   └── ...
+    │   │
+    │   └── ...
+    │
+    └── ...
+    

\ No newline at end of file diff --git a/docs/source/developers_manual/manual/index.rst b/docs/source/developers_manual/manual/index.rst deleted file mode 100644 index af33d9b..0000000 --- a/docs/source/developers_manual/manual/index.rst +++ /dev/null @@ -1,254 +0,0 @@ -Contribute to the manual -======================== - - -* :ref:`development-environment-contrib-manual` -* :ref:`tools-contrib-manual` -* :ref:`guidelines-contrib-manual` -* :ref:`git-workflow-contrib-manual` - -.. _development-environment-contrib-manual: - -Development environment -*********************** - - -Install dependencies --------------------- - - -.. important:: - Make sure to install the dependencies in an appropriate python environment. - For example, you can use the one which comes with Blender. - - -| Run: ``pip install -r requirements.txt`` - - -Contribute ----------- - - -.. note:: - Click `here `_ to learn about the forking workflow on Github. - - -* Fork the repository: https://github.com/Quantum-Creative-Group/quantum_nodes -* Do your modifications -* Once you are ready, open a new `pull request `_ -* Wait for your modifications to be reviewed and accepted - - -Build the manual ----------------- - -* Clone the `quantum_nodes `_ repository. - -* | Open a terminal and go in the ``docs`` folder: ``cd docs`` - | Then type: ``make html`` (or ``make.bat html`` on Windows) - | Visualize the html in ``build/html`` - - -.. _tools-contrib-manual: - -Tools -***** - -Here is a list of tools which will help you to write documentation. - -#. :ref:`tools-vs-code-extensions` - #. :ref:`tools-pydocstring-generator-vscode` - #. :ref:`tools-rst-vscode` - - -.. _tools-vs-code-extensions: - -VSCode extensions ------------------ - - -.. _tools-pydocstring-generator-vscode: - -Python Docstring Generator -########################## - - -.. note:: - Automatically generates the right docstring format for methods / functions / classes ... - - -* Install `python docstring generator `_ - -* Select the ``sphinx`` format for the auto docstring functionality - -.. image:: /images/contrib-tools/docstring_format.png - :width: 85% - :alt: Python Docstring Generator, auto docstring sphinx - :align: center - :class: img-rounded - -| - -.. _tools-rst-vscode: - -reStructuredText Syntax highlighting -#################################### - - -.. note:: - Syntax highlighting and document symbols for reStructuredText - - -* Install `reStructuredText syntax highlighting `_ -* This extension uses `Esbonio `_ -* Select the right output for sphinx-build in the settings: - -.. image:: /images/contrib-tools/esbonio_output_sphinx_build.png - :width: 85% - :alt: reStructuredText syntax highlighting, set output path sphinx-build - :align: center - :class: img-rounded - -| - - -.. _guidelines-contrib-manual: - -Guidelines -********** - - -#. :ref:`files-architecture-contrib-manual` -#. :ref:`add-a-new-chapter-contrib-manual` - - -.. _files-architecture-contrib-manual: - -Files architecture ------------------- - -.. raw:: html - -
-    docs/
-    ├── _static/
-    │   ├── animation_nodes_init_replacement_file.txt
-    │   ├── css/
-    │   └── images/
-    │
-    ├── _templates/
-    │   ├── modules.rst_t
-    │   ├── packages.rst_t
-    │   └── toc.rst_t
-    │
-    ├── build/
-    │
-    ├── source/
-    │   ├── conf.py
-    │   ├── index.rst
-    │   ├── MethodNameFilter.py
-    │   ├── spelling_wordlist.txt
-    │   │
-    │   ├── [chapter]/
-    │   │   ├── index.rst
-    │   │   ├── file.rst
-    │   │   ├── [subchapter]/
-    │   │   ├── ...
-    │   │   └── [subchapter]/
-    │   │
-    │   ├── ...
-    │   └── [chapter]/
-    │       └── ...
-    │
-    └── ...
-    

- - -.. _add-a-new-chapter-contrib-manual: - -Add a new chapter ------------------ - -#. Create a new folder - * If your chapter is a new section, create a new folder under ``source/`` - * If your chapter is a subchapter, create a new folder under ``source/parent_chapter/`` - * Your chapter may be a subsubchapter. No problem, keep the same logic as described before - * Give it a short and precise name (snake_case naming style) - -#. Create a new ``index.rst`` file in your chapter - * This file is the "welcome page" of your chapter - * Here you can add links to any subchapters and so on ... - -#. If you need to add custom css to your pages - * Create a new folder under ``docs/_static/css/`` - * Give it the same name as your chapter - * Insert your css files - * | Once this is done, add your path to the ``html_css_files`` variable in ``config.py`` - -In a more visual way, here is the architecture of a section/chapter: - -.. raw:: html - -
-    ├── index.rst
-    ├── my_subchapter/
-    │   ├── index.rst
-    │   ├── my_subsubchapter/
-    │   ├── file.rst
-    │   └── ...
-    ├── file.rst
-    └── ...
-    

- -So, at the end, here is what the global architecture should look like - -.. raw:: html - -
-    docs/
-    ├── _static/
-    │   ├── animation_nodes_init_replacement_file.txt
-    │   ├── css/
-    │   └── images/
-    │
-    ├── _templates/
-    │   ├── modules.rst_t
-    │   ├── packages.rst_t
-    │   └── toc.rst_t
-    │
-    ├── build/
-    │
-    ├── source/
-    │   ├── conf.py
-    │   ├── index.rst
-    │   ├── MethodNameFilter.py
-    │   ├── spelling_wordlist.txt
-    │   │
-    │   ├── my_chapter/
-    │   │   ├── index.rst
-    │   │   ├── my_subchapter/
-    │   │   │   ├── index.rst
-    │   │   │   ├── my_subsubchapter/
-    │   │   │   ├── file.rst
-    │   │   │   └── ...
-    │   │   ├── file.rst
-    │   │   └── ...
-    │   │
-    │   └── ...
-    │
-    └── ...
-    

- - -.. _git-workflow-contrib-manual: - -Git workflow -************ - -.. image:: https://miro.medium.com/max/560/1*UH5ozOBwkaFhWA1mrJkVIQ.png - :alt: Git workflow - :align: center - :width: 80% - :class: img-rounded - -| \ No newline at end of file diff --git a/docs/source/developers_manual/tools.rst b/docs/source/developers_manual/tools.rst new file mode 100644 index 0000000..29439fe --- /dev/null +++ b/docs/source/developers_manual/tools.rst @@ -0,0 +1,75 @@ +.. _tools-dev-addon: + +Tools +===== + +Here is a list of tools which will help you to develop Quantum Nodes. + +* :ref:`vs-code-extensions-addon` + * :ref:`tools-blender-vscode` + * :ref:`tools-pydocstring-generator-vscode` + * :ref:`tools-rst-vscode` + + +.. _vs-code-extensions-addon: + +VSCode extensions +################# + + +.. _tools-blender-vscode: + +Blender Development +******************* + + +.. note:: + Tools to simplify Blender development. Developed by `Jacques Lucke `_. + + +* Install `blender development `_ + + +.. _tools-pydocstring-generator-vscode: + +Python Docstring Generator +************************** + + +.. note:: + Automatically generates the right docstring format for methods / functions / classes ... + + +* Install `python docstring generator `_ + +* Select the ``sphinx`` format for the auto docstring functionality + +.. image:: /images/contrib-tools/docstring_format.png + :width: 85% + :alt: Python Docstring Generator, auto docstring sphinx + :align: center + :class: img-rounded + +| + +.. _tools-rst-vscode: + +reStructuredText Syntax highlighting +************************************ + + +.. note:: + Syntax highlighting and document symbols for reStructuredText + + +* Install `reStructuredText syntax highlighting `_ +* This extension uses `Esbonio `_ +* Select the right output for sphinx-build in the settings: + +.. image:: /images/contrib-tools/esbonio_output_sphinx_build.png + :width: 85% + :alt: reStructuredText syntax highlighting, set output path sphinx-build + :align: center + :class: img-rounded + +| \ No newline at end of file diff --git a/scripts/setup_animation_nodes.ps1 b/scripts/setup_animation_nodes.ps1 new file mode 100644 index 0000000..10802c7 --- /dev/null +++ b/scripts/setup_animation_nodes.ps1 @@ -0,0 +1,29 @@ +param( + [string]$animation_nodes = "./animation_nodes/", + [string]$quantum_nodes = "./", + [string]$site_packages +) + +Write-Output "---------- SETUP ANIMATION NODES: START ---------" + +Write-Output "STEP 1: replace __init__.py file" + +Remove-Item $animation_nodes/__init__.py +Copy-Item $quantum_nodes/docs/_static/animation_nodes_init_replacement_file.txt -Destination $animation_nodes/__init__.py + +Write-Output "STEP 2: edit preferences.py" + +$file = "$animation_nodes/preferences.py" +$find = "return bpy.app.version" +$replace = "return bpy.app.version if bpy.app.version is not None else (2, 93, 0)" +(Get-Content -Path $file -Raw) -replace $find, $replace | Set-Content -Path $file -NoNewLine + +Write-Output "STEP 3: remove '@persistent' decorators" + +"$PSScriptRoot\..\docs\replace_matching_string_in_files.ps1 -folder ./animation_nodes/" + +Write-Output "STEP 4: move animation_nodes to 'site-packages/'" + +Copy-Item $animation_nodes -Destination $site_packages -Recurse + +Write-Output "----------- SETUP ANIMATION NODES: END ----------"