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

Update to Python3 #533

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions operators/osl_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def execute(self, context):

if node.script is not None:
# Save existing connections and parameters
for key, value in node.items():
for key, value in list(node.items()):
temp_values[key] = value
for input_iter in node.inputs:
if input_iter.is_linked:
Expand Down Expand Up @@ -91,20 +91,20 @@ def execute(self, context):
setattr(new_node, "node_type", "osl_script")

# Copy variables to new node
for variable, value in temp_values.items():
for variable, value in list(temp_values.items()):
if variable in dir(new_node):
setattr(new_node, variable, value)

# Recreate node connections
for connection, sockets in output_connections.items():
for connection, sockets in list(output_connections.items()):
for output in new_node.outputs:
if output.bl_idname == connection:
output_socket_class = output
if output_socket_class:
for output_connection in sockets:
node_tree.links.new(output_socket_class,
output_connection)
for connection, sockets in input_connections.items():
for connection, sockets in list(input_connections.items()):
for in_socket in new_node.inputs:
if in_socket.bl_idname == connection:
input_socket_class = in_socket
Expand All @@ -129,3 +129,4 @@ def register():

def unregister():
util.safe_unregister_class(ASMAT_OT_compile_script)

2 changes: 1 addition & 1 deletion preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def draw(self, context):

lib_info = asr.get_third_parties_versions()

for key, item in lib_info.items():
for key, item in list(lib_info.items()):
box.label(text=f"{key} version {item}")


Expand Down
17 changes: 9 additions & 8 deletions properties/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def draw_buttons(self, context, layout):
param_section = ""
for x in self.input_params:
if x['type'] != 'pointer':
if 'hide_ui' in x.keys() and x['hide_ui'] is True:
if 'hide_ui' in list(x.keys()) and x['hide_ui'] is True:
continue
if 'section' in x.keys():
if 'section' in list(x.keys()):
if x['section'] != param_section and x['section'] is not None:
param_section = x['section']
icon = 'DISCLOSURE_TRI_DOWN' if getattr(self, param_section) else 'DISCLOSURE_TRI_RIGHT'
Expand Down Expand Up @@ -111,7 +111,7 @@ def draw_buttons(self, context, layout):
def draw_buttons_ext(self, context, layout):
for x in self.input_params:
if x['type'] != 'pointer':
if 'hide_ui' in x.keys() and x['hide_ui'] is True:
if 'hide_ui' in list(x.keys()) and x['hide_ui'] is True:
continue
elif x['name'] in self.filepaths:
layout.template_ID_preview(self, x['name'], open="image.open")
Expand Down Expand Up @@ -153,9 +153,9 @@ def draw_buttons(self, context, layout):
if hasattr(self, "input_params"):
for x in self.input_params:
if x['type'] != 'pointer':
if 'hide_ui' in x.keys() and x['hide_ui'] is True:
if 'hide_ui' in list(x.keys()) and x['hide_ui'] is True:
continue
if 'section' in x.keys():
if 'section' in list(x.keys()):
if x['section'] != param_section and x['section'] is not None:
param_section = x['section']
icon = 'DISCLOSURE_TRI_DOWN' if getattr(self, param_section) else 'DISCLOSURE_TRI_RIGHT'
Expand Down Expand Up @@ -187,7 +187,7 @@ def draw_buttons_ext(self, context, layout):
if hasattr(self, "input_params"):
for x in self.input_params:
if x['type'] != 'pointer':
if 'hide_ui' in x.keys() and x['hide_ui'] is True:
if 'hide_ui' in list(x.keys()) and x['hide_ui'] is True:
continue
elif x['name'] in self.filepaths:
layout.template_ID_preview(self, x['name'], open="image.open")
Expand Down Expand Up @@ -249,7 +249,7 @@ def node_categories(osl_nodes):

from ..translators.cycles_shaders import cycles_nodes

cyc_nodes = [nodeitems_utils.NodeItem(key) for key in cycles_nodes.keys()]
cyc_nodes = [nodeitems_utils.NodeItem(key) for key in list(cycles_nodes.keys())]

for node in osl_nodes:
node_item = nodeitems_utils.NodeItem(node[0])
Expand Down Expand Up @@ -327,7 +327,7 @@ def register():


def unregister():
for pcoll in preview_collections.values():
for pcoll in list(preview_collections.values()):
bpy.utils.previews.remove(pcoll)
preview_collections.clear()

Expand All @@ -337,3 +337,4 @@ def unregister():

for cls in reversed(classes):
util.safe_unregister_class(cls)

1 change: 1 addition & 0 deletions properties/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,3 +785,4 @@ def unregister():

for cls in reversed(classes):
util.safe_unregister_class(cls)

3 changes: 2 additions & 1 deletion render/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def view_draw(self, context, depsgraph):
# Check if view camera model has changes
updates = self.__interactive_scene_translator.check_view_window(depsgraph, context)

if True in updates.values():
if True in list(updates.values()):
self.__pause_rendering()
self.__interactive_scene_translator.update_view_window(updates, depsgraph)
self.__restart_interactive_render()
Expand Down Expand Up @@ -445,3 +445,4 @@ def register():

def unregister():
safe_unregister_class(RenderAppleseed)

74 changes: 41 additions & 33 deletions scripts/blenderseed.package.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# THE SOFTWARE.
#

from __future__ import print_function

from distutils import archive_util, dir_util
from xml.etree.ElementTree import ElementTree
import argparse
Expand All @@ -43,7 +43,7 @@
import sys
import time
import traceback
import urllib
import urllib.request, urllib.parse, urllib.error


#--------------------------------------------------------------------------------------------------
Expand All @@ -57,30 +57,33 @@
#--------------------------------------------------------------------------------------------------
# Utility functions.
#--------------------------------------------------------------------------------------------------

GREEN_CHECKMARK = u"{0}\u2713{1}".format(colorama.Style.BRIGHT + colorama.Fore.GREEN, colorama.Style.RESET_ALL)
RED_CROSSMARK = u"{0}\u2717{1}".format(colorama.Style.BRIGHT + colorama.Fore.RED, colorama.Style.RESET_ALL)
GREEN_CHECKMARK = f"{colorama.Style.BRIGHT}{colorama.Fore.GREEN}\u2713{colorama.Style.RESET_ALL}"
RED_CROSSMARK = f"{colorama.Style.BRIGHT}{colorama.Fore.RED}\u2717{colorama.Style.RESET_ALL}"


def trace(message):
# encode('utf-8') is required to support output redirection to files or pipes.
print(u" {0}{1}{2}".format(colorama.Style.DIM + colorama.Fore.WHITE, message, colorama.Style.RESET_ALL).encode('utf-8'))
print(f" {colorama.Style.DIM}{colorama.Fore.WHITE}{message}{colorama.Style.RESET_ALL}".encode('utf-8'))



def info(message):
print(u" {0}".format(message).encode('utf-8'))
print(f" {message}".encode('utf-8'))



def progress(message):
print(u" {0}...".format(message).encode('utf-8'))
print(f" {message}...".encode('utf-8'))



def warning(message):
print(u" {0}Warning: {1}.{2}".format(colorama.Style.BRIGHT + colorama.Fore.MAGENTA, message, colorama.Style.RESET_ALL).encode('utf-8'))
print(f" {colorama.Style.BRIGHT}{colorama.Fore.MAGENTA}{message}{colorama.Style.RESET_ALL}Warning: {message}.{colorama.Style.RESET_ALL}".encode('utf-8'))



def fatal(message):
print(u"{0}Fatal: {1}. Aborting.{2}".format(colorama.Style.BRIGHT + colorama.Fore.RED, message, colorama.Style.RESET_ALL).encode('utf-8'))
print(f"{colorama.Style.BRIGHT}{colorama.Fore.RED}Fatal: {message}. Aborting.{colorama.Style.RESET_ALL}".encode('utf-8'))
if sys.exc_info()[0]:
print(traceback.format_exc())
sys.exit(1)
Expand Down Expand Up @@ -190,7 +193,7 @@ def __load_values(self, tree):
def __get_required(self, tree, key):
value = tree.findtext(key)
if value is None:
fatal("Missing value \"{0}\" in configuration file".format(key))
fatal(f"Missing value \"{key}\" in configuration file")
return value


Expand Down Expand Up @@ -291,7 +294,7 @@ def download_settings_files(self):
safe_make_directory(settings_dir)

for file in ["appleseed.cli.xml"]:
urllib.urlretrieve(
urllib.request.urlretrieve(
"https://raw.githubusercontent.com/appleseedhq/appleseed/master/sandbox/settings/{0}".format(file),
os.path.join(settings_dir, file))

Expand Down Expand Up @@ -319,17 +322,17 @@ def clean_stage(self):

def build_final_zip_file(self):
progress("Building final zip file from staging directory")
package_name = "blenderseed-{0}-{1}-{2}".format(self.package_version, self.settings.platform, self.build_date)
package_name = f"blenderseed-{self.package_version}-{self.settings.platform}-{self.build_date}"
package_path = os.path.join(self.settings.output_dir, package_name)
archive_util.make_zipfile(package_path, "blenderseed")
info("Package path: {0}".format(package_path + ".zip"))
info(f"Package path: {package_path}.zip")

def remove_stage(self):
progress("Deleting staging directory")
safe_delete_directory("blenderseed")

def run(self, cmdline):
trace("Running command line: {0}".format(cmdline))
trace(f"Running command line: {cmdline}")
os.system(cmdline)

def run_subprocess(self, cmdline):
Expand Down Expand Up @@ -406,12 +409,12 @@ def copy_dependencies(self):
# Print dependencies.
trace(" Dependencies:")
for lib in all_libs:
trace(" {0}".format(lib))
trace(f" {lib}")

# Copy needed libs to lib directory.
for lib in all_libs:
if True:
trace(" Copying {0} to {1}...".format(lib, lib_dir))
trace(f" Copying {lib} to {lib_dir}...")
shutil.copy(lib, lib_dir)

def post_process_package(self):
Expand Down Expand Up @@ -453,23 +456,25 @@ def __change_library_paths_in_executables(self):

# Can be used on executables and dynamic libraries.
def __change_library_paths_in_binary(self, bin_path):
progress("Patching {0}".format(bin_path))
progress(f"Patching {bin_path}")
bin_dir = os.path.dirname(bin_path)
lib_dir = os.path.join(self.settings.root_dir, "appleseed", "lib")
path_to_appleseed_lib = os.path.relpath(lib_dir, bin_dir)
# fix_paths set to False because we must retrieve the unmodified dependency in order to replace it by the correct one.
for lib_path in self.__get_dependencies_for_file(bin_path, fix_paths=False):
lib_name = os.path.basename(lib_path)
if path_to_appleseed_lib == ".":
self.__change_library_path(bin_path, lib_path, "@loader_path/{0}".format(lib_name))
self.__change_library_path(bin_path, lib_path, f"@loader_path/{lib_name}")
else:
self.__change_library_path(bin_path, lib_path, "@loader_path/{0}/{1}".format(path_to_appleseed_lib, lib_name))
self.__change_library_path(bin_path, lib_path, f"@loader_path/{path_to_appleseed_lib}/{lib_name}")


def __set_library_id(self, target, name):
self.run('install_name_tool -id "{0}" {1}'.format(name, target))
self.run(f'install_name_tool -id "{name}" {target}')

def __change_library_path(self, target, old, new):
self.run('install_name_tool -change "{0}" "{1}" {2}'.format(old, new, target))
self.run(f'install_name_tool -change "{old}" "{new}" {target}')


def __get_dependencies_for_file(self, filepath, fix_paths=True):
filename = os.path.basename(filepath)
Expand All @@ -479,15 +484,17 @@ def __get_dependencies_for_file(self, filepath, fix_paths=True):

if True:
trace("Gathering dependencies for file")
trace(" {0}".format(filepath))
trace(f" {filepath}")
trace("with @loader_path set to")
trace(" {0}".format(loader_path))
trace(f" {loader_path}")
trace("and @rpath hardcoded to")
trace(" {0}".format(rpath))
trace(f" {rpath}")


returncode, out, err = self.run_subprocess(["otool", "-L", filepath])
if returncode != 0:
fatal("Failed to invoke otool(1) to get dependencies for {0}: {1}".format(filepath, err))
fatal(f"Failed to invoke otool(1) to get dependencies for {filepath}: {err}")


libs = set()

Expand All @@ -501,7 +508,7 @@ def __get_dependencies_for_file(self, filepath, fix_paths=True):
# Parse the line.
m = re.match(r"(.*) \(compatibility version .*, current version .*\)", line)
if not m:
fatal("Failed to parse line from otool(1) output: " + line)
fatal(f"Failed to parse line from otool(1) output: {line}")
lib = m.group(1)

# Ignore self-references (why do these happen?).
Expand Down Expand Up @@ -530,24 +537,25 @@ def __get_dependencies_for_file(self, filepath, fix_paths=True):
if not os.path.exists(candidate):
candidate = os.path.join("/usr/local/lib/", lib)
if os.path.exists(candidate):
info("Resolved relative dependency {0} as {1}".format(lib, candidate))
info(f"Resolved relative dependency {lib} as {candidate}")
lib = candidate

libs.add(lib)

if True:
trace("Dependencies for file {0}:".format(filepath))
trace(f"Dependencies for file {filepath}:")
for lib in libs:
if os.path.isfile(lib):
trace(u" {0} {1}".format(GREEN_CHECKMARK, lib))
trace(f" {GREEN_CHECKMARK} {lib}")
else:
trace(u" {0} {1}".format(RED_CROSSMARK, lib))
trace(f" {RED_CROSSMARK} {lib}")


# Don't check for missing dependencies if we didn't attempt to fix them.
if fix_paths:
for lib in libs:
if not os.path.isfile(lib):
fatal("Dependency {0} could not be found on disk".format(lib))
fatal(f"Dependency {lib} could not be found on disk")

return libs

Expand Down Expand Up @@ -652,7 +660,7 @@ def __is_system_lib(self, lib):
def __get_dependencies_for_file(self, filepath):
returncode, out, err = self.run_subprocess(["ldd", filepath])
if returncode != 0:
fatal("Failed to invoke ldd(1) to get dependencies for {0}: {1}".format(filepath, err))
fatal(f"Failed to invoke ldd(1) to get dependencies for {filepath}: {err}")

libs = set()

Expand Down
Loading