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

Updated all the python files to Python3 #2924

Open
wants to merge 22 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
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": "x64-Debug (default)"
}
10 changes: 10 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"ExpandedNodes": [
"",
"\\scripts",
"\\scripts\\runtestsuite",
"\\scripts\\tools"
],
"SelectedNode": "\\.gitattributes",
"PreviewInSolutionExplorer": false
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file added .vs/appleseed/v15/.suo
Binary file not shown.
Binary file added .vs/appleseed/v15/Browse.VC.db
Binary file not shown.
Binary file added .vs/appleseed/v17/.wsuo
Binary file not shown.
Binary file added .vs/appleseed/v17/workspaceFileList.bin
Binary file not shown.
Binary file added .vs/slnx.sqlite
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#
# This source file is part of appleseed.
# Visit https://appleseedhq.net/ for additional information and resources.
Expand Down Expand Up @@ -55,3 +54,4 @@ def list_objects_in_assembly(ass):
child_assemblies = ass.assemblies()
for sub_ass_key in child_assemblies:
list_objects_in_assembly(child_assemblies[sub_ass_key])

3 changes: 2 additions & 1 deletion sandbox/share/aspaths2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
# -------------------------------------------------------------------------------------------------

def fatal(message):
print("Fatal: {0}. Aborting.".format(message))
print(f"Fatal: {message}. Aborting.")
sys.exit(1)


Expand Down Expand Up @@ -213,3 +213,4 @@ def main():

if __name__ == '__main__':
main()

5 changes: 3 additions & 2 deletions sandbox/share/mitsuba2appleseed.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
# THE SOFTWARE.
#

from __future__ import division
from __future__ import print_function


from xml.etree.ElementTree import ElementTree
import appleseed as asr
import argparse
Expand Down Expand Up @@ -955,3 +955,4 @@ def main():

if __name__ == '__main__':
main()

11 changes: 6 additions & 5 deletions sandbox/share/rfmdisneypresets2appleseed.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def main():
for root, dirname, files in os.walk(args.directory):
for filename in files:
if filename.endswith(".mel"):
print "Processing file: " + os.path.join(root, filename)
print("Processing file: " + os.path.join(root, filename))

material_name = filename.replace(".mel", "")

Expand All @@ -75,7 +75,7 @@ def main():

# Check if the material is a Disney BRDF
if not DISNEY_BRDF_KEYS.issubset(set(params.keys())):
print "Error: material preset %s is not a Disney BRDF." % material_name
print(f"Error: material preset {material_name} is not a Disney BRDF.")

if args.stop_error:
sys.exit(1)
Expand All @@ -84,21 +84,21 @@ def main():

# Check the material for possible incompatibilities
if params["emitColorR"] != "0.0" or params["emitColorG"] != "0.0" or params["emitColorB"] != "0.0":
print "Error: material %s preset uses emision." % material_name
print(f"Error: material {material_name} preset uses emision.")

if args.stop_error:
sys.exit(1)

# Subsurface color is missing in appleseed's Disney BRDF implementation.
if params["subsurface"] != "0.0":
if params["subsurfaceColorR"] != params["baseColorR"] or params["subsurfaceColorG"] != params["baseColorG"] or params["subsurfaceColorB"] != params["baseColorB"]:
print "Error: material preset %s uses subsurface color." % material_name
print(f"Error: material preset {material_name} uses subsurface color.")

if args.stop_error:
sys.exit(-1)

out_filename = os.path.join(args.output_directory, material_name + ".dmt")
print "Generating file: " + out_filename
print("Generating file: " + out_filename)

out_file = open(out_filename, "w")

Expand Down Expand Up @@ -133,3 +133,4 @@ def main():

if __name__ == "__main__":
main()

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#
# This source file is part of appleseed.
# Visit https://appleseedhq.net/ for additional information and resources.
Expand Down Expand Up @@ -151,7 +150,7 @@ def build_project():
color_name = "color_" + key
# Add colors to the project.
assembly.colors().insert(asr.ColorEntity(color_name, {"color_space": "linear_rgb", "multiplier": 1.0}, light_colors[key]))
idx = light_colors.keys().index(key)
idx = list(light_colors.keys()).index(key)
light_name = "light_" + key
# Create the light.
light = asr.Light("max_omni_light", light_name, {
Expand Down Expand Up @@ -240,3 +239,4 @@ def main():

if __name__ == "__main__":
main()

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#
# This source file is part of appleseed.
# Visit https://appleseedhq.net/ for additional information and resources.
Expand Down Expand Up @@ -26,7 +25,7 @@
# THE SOFTWARE.
#

from __future__ import print_function


import colorsys
import math
Expand Down Expand Up @@ -290,3 +289,4 @@ def main():

if __name__ == "__main__":
main()

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#
# This source file is part of appleseed.
# Visit https://appleseedhq.net/ for additional information and resources.
Expand Down Expand Up @@ -26,7 +25,7 @@
# THE SOFTWARE.
#

from __future__ import print_function


import colorsys
import math
Expand Down Expand Up @@ -170,7 +169,7 @@ def build_project():
assembly.lights().insert(light)

elif color == "mix":
for i in xrange(0, grid_lights_count * grid_lights_count):
for i in range(0, grid_lights_count * grid_lights_count):
s = random.uniform(0, 1)
if s < 0.65:
ran = random.gauss(1, 0.01)
Expand Down Expand Up @@ -282,4 +281,4 @@ def main():
asr.ProjectFileWriter().write(project, output_scene_name + ".appleseed")

if __name__ == "__main__":
main()
main()
5 changes: 2 additions & 3 deletions scripts/appleseed.benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@
# THE SOFTWARE.
#

from __future__ import print_function
import argparse
import datetime
import os
import re
import subprocess
import sys

from utils import print_runtime_details # local module
from .utils import print_runtime_details #local module


# -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -98,7 +97,7 @@ def benchmark_project(project_path, appleseed_path, appleseed_args, logger):
command_line += ["--benchmark-mode"]
command_line += ["-o", os.path.join("renders", project_name + ".png")]

output = subprocess.check_output(command_line, stderr=subprocess.STDOUT)
output = subprocess.run(command_line, capture_output=True, text=True).stdout

if was_successful(output):
process_output(output, logger)
Expand Down
26 changes: 14 additions & 12 deletions scripts/appleseed.package.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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 @@ -45,6 +45,7 @@
import time
import traceback
import zipfile
import shutil

from utils import print_runtime_details # local module

Expand All @@ -62,29 +63,29 @@
# 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 = "{0}\u2713{1}".format(colorama.Style.BRIGHT + colorama.Fore.GREEN, colorama.Style.RESET_ALL)
RED_CROSSMARK = "{0}\u2717{1}".format(colorama.Style.BRIGHT + colorama.Fore.RED, colorama.Style.RESET_ALL)


def trace(message):
if VERBOSE:
print(u" {0}{1}{2}".format(colorama.Style.DIM + colorama.Fore.WHITE, message, colorama.Style.RESET_ALL))
print(" {0}{1}{2}".format(colorama.Style.DIM + colorama.Fore.WHITE, message, colorama.Style.RESET_ALL))


def info(message):
print(u" {0}".format(message))
print(" {0}".format(message))


def progress(message):
print(u" {0}...".format(message))
print(" {0}...".format(message))


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


def fatal(message):
print(u"{0}Fatal: {1}. Aborting.{2}".format(colorama.Style.BRIGHT + colorama.Fore.RED, message, colorama.Style.RESET_ALL))
print("{0}Fatal: {1}. Aborting.{2}".format(colorama.Style.BRIGHT + colorama.Fore.RED, message, colorama.Style.RESET_ALL))
if sys.exc_info()[0]:
print(traceback.format_exc())
sys.exit(1)
Expand Down Expand Up @@ -176,7 +177,7 @@ def merge_tree(src, dst, symlinks=False, ignore=None):
shutil.copy2(srcname, dstname)
# Catch the Error from the recursive copytree so that we can
# continue with other files.
except Error as ex:
except shutil.Error as ex:
errors.extend(ex.args[0])
except EnvironmentError as ex:
errors.append((srcname, dstname, str(ex)))
Expand All @@ -189,7 +190,7 @@ def merge_tree(src, dst, symlinks=False, ignore=None):
else:
errors.append((src, dst, str(ex)))
if errors:
raise Error(errors)
raise shutil.Error(errors)


# -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -802,9 +803,9 @@ def get_dependencies_for_file(self, filepath, fix_paths=True, verbose=True):
trace(" Dependencies for file {0}:".format(filepath))
for lib in libs:
if os.path.isfile(lib):
trace(u" {0} {1}".format(GREEN_CHECKMARK, lib))
trace(" {0} {1}".format(GREEN_CHECKMARK, lib))
else:
trace(u" {0} {1}".format(RED_CROSSMARK, lib))
trace(" {0} {1}".format(RED_CROSSMARK, lib))

# Don't warn about missing dependencies if we didn't attempt to fix them.
if fix_paths:
Expand Down Expand Up @@ -1032,3 +1033,4 @@ def main():

if __name__ == "__main__":
main()

8 changes: 4 additions & 4 deletions scripts/cleanmany.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def walk(directory, recursive):
for filename in filenames:
yield os.path.join(dirpath, filename)
else:
dirpath, dirnames, filenames = os.walk(directory).next()
dirpath, dirnames, filenames = next(os.walk(directory))
for filename in filenames:
yield os.path.join(dirpath, filename)

Expand All @@ -64,7 +64,7 @@ def walk(directory, recursive):
# -------------------------------------------------------------------------------------------------

def clean_project_file(filepath, tool_path):
print("cleaning {0}...".format(filepath))
print(f"cleaning {filepath}...")
subprocess.call([tool_path, "clean", filepath])


Expand Down Expand Up @@ -104,13 +104,13 @@ def main():
if args.tool_path is None:
script_directory = os.path.dirname(os.path.realpath(__file__))
args.tool_path = os.path.join(script_directory, DEFAULT_TOOL_FILENAME)
print("setting tool path to {0}.".format(args.tool_path))
print(f"setting tool path to {args.tool_path}.")

start_time = datetime.datetime.now()
cleaned_file_count = clean_project_files(args.tool_path, args.directory, args.recursive)
end_time = datetime.datetime.now()

print("cleaned {0} project file(s) in {1}.".format(cleaned_file_count, end_time - start_time))
print(f"cleaned {cleaned_file_count} project file(s) in {end_time - start_time}.")


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion scripts/convertmany.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def walk(directory, recursive):
for filename in filenames:
yield os.path.join(dirpath, filename)
else:
dirpath, dirnames, filenames = os.walk(directory).next()
dirpath, dirnames, filenames = next(os.walk(directory))
for filename in filenames:
yield os.path.join(dirpath, filename)

Expand Down
17 changes: 11 additions & 6 deletions scripts/oslextractmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import sys
import argparse
try:
from ConfigParser import ConfigParser
from configparser import ConfigParser
except:
from configparser import ConfigParser
import datetime
Expand Down Expand Up @@ -309,11 +309,15 @@ def getNumberOfShaders(jsonFile):

def cleanJsonShaders(jsonDict):
num_del = 0
for shaderpath in jsonDict.keys():
keys_to_delete = []
for shaderpath, _ in jsonDict.items():
if not os.path.isfile(shaderpath):
del jsonDict[shaderpath]
keys_to_delete.append(shaderpath)
num_del += 1
return (num_del, jsonDict)
for shaderpath in keys_to_delete:
del jsonDict[shaderpath]
return num_del, jsonDict



def existsJsonShader(jsonFile, shaderName):
Expand Down Expand Up @@ -436,8 +440,8 @@ def main():
# only adding new shaders
else:
temp_changes = changes
if jsonDict.has_key('shaders'):
existing_keys = jsonDict['shaders'].keys()
if 'shaders' in jsonDict:
existing_keys = list(jsonDict['shaders'].keys())
for key in shaders:
if key not in existing_keys:
jsonDict['shaders'][key] = shaders[key]
Expand Down Expand Up @@ -468,3 +472,4 @@ def main():

if __name__ == "__main__":
main()

Loading