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

Moved addons into src/addons and added VSCode settings and app launcher scripts #35

Merged
merged 10 commits into from
Jul 19, 2024
2 changes: 2 additions & 0 deletions .github/workflows/re-use-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ jobs:
export BLENDER_VERSION=${{ inputs.blender-version }}

echo $GITHUB_TOKEN | docker login ghcr.io -u ${{ secrets.GH_USER }} --password-stdin
docker pull ghcr.io/poly-hammer/blender-linux:$BLENDER_VERSION
docker pull ghcr.io/poly-hammer/unreal-linux:$UNREAL_VERSION

cd ./tests
python run_tests.py
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ permissions:
jobs:
test-lts:
name: Test LTS
uses: poly-hammer/BlenderTools/.github/workflows/re-use-tests.yml@main
uses: poly-hammer/BlenderTools/.github/workflows/re-use-tests.yml@restructure-addons-for-better-dev-setup
secrets: inherit
with:
title: Test LTS
Expand All @@ -32,7 +32,7 @@ jobs:
test-latest:
needs: test-lts
name: Test Latest
uses: poly-hammer/BlenderTools/.github/workflows/re-use-tests.yml@main
uses: poly-hammer/BlenderTools/.github/workflows/re-use-tests.yml@restructure-addons-for-better-dev-setup
secrets: inherit
with:
title: Test Latest
Expand Down
54 changes: 49 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}
},
{
"name": "Run All Tests",
"name": "Debug Tests: Host Environment",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/tests/run_tests.py",
Expand All @@ -37,11 +37,12 @@
"cwd": "${workspaceFolder}/tests",
"justMyCode": false,
"env": {
"DOCKER_ENVIRONMENT": "${input:docker-environment}"
"EXCLUSIVE_TEST_FILES": "${input:test-file}",
"EXCLUSIVE_TESTS": "${input:test-name}",
}
},
{
"name": "Run Specific Tests",
"name": "Debug Tests: Docker Environment",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/tests/run_tests.py",
Expand All @@ -50,18 +51,50 @@
"cwd": "${workspaceFolder}/tests",
"justMyCode": false,
"env": {
"DOCKER_ENVIRONMENT": "yes",
"EXCLUSIVE_TEST_FILES": "${input:test-file}",
"EXCLUSIVE_TESTS": "${input:test-name}",
"DOCKER_ENVIRONMENT": "${input:docker-environment}"
"DEBUGGING_ON": "${input:debugging-on}"
}
},
{
"name": "Python Debugger: Attach Blender Docker",
"type": "debugpy",
"request": "attach",
"pathMappings": [
{
"localRoot": "${workspaceFolder}/",
"remoteRoot": "/tmp/blender_tools/"
}
],
"connect": {
"host": "localhost",
"port": 5668
}
},
{
"name": "Python Debugger: Attach Unreal Docker",
"type": "debugpy",
"request": "attach",
"pathMappings": [
{
"localRoot": "${workspaceFolder}/",
"remoteRoot": "/tmp/blender_tools/"
}
],
"connect": {
"host": "localhost",
"port": 5669
}
}
],
"inputs": [
{
"id": "test-file",
"type": "pickString",
"default": "test_send2ue_core.py",
"default": "all",
"options": [
"all",
"test_send2ue_core.py",
"test_send2ue_cubes.py",
"test_send2ue_extension_affixes.py",
Expand Down Expand Up @@ -90,7 +123,18 @@
{
"id": "test-name",
"type": "promptString",
"default": "all",
"description": "The name of the specific test to run"
},
{
"id": "debugging-on",
"type": "pickString",
"default": "",
"options": [
"no",
"yes"
],
"description": "Turn on remote debugging in the containers?"
}
]
}
2 changes: 1 addition & 1 deletion .vscode/python.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PYTHONPATH=';./.venv/Lib/site-packages'
PYTHONPATH=';./.venv/Lib/site-packages;./src/addons;./src/addons/send2ue/dependencies'
PYTHONUNBUFFERED=1
2 changes: 1 addition & 1 deletion docs/contributing/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ git checkout some-task-branch
```

## VSCode
The repo contains the tasks, launch actions, and settings for for developing with vscode. To get setup do the following:
The repo contains the tasks, launch actions, and settings for developing with vscode. To get setup do the following:

### Setup
1. Install the VSCode profile under `scripts/resources/profiles/dev.code-profile`. You can do this by typing `> Profile Import Profile` in the command pallette. This will give you all the vscode extensions you will need.
Expand Down
Binary file modified docs/contributing/images/development/2.2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 21 additions & 4 deletions scripts/resources/blender/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

logging.basicConfig(level=logging.DEBUG)

REPO_ROOT = Path(__file__).parent.parent.parent.parent
debug = os.environ.get('BLENDER_DEBUGGING_ON', 'no').lower() == 'yes'

ADDONS = {
'send2ue': Path(__file__).parent.parent.parent.parent / 'src',
'ue2rigify': Path(__file__).parent.parent.parent.parent / 'src'
'send2ue': REPO_ROOT / 'src',
'ue2rigify': REPO_ROOT / 'src'
}


Expand All @@ -28,6 +29,7 @@
script_directory = bpy.context.preferences.filepaths.script_directories.new()
script_directory.name = name # type: ignore
script_directory.directory = str(scripts_folder) # type: ignore
sys.path.append(os.path.join(str(scripts_folder), 'addons'))

try:
bpy.ops.script.reload()
Expand All @@ -46,11 +48,26 @@
import debugpy
port = int(os.environ.get('BLENDER_DEBUG_PORT', 5678))
debugpy.configure(python=os.environ.get('BLENDER_PYTHON_EXE', sys.executable))
debugpy.listen(port)
if os.environ.get('TEST_ENVIRONMENT'):
debugpy.listen(('0.0.0.0', port))
else:
debugpy.listen(port)
logger.info(f'Waiting for debugger to attach on port {port}...')
debugpy.wait_for_client()
except ImportError:
logger.error(
'Failed to initialize debugger because debugpy is not available '
'in the current python environment.'
)
)


if os.environ.get('TEST_ENVIRONMENT'):
from send2ue.dependencies.rpc.server import RPCServer
rpc_server = RPCServer()
rpc_server.start_server_blocking()
else:
from send2ue.dependencies.rpc import blender_server
rpc_server = blender_server.RPCServer()
rpc_server.start(threaded=True)

print('Blender RPC Server started')
31 changes: 26 additions & 5 deletions scripts/resources/unreal/init_unreal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,44 @@
import unreal
from pathlib import Path

REPO_ROOT = os.environ.get('CONTAINER_REPO_FOLDER')
if REPO_ROOT:
REPO_ROOT = Path(REPO_ROOT)
else:
REPO_ROOT = Path(__file__).parent.parent.parent.parent

debug = os.environ.get('UNREAL_DEBUGGING_ON', 'no').lower() == 'yes'

if debug:
try:
import debugpy
platform_folder = 'Linux'
python_exe_path = Path(sys.executable).parent.parent / 'ThirdParty' / 'Python3' / 'Linux' / 'bin' / 'python3'
if sys.platform == 'win32':
platform_folder = 'Win64'
python_exe_path = Path(sys.executable).parent.parent / 'ThirdParty' / 'Python3' / 'Win64' / 'python'

port = int(os.environ.get('UNREAL_DEBUG_PORT', 5679))
python_exe_path = Path(sys.executable).parent.parent / 'ThirdParty' / 'Python3' / platform_folder / 'python'
debugpy.configure(python=os.environ.get('UNREAL_PYTHON_EXE', str(python_exe_path)))
debugpy.listen(port)
if os.environ.get('TEST_ENVIRONMENT'):
debugpy.listen(('0.0.0.0', port))
else:
debugpy.listen(port)

unreal.log(f'Waiting for debugger to attach on port {port}...') # type: ignore
debugpy.wait_for_client()
except ImportError:
unreal.log_error( # type: ignore
'Failed to initialize debugger because debugpy is not available '
'in the current python environment.'
)
)

sys.path.append(str(REPO_ROOT / 'src' / 'addons'/ 'send2ue' / 'dependencies'))
if os.environ.get('TEST_ENVIRONMENT'):
from rpc.server import RPCServer
rpc_server = RPCServer()
rpc_server.start_server_blocking()
else:
from rpc import unreal_server
rpc_server = unreal_server.RPCServer()
rpc_server.start(threaded=True)

print('Unreal Engine RPC Server started')
19 changes: 7 additions & 12 deletions src/addons/send2ue/core/utilities.py
Copy link
Collaborator

Choose a reason for hiding this comment

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

will removing the chmod line potentially cause file permission issues?

Copy link
Author

Choose a reason for hiding this comment

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

It shouldnt, these chmod calls were causing permissions issues. They shouldnt need 777 to delete the files so I removed them.

Original file line number Diff line number Diff line change
Expand Up @@ -881,17 +881,12 @@ def remove_from_disk(path, directory=False):

:param str path: An file path.
:param bool directory: Whether or not the path is a directory.
"""
try:
original_umask = os.umask(0)
if os.path.exists(path):
os.chmod(path, 0o777)
if directory:
shutil.rmtree(path)
else:
os.remove(path)
finally:
os.umask(original_umask)
"""
if os.path.exists(path):
if directory:
shutil.rmtree(path, ignore_errors=True)
else:
os.remove(path)


def remove_temp_folder():
Expand All @@ -911,7 +906,7 @@ def remove_temp_data():
"""
temp_folder = get_temp_folder()
if os.path.exists(temp_folder):
shutil.rmtree(temp_folder)
shutil.rmtree(temp_folder, ignore_errors=True)


def remove_unpacked_files(unpacked_files):
Expand Down
2 changes: 1 addition & 1 deletion src/addons/send2ue/dependencies/remote_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import socket as _socket
import logging as _logging
import threading as _threading
import bpy

# Protocol constants (see PythonScriptRemoteExecution.cpp for the full protocol definition)
_PROTOCOL_VERSION = 1 # Protocol version number
Expand All @@ -34,6 +33,7 @@ class RemoteExecutionConfig(object):
Configuration data for establishing a remote connection with a Unreal Editor instance running Python.
'''
def __init__(self):
import bpy
# The multicast group endpoint tuple that the UDP multicast socket should join (must match the "Multicast Group Endpoint" setting in the Python plugin)
self.multicast_ttl = bpy.context.preferences.addons["send2ue"].preferences.multicast_ttl

Expand Down
3 changes: 1 addition & 2 deletions src/addons/send2ue/dependencies/rpc/base_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ def run_in_main_thread(callable_instance, *args):
globals().pop(ERROR_VALUE_NAME, None)
EXECUTION_QUEUE.put((callable_instance, args))

start_time = time.time()
while time.time() - start_time < timeout:
for attempt in range(timeout * 10):
if RETURN_VALUE_NAME in globals():
return globals().get(RETURN_VALUE_NAME)
elif ERROR_VALUE_NAME in globals():
Expand Down
10 changes: 6 additions & 4 deletions src/addons/send2ue/dependencies/unreal.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
default_imports=['import unreal'],
remap_pairs=REMAP_PAIRS,
)

rpc_client = rpc.client.RPCClient(port=UNREAL_PORT)
unreal_response = ''


Expand Down Expand Up @@ -170,6 +168,7 @@ def is_connected():
Checks the rpc server connection
"""
try:
rpc_client = rpc.client.RPCClient(port=UNREAL_PORT)
return rpc_client.proxy.is_running()
except (RemoteDisconnected, ConnectionRefusedError, ProtocolError):
return False
Expand All @@ -179,6 +178,7 @@ def set_rpc_env(key, value):
"""
Sets an env value on the unreal RPC server.
"""
rpc_client = rpc.client.RPCClient(port=UNREAL_PORT)
rpc_client.proxy.set_env(key, value)


Expand Down Expand Up @@ -1098,8 +1098,10 @@ def get_project_settings_value(config_name, section_name, setting_name):
:param str setting_name: The setting to query in the supplied section.
:return: Value of the queried setting.
"""
engine_config_dir = unreal.Paths.project_config_dir()
config_path = f'{engine_config_dir}{config_name}.ini'
uproject_path = unreal.Paths.get_project_file_path()
config_path = os.path.join(os.path.dirname(uproject_path), 'Config', f'{config_name}.ini') # type: ignore
if not os.path.exists(config_path):
return None

from configparser import ConfigParser
# setting strict to False to bypass duplicate keys in the config file
Expand Down
18 changes: 11 additions & 7 deletions src/addons/ue2rigify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ def unregister():
"""
Unregisters the addon classes when the addon is disabled.
"""
nodes.remove_pie_menu_hot_keys()
node_editor.unregister()
nodes.unregister()
operators.unregister()
view_3d.unregister()
addon_preferences.unregister()
properties.unregister()
try:
nodes.remove_pie_menu_hot_keys()
node_editor.unregister()
nodes.unregister()
operators.unregister()
view_3d.unregister()
addon_preferences.unregister()
properties.unregister()
except Exception as e:
print(f"Error un-registering UE2Rigify: \n{e}")

Loading
Loading