Skip to content

Commit

Permalink
Clean up doc generation of Properties reference
Browse files Browse the repository at this point in the history
Used the new python code to get all props.
Signed-off-by: Gary Oberbrunner <[email protected]>
  • Loading branch information
garyo committed Aug 28, 2024
1 parent b902d8c commit 81b54e2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 48 deletions.
96 changes: 58 additions & 38 deletions Documentation/genPropertiesReference.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,86 @@

badlyNamedProperties = ["kOfxImageEffectFrameVarying", "kOfxImageEffectPluginRenderThreadSafety"]

def getPropertiesFromDir(sourcePath, recursive, props):
def getPropertiesFromFile(path):
"""Get all OpenFX property definitions from C header file.
if os.path.isdir(sourcePath):
files=sorted(os.listdir(sourcePath))
for f in files:
absF = sourcePath + '/' + f
if not recursive and os.path.isdir(absF):
Uses a heuristic to identify property #define lines:
anything starting with '#define' and containing 'Prop' in the name.
"""
props = set()
with open(path) as f:
try:
lines = f.readlines()
except UnicodeDecodeError as e:
logging.error(f'error reading {path}: {e}')
raise e
for l in lines:
# Detect lines that correspond to a property definition, e.g:
# #define kOfxPropLala "OfxPropLala"
splits=l.split()
if len(splits) < 3:
continue
else:
getPropertiesFromDir(absF,recursive,props)
elif os.path.isfile(sourcePath):
ext = os.path.splitext(sourcePath)[1]
if ext.lower() in ('.c', '.cxx', '.cpp', '.h', '.hxx', '.hpp'):
with open(sourcePath) as f:
try:
lines = f.readlines()
except UnicodeDecodeError as e:
print('WARNING: error in', sourcePath, ':')
raise e
for l in lines:
# Detect lines that correspond to a property definition, e.g:
# #define kOfxPropLala "OfxPropLala"
splits=l.split(' ')
if len(splits) != 3:
continue
if splits[0] != '#define':
continue
if 'Prop' in splits[1] and splits[1] != 'kOfxPropertySuite':
#if l.startswith('#define kOfx') and 'Prop' in l:
props.append(splits[1])
else:
raise ValueError('No such file or directory: %s' % sourcePath)
if splits[0] != '#define':
continue
# ignore these
nonProperties = ('kOfxPropertySuite',
# prop values, not props
'kOfxImageEffectPropColourManagementNone',
'kOfxImageEffectPropColourManagementBasic',
'kOfxImageEffectPropColourManagementCore',
'kOfxImageEffectPropColourManagementFull',
'kOfxImageEffectPropColourManagementOCIO',
)
if splits[1] in nonProperties:
continue
# these are props, as well as anything with Prop in the name
badlyNamedProperties = ("kOfxImageEffectFrameVarying",
"kOfxImageEffectPluginRenderThreadSafety")
if 'Prop' in splits[1] \
or any(s in splits[1] for s in badlyNamedProperties):
props.add(splits[1])
return props

def getPropertiesFromDir(dir):
"""
Recursively get all property definitions from source files in a dir.
"""

extensions = {'.c', '.h', '.cxx', '.hxx', '.cpp', '.hpp'}

props = set()
for root, _dirs, files in os.walk(dir):
for file in files:
# Get the file extension
file_extension = os.path.splitext(file)[1]

if file_extension in extensions:
file_path = os.path.join(root, file)
props |= getPropertiesFromFile(file_path)
return list(props)

def main(argv):

recursive=False
sourcePath=''
outputFile=''
try:
opts, args = getopt.getopt(argv,"i:o:r",["sourcePath=","outputFile","recursive"])
opts, args = getopt.getopt(argv,"i:o:r",["sourcePath=","outputFile"])
for opt,value in opts:
if opt == "-i":
sourcePath = value
elif opt == "-o":
outputFile = value
elif opt == "-r":
recursive=True

except getopt.GetoptError:
sys.exit(1)

props=badlyNamedProperties
getPropertiesFromDir(sourcePath, recursive, props)
props = getPropertiesFromDir(sourcePath)

with open(outputFile, 'w') as f:
f.write('.. _propertiesReference:\n')
f.write('Properties Reference\n')
f.write('=====================\n')
props.sort()
for p in props:
for p in sorted(props):
f.write('.. doxygendefine:: ' + p + '\n\n')

if __name__ == "__main__":
Expand Down
18 changes: 8 additions & 10 deletions Documentation/sources/Reference/ofxPropertiesReference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Properties Reference

.. doxygendefine:: kOfxImageEffectHostPropIsBackground

.. doxygendefine:: kOfxImageEffectHostPropNativeOrigin

.. doxygendefine:: kOfxImageEffectInstancePropEffectDuration

.. doxygendefine:: kOfxImageEffectInstancePropSequentialRender
Expand All @@ -47,18 +49,8 @@ Properties Reference

.. doxygendefine:: kOfxImageEffectPropColourManagementAvailableConfigs

.. doxygendefine:: kOfxImageEffectPropColourManagementBasic

.. doxygendefine:: kOfxImageEffectPropColourManagementConfig

.. doxygendefine:: kOfxImageEffectPropColourManagementCore

.. doxygendefine:: kOfxImageEffectPropColourManagementFull

.. doxygendefine:: kOfxImageEffectPropColourManagementNone

.. doxygendefine:: kOfxImageEffectPropColourManagementOCIO

.. doxygendefine:: kOfxImageEffectPropColourManagementStyle

.. doxygendefine:: kOfxImageEffectPropComponents
Expand Down Expand Up @@ -103,8 +95,12 @@ Properties Reference

.. doxygendefine:: kOfxImageEffectPropOpenCLEnabled

.. doxygendefine:: kOfxImageEffectPropOpenCLImage

.. doxygendefine:: kOfxImageEffectPropOpenCLRenderSupported

.. doxygendefine:: kOfxImageEffectPropOpenCLSupported

.. doxygendefine:: kOfxImageEffectPropOpenGLEnabled

.. doxygendefine:: kOfxImageEffectPropOpenGLRenderSupported
Expand Down Expand Up @@ -313,6 +309,8 @@ Properties Reference

.. doxygendefine:: kOfxParamPropShowTimeMarker

.. doxygendefine:: kOfxParamPropStringFilePathExists

.. doxygendefine:: kOfxParamPropStringMode

.. doxygendefine:: kOfxParamPropType
Expand Down

0 comments on commit 81b54e2

Please sign in to comment.