Skip to content

Commit

Permalink
Fixed code errors in Python scripts flagged by pyflakes.
Browse files Browse the repository at this point in the history
```bash
$ flake8 python/scripts --select F
python/scripts/generateshader.py:28:13: F841 local variable 'result' is assigned to but never used
python/scripts/generateshader.py:86:16: F821 undefined name 'err'
python/scripts/generateshader.py:87:43: F821 undefined name 'err'
python/scripts/genmdl.py:8:1: F401 'string' imported but unused
python/scripts/genmdl.py:344:5: F841 local variable 'LIBRARY' is assigned to but never used
python/scripts/genmdl.py:525:21: F841 local variable 'outputvalue' is assigned to but never used
python/scripts/mxdoc.py:6:1: F401 'os' imported but unused
python/scripts/mxformat.py:7:1: F401 'sys' imported but unused
python/scripts/mxvalidate.py:6:1: F401 'os' imported but unused
python/scripts/mxvalidate.py:28:16: F821 undefined name 'err'
python/scripts/mxvalidate.py:29:19: F821 undefined name 'err'
```

With this patch:
```bash
$ flake8 python/scripts --select F --count
0
```

Found while working on AcademySoftwareFoundation#1595.

This commit follows 83ae82e.

Signed-off-by: Stefan Habel <[email protected]>
  • Loading branch information
StefanHabel committed Nov 26, 2023
1 parent 60c8a59 commit 4a6e2b1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions python/Scripts/generateshader.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def validateCode(sourceCodeFile, codevalidator, codevalidatorArgs):
print(cmd_flatten)
try:
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
result = output.decode(encoding='utf-8')
return output.decode(encoding='utf-8')
except subprocess.CalledProcessError as out:
return (out.output.decode(encoding='utf-8'))
return ""
Expand Down Expand Up @@ -83,7 +83,7 @@ def main():
try:
mx.loadLibraries(libraryFolders, searchPath, stdlib)
doc.importLibrary(stdlib)
except err:
except Exception as err:
print('Generation failed: "', err, '"')
sys.exit(-1)

Expand Down
10 changes: 6 additions & 4 deletions python/Scripts/genmdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
Generate MDL implementation directory based on MaterialX nodedefs
'''

import sys
import os
import string; os.environ['PYTHONIOENCODING'] = 'utf-8'
import sys

os.environ['PYTHONIOENCODING'] = 'utf-8'

import MaterialX as mx

def usage():
Expand Down Expand Up @@ -345,7 +347,7 @@ def main():

doc = mx.createDocument()
searchPath = os.path.join(_startPath, 'libraries')
libraryPath = os.path.join(searchPath, 'stdlib')
libraryPath = os.path.join(searchPath, LIBRARY)
_loadLibraries(doc, searchPath, libraryPath)

DEFINITION_PREFIX = 'ND_'
Expand Down Expand Up @@ -522,7 +524,7 @@ def main():
if isinstance(elem, mx.Output):
outputValue = elem.getAttribute('default')
if outputValue == '[]':
outputvalue = ''
outputValue = ''
if not outputValue:
outputValue = elem.getAttribute('defaultinput')
if outputValue:
Expand Down
4 changes: 3 additions & 1 deletion python/Scripts/mxdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Print markdown documentation for each nodedef in the given document.
'''

import sys, os, argparse
import argparse
import sys

import MaterialX as mx

HEADERS = ('Name', 'Type', 'Default Value',
Expand Down
4 changes: 3 additions & 1 deletion python/Scripts/mxformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
the documents to the latest version of the standard.
'''

import sys, os, argparse
import argparse
import os

import MaterialX as mx

def main():
Expand Down
6 changes: 4 additions & 2 deletions python/Scripts/mxvalidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
Verify that the given file is a valid MaterialX document.
'''

import sys, os, argparse
import argparse
import sys

import MaterialX as mx

def main():
Expand All @@ -25,7 +27,7 @@ def main():
stdlib = mx.createDocument()
try:
mx.loadLibraries(mx.getDefaultDataLibraryFolders(), mx.getDefaultDataSearchPath(), stdlib)
except err:
except Exception as err:
print(err)
sys.exit(0)
doc.importLibrary(stdlib)
Expand Down

0 comments on commit 4a6e2b1

Please sign in to comment.