diff --git a/blender_requirements.txt b/blender_requirements.txt index 8a7c2af..c57e5fa 100644 --- a/blender_requirements.txt +++ b/blender_requirements.txt @@ -1,5 +1 @@ -pip -yolk3k -pytest -coverage -pytest-cov +blender-addon-tester diff --git a/scripts/addon_helper.py b/scripts/addon_helper.py deleted file mode 100644 index 071fd9f..0000000 --- a/scripts/addon_helper.py +++ /dev/null @@ -1,61 +0,0 @@ -import os -import sys -import re -import time -import zipfile -import shutil -import bpy - - -def zip_addon(addon, addon_dir): - bpy_module = re.sub(".py", "", os.path.basename(os.path.realpath(addon))) - - if os.path.isdir(addon_dir): - shutil.rmtree(addon_dir) - os.mkdir(addon_dir) - - zfile = os.path.realpath(bpy_module + ".zip") - - print("Zipping addon - {0}".format(bpy_module)) - - zf = zipfile.ZipFile(zfile, "w") - if os.path.isdir(addon): - for dirname, subdirs, files in os.walk(addon): - zf.write(dirname) - for filename in files: - zf.write(os.path.join(dirname, filename)) - else: - zf.write(addon) - zf.close() - return (bpy_module, zfile) - - -def change_addon_dir(bpy_module, zfile, addon_dir): - print("Change addon dir - {0}".format(addon_dir)) - - - if (2, 80, 0) < bpy.app.version: - bpy.context.preferences.filepaths.script_directory = addon_dir - bpy.utils.refresh_script_paths() - bpy.ops.preferences.addon_install(overwrite=True, filepath=zfile) - bpy.ops.preferences.addon_enable(module=bpy_module) - else: - bpy.context.user_preferences.filepaths.script_directory = addon_dir - bpy.utils.refresh_script_paths() - bpy.ops.wm.addon_install(overwrite=True, filepath=zfile) - bpy.ops.wm.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) - if os.path.isdir(addon_dir): - shutil.rmtree(addon_dir) - - -def get_version(bpy_module): - mod = sys.modules[bpy_module] - return mod.bl_info.get("version", (-1, -1, -1)) diff --git a/scripts/get_blender.py b/scripts/get_blender.py deleted file mode 100755 index 591a970..0000000 --- a/scripts/get_blender.py +++ /dev/null @@ -1,154 +0,0 @@ -import os -import sys -import shutil -import subprocess -import zipfile -import tarfile -import requests -import re -from glob import glob -from bs4 import BeautifulSoup - - -def checkPath(path): - if "cygwin" == sys.platform: - cmd = "cygpath -wa {0}".format(path) - path = subprocess.check_output(cmd.split()).decode("ascii").rstrip() - return path - - -def getSuffix(blender_version): - print(sys.platform) - if "win32" == sys.platform or "win64" == sys.platform or "cygwin" == sys.platform: - machine = "windows64" - ext = "zip" - elif "darwin" == sys.platform: - machine = "macOS" - ext = "dmg" - else: - machine = "linux.*64" - ext = "tar.+" - - g = re.search(f"\d\.\d\d", blender_version) - if g: - rev = g.group(0) - else: - raise - - urls = [ - f"https://ftp.nluug.nl/pub/graphics/blender/release/Blender{rev}", - "https://builder.blender.org/download", - ] - blender_zippath = None - nightly = False - for url in urls: - page = requests.get(url) - data = page.text - soup = BeautifulSoup(data, features="html.parser") - - blender_version_suffix = "" - versions_found = [] - for link in soup.find_all("a"): - x = str(link.get("href")) - #print(x) - g = re.search(f"blender-(.+)-{machine}.+{ext}", x) - if g: - version_found = g.group(1).split("-")[0] - versions_found.append(version_found) - if version_found == blender_version: - blender_zippath = f"{url}/{g.group(0)}" - if url == urls[1]: - nightly = True - - if None == blender_zippath: - print(soup) - raise Exception(f"Unable to find {blender_version} in nightlies, here is what is available {versions_found}") - - #print(blender_zippath, nightly) - #exit() - return blender_zippath, nightly - - -def getBlender(blender_version, blender_zippath, nightly): - cwd = checkPath(os.getcwd()) - if "BLENDER_CACHE" in os.environ.keys(): - print(f"BLENDER_CACHE found {os.environ['BLENDER_CACHE']}") - os.chdir(os.environ["BLENDER_CACHE"]) - else: - os.chdir("..") - cache_dir = checkPath(os.getcwd()) - - blender_zipfile = blender_zippath.split("/")[-1] - - files = glob(blender_zipfile) - - if 0 == len(files): - if not os.path.exists(blender_zipfile): - r = requests.get(blender_zippath, stream=True) - print(f"Downloading {blender_zippath}") - open(blender_zipfile, "wb").write(r.content) - - if blender_zipfile.endswith("zip"): - z = zipfile.ZipFile(blender_zipfile, "r") - zfiles = z.namelist() - elif blender_zipfile.endswith("dmg"): - raise Exception(f"dmg Unsupported") - #hdiutil attach -mountpoint - else: - z = tarfile.open(blender_zipfile) - zfiles = z.getnames() - - zdir = zfiles[0].split("/")[0] - if not os.path.isdir(zdir): - print(f"Unpacking {blender_zipfile}") - z.extractall() - z.close() - blender_archive = zdir - - for zfile in zfiles: - if re.search("bin/python.exe", zfile) or re.search("bin/python\d.\d", zfile): - python = os.path.realpath(zfile) - - cmd = f"{python} -m ensurepip" - os.system(cmd) - cmd = f"{python} -m pip install --upgrade -r {cwd}/blender_requirements.txt -r {cwd}/scripts/requirements.txt" - os.system(cmd) - - os.chdir(cwd) - - shutil.rmtree("tests/__pycache__", ignore_errors=True) - - ext = "" - if nightly == True: - ext = "-nightly" - dst = f"../blender-{blender_version}{ext}" - - if os.path.exists(dst): - shutil.rmtree(dst) - - src = f"{cache_dir}/{blender_archive}" - print(f"Move {src} to {dst}") - shutil.move(src, dst) - - -def main(blender_version): - - blender_zipfile, nightly = getSuffix(blender_version) - - getBlender(blender_version, blender_zipfile, nightly) - - -if __name__ == "__main__": - if "cygwin" == sys.platform: - print("ERROR, do not run this under cygwin, run it under Linux and Windows cmd!!") - exit() - - if len(sys.argv) >= 2: - blender_rev = sys.argv[1] - else: - blender_rev = "2.79b" - - if re.search("-", blender_rev): - blender_rev, _ = blender_rev.split("-") - - main(blender_rev) diff --git a/scripts/get_python.sh b/scripts/get_python.sh deleted file mode 100644 index 9036826..0000000 --- a/scripts/get_python.sh +++ /dev/null @@ -1,70 +0,0 @@ -unameOut="$(uname -s)" -case "${unameOut}" in - Linux*) machine=Linux;; - Darwin*) machine=Mac;; - CYGWIN*) machine=Cygwin;; - MINGW*) machine=MinGw;; - MSYS_NT*) machine=MsysNt;; - *) machine="UNKNOWN:${unameOut}" -esac - -PYTHON_VENV="${VENV_CACHE}/${machine}/${BLENDER_VERSION}/Python-${PYTHON_REV}" - -#rm -rf "${VENV_CACHE}/${machine}" -#rm -rf "${VENV_CACHE}/Mac" - -mkdir -p "${VENV_CACHE}/${machine}" -ls "${VENV_CACHE}/${machine}" - -if [ ${machine} == "MsysNt" ]; then - choco install python --version ${PYTHON_REV} - py -m venv --copies ${PYTHON_VENV} -else - if [ ! -d "${PYTHON_VENV}" ]; then - cd ${VENV_CACHE}/${machine} - if [ ${machine} == "Mac" ]; then - #brew update - #brew upgrade libssl-dev openssl > logfile 2>&1 - #brew unlink openssl && brew link openssl --force - brew install openssl xz - CPPFLAGS="-I$(brew --prefix openssl)/include" \ - LDFLAGS="-L$(brew --prefix openssl)/lib" \ - pythonz install ${PYTHON_VENV} - else - sudo apt-get install libssl-dev openssl - fi - wget https://www.python.org/ftp/python/${PYTHON_REV}/Python-${PYTHON_REV}.tgz - tar -zxvf Python-${PYTHON_REV}.tgz > logfile 2>&1 - cd Python-${PYTHON_REV} - if [ ${machine} == "Mac" ]; then - which python -# ./configure > logfile 2>&1 -# make > logfile 2>&1 -# ./python.exe -m venv --copies ${PYTHON_VENV} - else - ./configure > logfile 2>&1 - make > logfile 2>&1 - ./python -m venv --copies ${PYTHON_VENV} - fi - fi -fi - -if [ ${machine} == "MsysNt" ]; then - source ${PYTHON_VENV}/Scripts/activate -else - source ${PYTHON_VENV}/bin/activate -fi - -python -m pip install pip yolk3k --upgrade -python -m yolk -l - -which python -export PYTHON_RET=`python --version` -if [ "${PYTHON_RET}" != "Python ${PYTHON_REV}" ]; then - echo "Wrong Python rev returned!" - echo " ${PYTHON_RET} != Python ${PYTHON_REV}" - exit 1 -else - echo "This is the expected version of Python:" - echo ${PYTHON_RET} -fi diff --git a/scripts/load_pytest.py b/scripts/load_pytest.py deleted file mode 100644 index 1f4bb4e..0000000 --- a/scripts/load_pytest.py +++ /dev/null @@ -1,37 +0,0 @@ -ADDON = "fake_addon" - -import os -import sys -import pytest - -try: - sys.path.append(os.environ["LOCAL_PYTHONPATH"]) - from addon_helper import zip_addon, change_addon_dir, cleanup -except Exception as e: - print(e) - sys.exit(1) - - -class SetupPlugin: - def __init__(self, addon): - self.addon = addon - self.addon_dir = "local_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) - config.cache.set("bpy_module", self.bpy_module) - - def pytest_unconfigure(self): -# cmd = "coverage xml" -# os.system(cmd) - cleanup(self.addon, self.bpy_module, self.addon_dir) - print("*** test run reporting finished") - - -try: - exit_val = pytest.main(["tests", "-v", "-x", "--cov", "--cov-report", "term-missing", "--cov-report", "xml",], plugins=[SetupPlugin(ADDON)]) -except Exception as e: - print(e) - exit_val = 1 -sys.exit(exit_val) diff --git a/scripts/requirements.txt b/scripts/requirements.txt deleted file mode 100644 index 218f365..0000000 --- a/scripts/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -pip -yolk3k -bs4 -requests diff --git a/scripts/run_blender.py b/scripts/run_blender.py deleted file mode 100644 index dd15b35..0000000 --- a/scripts/run_blender.py +++ /dev/null @@ -1,49 +0,0 @@ -import os -import sys -import subprocess -import re -from glob import glob - - -def checkPath(path): - if "cygwin" == sys.platform: - cmd = "cygpath -wa {0}".format(path) - path = subprocess.check_output(cmd.split()).decode("ascii").rstrip() - return path - - -def main(blender, test_file): - test_file = checkPath(test_file) - local_python = checkPath(os.getcwd() + "/scripts") - os.environ["LOCAL_PYTHONPATH"] = local_python - - cmd = f'{blender} -b --python "{test_file}"' - result = int(os.system(cmd)) - if 0 == result: - return 0 - else: - return 1 - - -if __name__ == "__main__": - if len(sys.argv) >= 2: - blender_rev = sys.argv[1] - else: - blender_rev = "2.80" - - if "win32" == sys.platform or "win64" == sys.platform or "cygwin" == sys.platform: - ext = ".exe" - else: - ext = "" - - files = glob(f"../blender-{blender_rev}*/blender{ext}") - if not 1 == len(files): - raise Exception(f"Too many blenders returned: {files}") - - blender = os.path.realpath(files[0]) - - test_file = "scripts/load_pytest.py" - - exit_val = main(blender, test_file) - - sys.exit(exit_val)