diff --git a/directdocs/acquireoriginal.py b/directdocs/acquireoriginal.py
index a1c32c92..49ed676e 100755
--- a/directdocs/acquireoriginal.py
+++ b/directdocs/acquireoriginal.py
@@ -1,5 +1,6 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
"""Builds links from the OpenGL.org man pages to our "original" directory"""
+from __future__ import absolute_import
import os, sys, glob, shutil, re, subprocess
MAN_TARGET = 'original'
diff --git a/directdocs/dumbmarkup.py b/directdocs/dumbmarkup.py
index 7ff1a3a0..b10ebba3 100644
--- a/directdocs/dumbmarkup.py
+++ b/directdocs/dumbmarkup.py
@@ -1,6 +1,8 @@
"""Simplistic wiki-like format parsing support"""
+from __future__ import absolute_import
import re,os,sys,textwrap, datetime
import logging
+import six
log = logging.getLogger( __name__ )
text_re = re.compile(
@@ -84,7 +86,7 @@ def child_function( match ):
return markup( text, child_function )
def append( self, value ):
"""Append given value to our content"""
- if isinstance( value, (str,unicode)):
+ if isinstance( value, (str,six.text_type)):
if self.children:
last_child = self.children[-1]
if last_child.tail:
diff --git a/directdocs/dumbpydoc.py b/directdocs/dumbpydoc.py
index fc65cc4e..9dc2f16a 100755
--- a/directdocs/dumbpydoc.py
+++ b/directdocs/dumbpydoc.py
@@ -1,7 +1,12 @@
#! /usr/bin/env python
"""Extremely dumb replacement for pydoc"""
+from __future__ import absolute_import
+from __future__ import print_function
from directdocs import model,references
import OpenGL
+import six
+from six.moves import range
+from six.moves import zip
OpenGL.USE_ACCELERATE = False # document the Python versions
OpenGL.MODULE_ANNOTATIONS = True # tell us where the constants/alternates are defined...
from OpenGL.extensions import _Alternate as Alternate
@@ -13,7 +18,7 @@
from OpenGL.GL import glGetString
from OpenGL.platform.baseplatform import _NullFunctionPointer as NullFunc
from OpenGL import platform
-import dumbmarkup
+from . import dumbmarkup
CythonMethod = type( platform.PLATFORM.GL.glGetString )
@@ -111,7 +116,7 @@ def inspect( self ):
if self._inspected:
return
self._inspected = True
- for key,value in sorted( self.mod.__dict__.items(), key=lambda x: x[0].lower()):
+ for key,value in sorted( list(self.mod.__dict__.items()), key=lambda x: x[0].lower()):
if self.interesting( value ):
for attr,types in self.FT_MAP:
if isinstance( value, types ):
@@ -129,8 +134,8 @@ def inspect( self ):
value = inspector( value, key )
collection.append( (key,value))
else:
- if not isinstance( value, (str,unicode,int,long,dict)):
- print 'not interesting', key, type(value)
+ if not isinstance( value, (str,six.text_type,int,int,dict)):
+ print('not interesting', key, type(value))
if self.is_package:
dirname = os.path.dirname( self.mod.__file__ )
for name in sorted(os.listdir( dirname )):
@@ -149,7 +154,7 @@ def sub_module( self, name ):
mod = PyModule( ".".join( [self.name,name] ))
try:
mod.inspect()
- except Exception, err:
+ except Exception as err:
log.warn( 'Unable to import %s: %s'%( mod.name, err ))
return None
else:
@@ -218,14 +223,14 @@ def docstring( self ):
if self.cls.__doc__:
try:
return textwrap.dedent( self.cls.__doc__ or '' )
- except TypeError, err:
+ except TypeError as err:
return None
else:
return None
def inspect( self ):
"""Introspect to find methods, properties, etceteras"""
- for key,value in sorted(self.cls.__dict__.items(), key=lambda x: x[0].lower()):
+ for key,value in sorted(list(self.cls.__dict__.items()), key=lambda x: x[0].lower()):
if isinstance( value, (
types.FunctionType,
types.MethodType,
@@ -249,7 +254,7 @@ def docstring( self ):
if self.target.__doc__:
try:
return textwrap.dedent( self.target.__doc__ or '' )
- except TypeError, err:
+ except TypeError as err:
return None
else:
return None
diff --git a/directdocs/generate.py b/directdocs/generate.py
index 5e170d2a..8e9b572f 100755
--- a/directdocs/generate.py
+++ b/directdocs/generate.py
@@ -1,15 +1,19 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
"""Generates the PyOpenGL reference documentation"""
+from __future__ import absolute_import
+from __future__ import print_function
import glob, os, datetime, subprocess, re, sys
#import elementtree.ElementTree as ET
import lxml.etree as ET
from genshi.template import TemplateLoader
import logging
+import six
log = logging.getLogger( 'generate' )
from directdocs.model import Function, Parameter, ParameterReference
from directdocs import model,references
from OpenGL import __version__
+from OpenGL._bytes import as_8_bit
from OpenGL import GL, GLU, GLUT, GLE,GLX
loader = TemplateLoader([os.path.join(os.path.dirname( __file__ ), 'templates')])
@@ -24,7 +28,7 @@
XML_NS = "http://www.w3.org/XML/1998/namespace"
LINK_NS = "http://www.w3.org/1999/xlink"
-WRAPPER = """
+WRAPPER = b"""
]>
%%s
-"""%( DOCBOOK_NS, MML_NS, LINK_NS )
+"""%tuple( as_8_bit(x) for x in [DOCBOOK_NS, MML_NS, LINK_NS ] )
IMPLEMENTATION_MODULES = [
# modules which contain external API entry points...
@@ -54,14 +58,14 @@ def get_crossref( self, title, volume=None,section=None ):
key = '%s.%s'%(title,volume)
if '(' in title:
title = title.split('(')[0]
- if self.sections.has_key( key ):
+ if key in self.sections:
return self.sections[key]
- elif self.section_titles.has_key( title ):
+ elif title in self.section_titles:
return self.section_titles[ title ]
- elif self.functions.has_key( title ):
+ elif title in self.functions:
return self.functions[title]
elif title.startswith( 'glX') or title.startswith( 'wgl' ):
- print 'Reference to', title, 'in', getattr(section,'title','Unknown')
+ print('Reference to', title, 'in', getattr(section,'title','Unknown'))
return None
else:
# try a linear scan for suffixed version...
@@ -133,7 +137,7 @@ def process( self, tree ):
elif id:
self.discussions.append(section)
elif not id:
- log.warn( 'Found reference section without id: %s', section.items() )
+ log.warn( 'Found reference section without id: %s', list(section.items()) )
self.discussions.append( section )
continue
processed_sections[ id ] = True
@@ -176,11 +180,11 @@ def process_funcprototype( self, node ):
data_type = typ,
name = paramname
))
- except Exception, err:
- print 'Failure retrieving parameter:', str(param)
+ except Exception as err:
+ print('Failure retrieving parameter:', str(param))
try:
function = self.functions[ funcname ]
- except KeyError, err:
+ except KeyError as err:
function = Function(funcname,self)
self.functions[ funcname ] = function
# err.args += (self.functions.keys(),)
@@ -209,7 +213,7 @@ def process_variablelist( self, node ):
self.varrefs.extend( set )
-HEADER_KILLER = re.compile( '[<][!]DOCTYPE.*?[>]', re.MULTILINE|re.DOTALL )
+HEADER_KILLER = re.compile( b'[<][!]DOCTYPE.*?[>]', re.MULTILINE|re.DOTALL )
def strip_bad_header( data ):
"""Header in the xml files declared from opengl.org doesn't declare namespaces but files use them"""
match = HEADER_KILLER.search( data )
@@ -219,18 +223,18 @@ def strip_bad_header( data ):
def load_file( filename ):
- data = WRAPPER%(strip_bad_header(open(filename).read()))
+ data = WRAPPER%(strip_bad_header(open(filename,'rb').read()))
# data = open(filename).read()
parser = ET.ETCompatXMLParser(resolve_entities=False)
try:
return filter_comments( ET.XML( data, parser ) )
- except Exception, err:
+ except Exception as err:
log.error( "Failure loading file: %r", filename )
raise
def filter_comments( tree ):
for element in tree:
- if isinstance(element.tag, (str,unicode)):
+ if isinstance(element.tag, (str,six.text_type)):
filter_comments( element )
else:
tree.remove( element )
@@ -238,7 +242,7 @@ def filter_comments( tree ):
def init_output( ):
if not os.path.isdir( OUTPUT_DIRECTORY ):
- print 'Creating new manual directory: %s'%(OUTPUT_DIRECTORY )
+ print('Creating new manual directory: %s'%(OUTPUT_DIRECTORY ))
os.mkdir( OUTPUT_DIRECTORY )
for file in os.listdir( 'output' ):
src = os.path.join( 'output', file )
@@ -271,7 +275,7 @@ def main():
log.info( 'Loading references' )
if os.path.isfile( references.CACHE_FILE ):
import pickle
- samples = pickle.loads( open(references.CACHE_FILE).read())
+ samples = pickle.loads( open(references.CACHE_FILE,'rb').read())
else:
log.warn( """Loading references directly, run ./references.py to pre-generate""" )
samples = references.loadData()
@@ -345,7 +349,7 @@ def main():
data = stream.render('html')
data = data.encode('utf-8')
open(
- output_file, 'w'
+ output_file, 'wb'
).write( data )
old_file = os.path.splitext( output_file )[0] + '.xhtml'
base = ref.url( section )
diff --git a/directdocs/model.py b/directdocs/model.py
index 9cf72d6f..ae4f5846 100644
--- a/directdocs/model.py
+++ b/directdocs/model.py
@@ -1,5 +1,7 @@
"""Modelling objects for the documentation generator"""
+from __future__ import absolute_import
import logging, types, inspect
+from six.moves import zip
log = logging.getLogger( 'directdocs.model' )
from OpenGL import __version__
@@ -95,8 +97,8 @@ def set_deprecation( self, value ):
def has_function( self, name ):
"""Ask whether we have this name defined"""
return (
- self.functions.has_key( name ) or
- self.py_functions.has_key( name )
+ name in self.functions or
+ name in self.py_functions
)
def get_module( self ):
"""Retrieve our module"""
@@ -135,7 +137,7 @@ def find_python_functions( self ):
alias = name,
)
self.py_functions[name] = function
- if not self.reference.functions.has_key( name ):
+ if name not in self.reference.functions:
self.reference.functions[ name ] = function
def get_samples( self, sample_set ):
"""Populate our sample-set for all of the available samples"""
@@ -146,11 +148,12 @@ def get_samples( self, sample_set ):
filtered = []
filter_set = {}
for name in names:
- if not filter_set.has_key( name ):
+ if name not in filter_set:
filtered.append( name )
for name in filtered:
- if sample_set.has_key( name ):
+ if name in sample_set:
self.samples.append( (name,Sample.joined(sample_set[name])))
+ self.samples.sort()
class Function( object ):
"""Function description produced from docs
@@ -260,7 +263,7 @@ def get_parameters( self, target ):
name, default=default_dict.get( name, NOT_DEFINED ),
function = self,
))
- except Exception, err:
+ except Exception as err:
import pdb
pdb.set_trace()
if varargs:
diff --git a/directdocs/oglctutorials.py b/directdocs/oglctutorials.py
index cc4e1848..f3371766 100755
--- a/directdocs/oglctutorials.py
+++ b/directdocs/oglctutorials.py
@@ -1,10 +1,13 @@
#! /usr/bin/env python
"""Generate the OpenGLContext shader tutorials from '''-string marked-up source code"""
+from __future__ import absolute_import
+from __future__ import print_function
import re,os,sys,textwrap, datetime
from genshi.template import TemplateLoader
import logging
+from six.moves import range
log = logging.getLogger( 'tutorials' )
-from dumbmarkup import *
+from .dumbmarkup import *
loader = TemplateLoader([os.path.join(os.path.dirname( __file__ ), 'templates')])
@@ -101,7 +104,7 @@ def generate_index( paths ):
)
data = stream.render( 'html' )
html_file = os.path.join( OUTPUT_DIRECTORY, 'index.html' )
- print 'writing', html_file
+ print('writing', html_file)
open( html_file, 'w').write( data )
redirect( html_file )
@@ -116,7 +119,7 @@ def generate( tutorial, prev=None, next=None, path=None ):
next=next,
)
data = stream.render( 'html' )
- print 'writing', tutorial.html_file
+ print('writing', tutorial.html_file)
open( tutorial.html_file, 'w').write( data )
redirect( tutorial.html_file )
diff --git a/directdocs/references.py b/directdocs/references.py
index 9cf03d2d..f814c243 100755
--- a/directdocs/references.py
+++ b/directdocs/references.py
@@ -1,5 +1,7 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
"""Collects sample-code references from file-system"""
+from __future__ import absolute_import
+from __future__ import print_function
import token, tokenize, glob, os
from directdocs.model import Sample
@@ -32,9 +34,11 @@ def glName( name ):
return True
return 0
-def glProcess( filename, tokenType,tokenString,(sourceRow,sourceCol),(endRow,endCol),lineText ):
+def glProcess( filename, tokenType,tokenString, xxx_todo_changeme4, xxx_todo_changeme5,lineText ):
"""Process the name in some way"""
- print filename, sourceRow, tokenString, lineText.strip()
+ (sourceRow,sourceCol) = xxx_todo_changeme4
+ (endRow,endCol) = xxx_todo_changeme5
+ print(filename, sourceRow, tokenString, lineText.strip())
def generate_tokens_file( filename, filterFunction=glName, processFunction=glProcess ):
@@ -47,7 +51,7 @@ def generate_tokens_file( filename, filterFunction=glName, processFunction=glPro
if tokenType == token.NAME and filterFunction and filterFunction(tokenString):
if processFunction:
processFunction( filename, tokenType, tokenString, (sourceRow,sourceCol),(endRow,endCol),lineText )
- except Exception, err:
+ except Exception as err:
pass
def generate_tokens_dir( directory, filterFunction=glName, processFunction=glProcess ):
@@ -91,11 +95,13 @@ def __init__(
self.urlTemplate = urlTemplate
self.baseURL = baseURL
self.suppressed = suppressed or {}
- def processEntry( self, filename, tokenType,tokenString,(sourceRow,sourceCol),(endRow,endCol),lineText ):
+ def processEntry( self, filename, tokenType,tokenString, xxx_todo_changeme, xxx_todo_changeme1,lineText ):
"""Record an entry from the scanner"""
+ (sourceRow,sourceCol) = xxx_todo_changeme
+ (endRow,endCol) = xxx_todo_changeme1
url = self.url( filename, (sourceRow,sourceCol),(endRow,endCol) )
deltaPath = self.deltaPath( filename )
- if not self.suppressed.has_key( deltaPath ):
+ if deltaPath not in self.suppressed:
self.nameMapping.setdefault(tokenString, []).append( Sample(
url=url,
projectName=self.projectName,
@@ -112,8 +118,10 @@ def deltaPath( self, filename ):
deltaPath = filename[len(os.path.commonprefix( (self.localDir, filename))):]
deltaPath = deltaPath.replace( '\\','/').lstrip( '/' )
return deltaPath
- def url( self, filename, (sourceRow,sourceCol),(endRow,endCol) ):
+ def url( self, filename, xxx_todo_changeme2, xxx_todo_changeme3 ):
"""Create a URL for the given filename"""
+ (sourceRow,sourceCol) = xxx_todo_changeme2
+ (endRow,endCol) = xxx_todo_changeme3
deltaPath = self.deltaPath( filename )
baseURL = self.baseURL.rstrip( '/' )
return self.urlTemplate %locals()
@@ -254,10 +262,10 @@ def loadData():
open( CACHE_FILE, 'wb').write(
pickle.dumps( items )
)
- items = items.items()
+ items = list(items.items())
items.sort()
for name, itemset in items:
- print name
+ print(name)
for item in itemset:
- print ' ', item.projectName, item.deltaPath, item.lineText
+ print(' ', item.projectName, item.deltaPath, item.lineText)
diff --git a/directdocs/samples.py b/directdocs/samples.py
index e0d288ce..d327f159 100755
--- a/directdocs/samples.py
+++ b/directdocs/samples.py
@@ -1,5 +1,7 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
"""Downloads project source checkouts for integration as samples"""
+from __future__ import absolute_import
+from __future__ import print_function
import os, subprocess
SAMPLE_DIRECTORY = '.samples'
@@ -202,6 +204,6 @@ def update_command( self ):
os.makedirs(SAMPLE_DIRECTORY)
os.chdir( '.samples' )
for checkout in checkouts:
- print('Project:', checkout.dirname)
+ print(('Project:', checkout.dirname))
checkout.update()
diff --git a/directdocs/templates/index.kid b/directdocs/templates/index.kid
index be604e59..f5da7270 100644
--- a/directdocs/templates/index.kid
+++ b/directdocs/templates/index.kid
@@ -9,9 +9,9 @@
@@ -50,11 +50,11 @@