Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug Build Support #605

Merged
merged 6 commits into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ venv/
*.sublime-*
MCprep_addon/import_bridge/conf
MCprep_addon/import_bridge/nbt
MCprep_addon/MCprep_resources/
MCprep_addon/MCprep_resources/
MCprep_addon/.vscode
23 changes: 23 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
// Use IntelliSense to learn about possible attributes.
StandingPadAnimations marked this conversation as resolved.
Show resolved Hide resolved
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Remote Attach",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/home/mahid/.config/blender/4.2/extensions/user_default/mcprep"
}
]
}
]
}
21 changes: 21 additions & 0 deletions MCprep_addon/blender_manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
schema_version = "1.0.0"

id = "mcprep"
version = "3.6.0"
name = "MCprep"
tagline = "An addon for Minecraft animation workflows"
maintainer = "Patrick W. Crawford <[email protected]"
type = "add-on"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard for me to accept but yes, I guess I really have been saying addon incorrectly all these years. Well at least it's better than Godot, which itself somehow references both addons and plugins as interchangeable in different contexts


website = "https://TheDuckCow.com/MCprep"

tags = ["Animation", "Material"]

blender_version_min = "4.2.0"

license = [
"SPDX:GPL-3.0-or-later",
]

[permissions]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do need internet as well, since we have skin downloads for username and batch.

According to the foundation, we should even try to respect the blender preference for checking if internet access overall is turned on. They don't have a way to force require it, but something for us to contemplate having a popup instead of performing the action in case that setting is off.

files = "To import OBJ files and assets"
6 changes: 6 additions & 0 deletions MCprep_addon/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Engine(enum.Enum):
# constant to make it easier to use
# and check for
UNKNOWN_LOCATION = (-1, "UNKNOWN LOCATION")
DEBUG_MODE = False

# check if custom preview icons available
try:
Expand Down Expand Up @@ -316,6 +317,11 @@ class MCprepError(object):
file: str
msg: Optional[str] = None

# Requires Extension support and building with the proper wheels
if DEBUG_MODE and bpy.app.version >= (4, 2, 0):
import debugpy
debugpy.listen(("localhost", 5678))

env = MCprepEnv()

def updater_select_link_function(self, tag):
Expand Down
2 changes: 1 addition & 1 deletion MCprep_addon/spawner/meshswap.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from dataclasses import dataclass
from typing import Dict, List, Union, Tuple
import math
from MCprep_addon import world_tools
from .. import world_tools
import mathutils
import os
import random
Expand Down
2 changes: 1 addition & 1 deletion MCprep_addon/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import random
import re
import subprocess
from MCprep_addon.commonmcobj_parser import CommonMCOBJTextureType
from .commonmcobj_parser import CommonMCOBJTextureType

import bpy
from bpy.types import (
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion MCprep_addon/world_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from pathlib import Path
from typing import List, Optional, Union
import shutil
from MCprep_addon.commonmcobj_parser import CommonMCOBJ, CommonMCOBJTextureType, parse_header
from .commonmcobj_parser import CommonMCOBJ, CommonMCOBJTextureType, parse_header

import bpy
from bpy.types import Context, Camera
Expand Down
29 changes: 29 additions & 0 deletions action-scripts/build-patches/debug-mode.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/MCprep_addon/blender_manifest.toml b/MCprep_addon/blender_manifest.toml
index 705e0ae..23683df 100644
--- a/MCprep_addon/blender_manifest.toml
+++ b/MCprep_addon/blender_manifest.toml
@@ -17,5 +17,11 @@ license = [
"SPDX:GPL-3.0-or-later",
]

+wheels = [
+ "./wheels/debugpy-1.8.2-py2.py3-none-any.whl",
+ "./wheels/debugpy-1.8.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
+ "./wheels/debugpy-1.8.2-cp311-cp311-win_amd64.whl",
+]
+
[permissions]
files = "To import OBJ files and assets"
diff --git a/MCprep_addon/conf.py b/MCprep_addon/conf.py
index 38bda7f..f74b0fe 100644
--- a/MCprep_addon/conf.py
+++ b/MCprep_addon/conf.py
@@ -62,7 +62,7 @@ Entity = Tuple[str, str, str]
# constant to make it easier to use
# and check for
UNKNOWN_LOCATION = (-1, "UNKNOWN LOCATION")
-DEBUG_MODE = False
+DEBUG_MODE = True

# check if custom preview icons available
try:
28 changes: 28 additions & 0 deletions action-scripts/build-patches/extension-bl_info.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/MCprep_addon/__init__.py b/MCprep_addon/__init__.py
index e727f3f..748a5dc 100755
--- a/MCprep_addon/__init__.py
+++ b/MCprep_addon/__init__.py
@@ -38,7 +38,7 @@ Disclaimer: This is not an official Google product
# Increment this number for each time you get a "inconsistent use of spaces and tab error"
# error = 51

-bl_info = {
+mcprep_bl_info = {
"name": "MCprep",
"category": "Object",
"version": (3, 5, 3),
@@ -62,12 +62,11 @@ import bpy


def register():
- load_modules.register(bl_info)
+ load_modules.register(mcprep_bl_info)


def unregister():
- load_modules.unregister(bl_info)
-
+ load_modules.unregister(mcprep_bl_info)

if __name__ == "__main__":
register()
51 changes: 51 additions & 0 deletions action-scripts/debug-build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from bpy_addon_build.api import BabContext
import subprocess
from pathlib import Path
import urllib.request
import hashlib

DEBUG_MODE_PATCH = Path(__file__).parent.joinpath("build-patches/debug-mode.diff")


# debugpy library from Microsoft, downloaded from Pypi
#
# https://github.com/microsoft/debugpy
DEBUGPY_WIN = "https://files.pythonhosted.org/packages/23/b1/3fc28ba2921234e3fad4a421dcb3185c38066eab0f92702c0d88ce891381/debugpy-1.8.2-cp311-cp311-win_amd64.whl"
DEBUGPY_LINUX = "https://files.pythonhosted.org/packages/4f/d6/04ae52227ab7c1d43b729d5ae75ebd592df56c55d4e4dfa30ba173096b0f/debugpy-1.8.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl"
DEBUGPY_OSX = "https://files.pythonhosted.org/packages/b4/32/dd0707c8557f99496811763c5333ea87bcec1eb233c1efa324c9a8082bff/debugpy-1.8.2-py2.py3-none-any.whl"

DEBUGPY_HASH_WIN = "d3408fddd76414034c02880e891ea434e9a9cf3a69842098ef92f6e809d09afa"
DEBUGPY_HASH_LINUX = "acdf39855f65c48ac9667b2801234fc64d46778021efac2de7e50907ab90c634"
DEBUGPY_HASH_OSX = "16e16df3a98a35c63c3ab1e4d19be4cbc7fdda92d9ddc059294f18910928e0ca"


def validate_hash(file: str, hash: str):
with open(file, "rb") as file:
read_file = file.read()
hasher = hashlib.sha256()
hasher.update(read_file)
assert hasher.hexdigest() == hash


def pre_build(ctx: BabContext) -> None:
print("Debug Mode: Applying Patches")
_ = subprocess.run(["git", "apply", str(DEBUG_MODE_PATCH)], cwd=ctx.current_path.parent)


def main(ctx: BabContext) -> None:
print("Debug Mode: Adding debugpy wheels")
_ = urllib.request.urlretrieve(DEBUGPY_WIN, f"{ctx.current_path}/wheels/debugpy-1.8.2-cp311-cp311-win_amd64.whl")
_ = urllib.request.urlretrieve(DEBUGPY_LINUX, f"{ctx.current_path}/wheels/debugpy-1.8.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl")
_ = urllib.request.urlretrieve(DEBUGPY_OSX, f"{ctx.current_path}/wheels/debugpy-1.8.2-py2.py3-none-any.whl")

validate_hash(f"{ctx.current_path}/wheels/debugpy-1.8.2-cp311-cp311-win_amd64.whl", DEBUGPY_HASH_WIN)
validate_hash(f"{ctx.current_path}/wheels/debugpy-1.8.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", DEBUGPY_HASH_LINUX)
validate_hash(f"{ctx.current_path}/wheels/debugpy-1.8.2-py2.py3-none-any.whl", DEBUGPY_HASH_OSX)

print("Debug Mode: Applying Patches")
_ = subprocess.run(["git", "apply", str(DEBUG_MODE_PATCH)], cwd=ctx.current_path.parent)


def clean_up(ctx: BabContext) -> None:
print("Debug Mode: Cleaning Up")
_ = subprocess.run(["git", "apply", "-R", str(DEBUG_MODE_PATCH)], cwd=ctx.current_path.parent)
13 changes: 13 additions & 0 deletions action-scripts/extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from bpy_addon_build.api import BabContext
import subprocess
from pathlib import Path

EXTENSION_BL_INFO_PATCH = Path(__file__).parent.joinpath("build-patches/extension-bl_info.diff")

def pre_build(ctx: BabContext) -> None:
print("Applying Extension Patches")
_ = subprocess.run(["git", "apply", str(EXTENSION_BL_INFO_PATCH)], cwd=ctx.current_path.parent)

def clean_up(ctx: BabContext) -> None:
print("Cleaning up patches")
_ = subprocess.run(["git", "apply", "-R", str(EXTENSION_BL_INFO_PATCH)], cwd=ctx.current_path.parent)
4 changes: 4 additions & 0 deletions bpy-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ build_actions:
script: "action-scripts/default.py"
dev:
script: "action-scripts/dev.py"
extension:
script: "action-scripts/extension.py"
debug:
script: "action-scripts/debug-build.py"
translate:
script: "action-scripts/translate.py"