diff --git a/.github/workflows/test-fake-addon-example-from-github-pip-nightly.yml b/.github/workflows/test-fake-addon-example-from-github-pip-nightly.yml index b45d6f3..f3cdabc 100644 --- a/.github/workflows/test-fake-addon-example-from-github-pip-nightly.yml +++ b/.github/workflows/test-fake-addon-example-from-github-pip-nightly.yml @@ -13,7 +13,7 @@ jobs: max-parallel: 4 fail-fast: false matrix: - blender-version: ["3.0", "2.93", "2.92", "2.91", "2.90", "2.83", "2.82", "2.81", "2.80",] + blender-version: ["3.0", "2.93", "2.92", "2.83", "2.82",] os: [ubuntu-latest, windows-latest, macos-latest] env: BLENDER_CACHE: ${{ github.workspace }}/.blender_releases_cache # The place where blender releases are downloaded @@ -24,18 +24,12 @@ jobs: - name: Set up Python uses: actions/setup-python@v1 with: - python-version: 3.7 + python-version: 3.8 - name: Cache Blender release download uses: actions/cache@v1 with: path: ${{ env.BLENDER_CACHE }} key: ${{ matrix.os }}-blender-${{ matrix.blender-version }} - - name: Fix blender 2.7* for Linux, by apt-getting prepackaged blender with proper dependencies - if: matrix.os == 'ubuntu-latest' && startsWith(matrix.blender-version, '2.7') - run: | - sudo add-apt-repository ppa:thomas-schiex/blender-legacy - sudo apt-get update - sudo apt-get install blender - name: Setup Environment run: | # This testing script will make use of BLENDER_VERSION and BLENDER_CACHE diff --git a/.github/workflows/test-fake-addon-example-from-local-wheel.yml b/.github/workflows/test-fake-addon-example-from-local-wheel.yml index 561fed4..e89c244 100644 --- a/.github/workflows/test-fake-addon-example-from-local-wheel.yml +++ b/.github/workflows/test-fake-addon-example-from-local-wheel.yml @@ -13,7 +13,7 @@ jobs: max-parallel: 4 fail-fast: false matrix: - blender-version: ["3.0", "2.93", "2.92", "2.91", "2.90", "2.83", "2.82", "2.81", "2.80",] + blender-version: ["3.0", "2.93", "2.92", "2.83", "2.82",] os: [ubuntu-latest, windows-latest, macos-latest] env: BLENDER_CACHE: ${{ github.workspace }}/.blender_releases_cache # The place where blender releases are downloaded @@ -24,7 +24,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v1 with: - python-version: 3.7 + python-version: 3.8 - name: Cache Blender release download uses: actions/cache@v1 with: diff --git a/.travis.yml b/.travis.yml index 19a59d4..2724adc 100755 --- a/.travis.yml +++ b/.travis.yml @@ -10,17 +10,14 @@ env: - BLENDER_CACHE=$HOME/.cache/blender - BL_ADDON=fake_addon matrix: + - BLENDER_VERSION="3.0" + - BLENDER_VERSION="2.93" - BLENDER_VERSION="2.92" - - BLENDER_VERSION="2.91" - - BLENDER_VERSION="2.90" - BLENDER_VERSION="2.83" - - BLENDER_VERSION="2.82" - - BLENDER_VERSION="2.81" - - BLENDER_VERSION="2.80" language: python python: - - 3.7 + - 3.8 cache: apt: true diff --git a/README.md b/README.md index 7a50f54..485cac1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ -[![Travis Build Status](https://travis-ci.com/nangtani/blender-addon-tester.svg?branch=master)](https://travis-ci.com/nangtani/blender-addon-tester) ![Github Actions pypi.org nightly tests](https://github.com/nangtani/blender-addon-tester/workflows/test-fake-addon-example-from-github-pip-nightly/badge.svg) ![Github Actions local Python wheel tests](https://github.com/nangtani/blender-addon-tester/workflows/test-fake-addon-example-from-local-wheel/badge.svg) [![codecov](https://codecov.io/gh/nangtani/blender-addon-tester/branch/master/graph/badge.svg)](https://codecov.io/gh/nangtani/blender-addon-tester) @@ -62,7 +61,7 @@ Example output of a successful `pytest`. ``` ============================= test session starts ============================= -platform win32 -- Python 3.7.4, pytest-5.4.1, py-1.8.1, pluggy-0.13.1 -- C:\blender\blender-2.90\blender.exe +platform win32 -- Python 3.7.4, pytest-5.4.1, py-1.8.1, pluggy-0.13.1 -- C:\blender\blender-2.93\blender.exe cachedir: .pytest_cache rootdir: C:\blender\blender-fake-addon plugins: cov-2.8.1 @@ -95,7 +94,7 @@ tests/test_pytest.py:11: AssertionError To see a working addon environment checkout this repo. In the sub directory `examples\testing-fake-addon`, it contains a dummy addon that that can be sued to verify that the whole enviroment is setup correctly. ``` cd examples\testing-fake-addon -test_addon_blender.py fake_addon 2.90 +test_addon_blender.py fake_addon 2.93 ``` However it is better to use this modile with an addon in a different repo. Check out this repo for that example, [fake_addon](https://github.com/nangtani/blender-fake-addon) @@ -111,6 +110,13 @@ However it is better to use this modile with an addon in a different repo. Chec ## Releases +### v0.8 +Needed to updated how the blender packages got fetch from the server (again) +Fixed the non default addon directory option, #26 +Break out the addon directory setup from the addon install +Deprecated 2.79, which removes any dependancy on python3.5 +Deprecated 2.80 + ### v0.7 Re do how most recent version of blender is fetched as the format used on the server has changed. Deprecated 2.78. diff --git a/blender_addon_tester/addon_helper.py b/blender_addon_tester/addon_helper.py index 74640d1..fa301e6 100644 --- a/blender_addon_tester/addon_helper.py +++ b/blender_addon_tester/addon_helper.py @@ -1,11 +1,11 @@ import os -from pathlib import Path import re import sys import shutil -from tempfile import gettempdir import time import zipfile +from pathlib import Path +from tempfile import gettempdir import bpy @@ -54,7 +54,7 @@ def clean_file(filename): k = re.search('"blender":\s\(\d+, \d+, \d+\)', line) if k: - line = ' "blender": {0},\n'.format(bpy.app.version) + line = f' "blender": {bpy.app.version},\n' f.write(line) f.close() @@ -155,46 +155,37 @@ def zip_addon(addon: str, addon_dir: str): return bpy_module, bfile -def change_addon_dir(bpy_module: str, zfile: str, addon_dir: str): +def change_addon_dir(bpy_module: str, addon_dir: str): """Change Blender default addons (a.k.a user scripts) directory to the given one. - - TODO shouldn't it be split in two functions? - 1- Changing the scripts dir - 2- Importing addons into Blender - :param bpy_module: Addon name used as bpy module name - :param zfile: Zipped addon to import :param addon_dir: Directory used by Blender to get addons (user scripts) """ # Ensure paths addon_dir = Path(addon_dir).resolve() - zfile = Path(zfile).resolve() # Create addon target dir if doesn't exist if not addon_dir.is_dir(): addon_dir.mkdir(parents=True) - + print(f"Change addon dir - {addon_dir}") - if (2, 80, 0) < bpy.app.version: - # https://docs.blender.org/api/current/bpy.types.PreferencesFilePaths.html#bpy.types.PreferencesFilePaths.script_directory - # requires restart - bpy.context.preferences.filepaths.script_directory = addon_dir.as_posix() - bpy.utils.refresh_script_paths() - bpy.ops.preferences.addon_install(overwrite=True, filepath=zfile.as_posix()) - bpy.ops.preferences.addon_enable(module=bpy_module) - else: - bpy.context.user_preferences.filepaths.script_directory = addon_dir.as_posix() - bpy.utils.refresh_script_paths() - bpy.ops.wm.addon_install(overwrite=True, filepath=zfile.as_posix()) - bpy.ops.wm.addon_enable(module=bpy_module) + bpy.context.preferences.filepaths.script_directory = addon_dir.as_posix() + bpy.utils.refresh_script_paths() + + +def install_addon(bpy_module: str, zfile: str): + """Install addon to the version of blender + :param bpy_module: Addon name used as bpy module name + :param zfile: Zipped addon to import + """ + # Ensure paths + zfile = Path(zfile).resolve() + bpy.ops.preferences.addon_install(overwrite=True, target='PREFS', filepath=zfile.as_posix()) + bpy.ops.preferences.addon_enable(module=bpy_module) def cleanup(addon, bpy_module, addon_dir): - print("Cleaning up - {}".format(bpy_module)) - if (2, 80, 0) < bpy.app.version: - bpy.ops.preferences.addon_disable(module=bpy_module) - else: - bpy.ops.wm.addon_disable(module=bpy_module) + print(f"Cleaning up - {bpy_module}") + bpy.ops.preferences.addon_disable(module=bpy_module) if os.path.isdir(addon_dir): shutil.rmtree(addon_dir) diff --git a/blender_addon_tester/blender_load_pytest.py b/blender_addon_tester/blender_load_pytest.py index ece617b..e91b03a 100644 --- a/blender_addon_tester/blender_load_pytest.py +++ b/blender_addon_tester/blender_load_pytest.py @@ -27,7 +27,7 @@ try: sys.path.append(os.environ["LOCAL_PYTHONPATH"]) - from addon_helper import zip_addon, change_addon_dir, cleanup + from addon_helper import zip_addon, change_addon_dir, install_addon, cleanup except Exception as e: print(e) sys.exit(1) @@ -48,7 +48,8 @@ def __init__(self, addon): def pytest_configure(self, config): (self.bpy_module, self.zfile) = zip_addon(self.addon, self.addon_dir) - change_addon_dir(self.bpy_module, self.zfile, self.addon_dir) + change_addon_dir(self.bpy_module, self.addon_dir) + install_addon(self.bpy_module, self.zfile) config.cache.set("bpy_module", self.bpy_module) def pytest_unconfigure(self): diff --git a/blender_addon_tester/get_blender.py b/blender_addon_tester/get_blender.py index 90141de..78d897c 100755 --- a/blender_addon_tester/get_blender.py +++ b/blender_addon_tester/get_blender.py @@ -35,7 +35,7 @@ def getSuffix(blender_version, platform=None): if g: rev = g.group(0) else: - raise RuntimeError("Blender version cannot be guessed in the following string: {0}".format(blender_version)) + raise RuntimeError(f"Blender version cannot be guessed in the following string: {blender_version}") urls = [ f"https://ftp.nluug.nl/pub/graphics/blender/release/Blender{rev}", @@ -240,18 +240,11 @@ def getBlender(blender_version, blender_zippath, nightly): print("ERROR, Blender's bundled python executable could not be found within Blender's files") exit(1) - if "cygwin" == sys.platform: - print("ERROR, do not run this under cygwin, run it under Linux and Windows cmd!!") - exit(1) + cmd = f"{python} -m ensurepip" + os.system(cmd) - if sys.platform.startswith("win") or sys.platform == "darwin" or (sys.platform == "linux" and blender_version.startswith("2.7")): - import urllib.request - urllib.request.urlretrieve("https://bootstrap.pypa.io/get-pip.py", "get-pip.py") - cmd = f"{python} get-pip.py" - os.system(cmd) - else: - cmd = f"{python} -m ensurepip" - os.system(cmd) + cmd = f"{python} -m pip install -U pip" + os.system(cmd) cmd = f"{python} -m pip install --upgrade -r {CURRENT_MODULE_DIRECTORY}/blender_requirements.txt -r {CURRENT_MODULE_DIRECTORY}/requirements.txt" os.system(cmd) @@ -283,7 +276,7 @@ def get_blender_from_suffix(blender_version): if len(sys.argv) > 1: blender_rev = sys.argv[1] else: - blender_rev = "2.80" + blender_rev = "2.92" if re.search("-", blender_rev): blender_rev, _ = blender_rev.split("-") diff --git a/examples/testing-fake-addon/test_addon_blender.py b/examples/testing-fake-addon/test_addon_blender.py index d0c8150..8359c6a 100644 --- a/examples/testing-fake-addon/test_addon_blender.py +++ b/examples/testing-fake-addon/test_addon_blender.py @@ -14,7 +14,7 @@ def main(): if len(sys.argv) > 2: blender_rev = sys.argv[2] else: - blender_rev = "2.80" + blender_rev = "2.92" try: exit_val = BAT.test_blender_addon(addon_path=addon, blender_revision=blender_rev) diff --git a/scripts/load_pytest.py b/scripts/load_pytest.py index cd5df3d..7bb9c4c 100644 --- a/scripts/load_pytest.py +++ b/scripts/load_pytest.py @@ -11,7 +11,7 @@ try: sys.path.append(os.environ["LOCAL_PYTHONPATH"]) - from addon_helper import zip_addon, change_addon_dir, cleanup + from addon_helper import zip_addon, change_addon_dir, install_addon, cleanup except Exception as e: print(e) sys.exit(1) @@ -24,7 +24,8 @@ def __init__(self, addon): def pytest_configure(self, config): (self.bpy_module, self.zfile) = zip_addon(self.addon, self.addon_dir) - change_addon_dir(self.bpy_module, self.zfile, self.addon_dir) + change_addon_dir(self.bpy_module, self.addon_dir) + install_addon(self.bpy_module, self.zfile) config.cache.set("bpy_module", self.bpy_module) def pytest_unconfigure(self):