aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-06-16 13:36:45 -0400
committerDavid Robillard <d@drobilla.net>2022-07-17 17:08:38 -0400
commit85e480aa08aef7d20617bd084e8a61b745e0aed6 (patch)
treef3f534009470922fc87e195267eb029d02250079
parent487caa5868d816ae811c6a68f2bb9b1f5a798dbe (diff)
downloadlv2-85e480aa08aef7d20617bd084e8a61b745e0aed6.tar.xz
Format all Python code with black
-rwxr-xr-xlv2specgen/lv2docgen.py76
-rwxr-xr-xlv2specgen/lv2specgen.py31
-rwxr-xr-xplugins/literasc.py89
3 files changed, 103 insertions, 93 deletions
diff --git a/lv2specgen/lv2docgen.py b/lv2specgen/lv2docgen.py
index 3c44ccf..35237b3 100755
--- a/lv2specgen/lv2docgen.py
+++ b/lv2specgen/lv2docgen.py
@@ -20,25 +20,25 @@ import errno
import os
import sys
-__date__ = '2012-03-27'
-__version__ = '0.0.0'
-__authors__ = 'David Robillard'
-__license__ = 'ISC License <http://www.opensource.org/licenses/isc>'
-__contact__ = 'devel@lists.lv2plug.in'
+__date__ = "2012-03-27"
+__version__ = "0.0.0"
+__authors__ = "David Robillard"
+__license__ = "ISC License <http://www.opensource.org/licenses/isc>"
+__contact__ = "devel@lists.lv2plug.in"
try:
import rdflib
except ImportError:
- sys.exit('Error importing rdflib')
+ sys.exit("Error importing rdflib")
-doap = rdflib.Namespace('http://usefulinc.com/ns/doap#')
-lv2 = rdflib.Namespace('http://lv2plug.in/ns/lv2core#')
-rdf = rdflib.Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#')
-rdfs = rdflib.Namespace('http://www.w3.org/2000/01/rdf-schema#')
+doap = rdflib.Namespace("http://usefulinc.com/ns/doap#")
+lv2 = rdflib.Namespace("http://lv2plug.in/ns/lv2core#")
+rdf = rdflib.Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
+rdfs = rdflib.Namespace("http://www.w3.org/2000/01/rdf-schema#")
def uri_to_path(uri):
- path = uri[uri.find(':'):]
+ path = uri[uri.find(":") :]
while not path[0].isalpha():
path = path[1:]
return path
@@ -48,14 +48,14 @@ def get_doc(model, subject):
comment = model.value(subject, rdfs.comment, None)
if comment:
return '<p class="content">%s</p>' % comment
- return ''
+ return ""
def port_doc(model, port):
name = model.value(port, lv2.name, None)
html = '<div class="specterm"><h3>%s</h3>' % name
html += get_doc(model, port)
- html += '</div>'
+ html += "</div>"
return html
@@ -64,23 +64,29 @@ def plugin_doc(model, plugin, style_uri):
name = model.value(plugin, doap.name, None)
dtd = "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"
- html = '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" %s>
+ html = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" %s>
<html about="%s"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:lv2="http://lv2plug.in/ns/lv2core#"
- xml:lang="en">''' % (uri, dtd)
+ xml:lang="en">""" % (
+ uri,
+ dtd,
+ )
- html += '''<head>
+ html += """<head>
<title>%s</title>
<meta http-equiv="content-type" content="text/xhtml+xml; charset=utf-8" />
<meta name="generator" content="lv2docgen" />
<link href="%s" rel="stylesheet" type="text/css" />
</head>
- <body>''' % (name, style_uri)
+ <body>""" % (
+ name,
+ style_uri,
+ )
- html += '''
+ html += """
<!-- HEADER -->
<div id="header">
<h1 id="title">%s</h1>
@@ -89,45 +95,53 @@ def plugin_doc(model, plugin, style_uri):
<tr><th>Version</th><td>%s</td></tr>
</table>
</div>
-''' % (name, uri, uri, '0.0.0')
+""" % (
+ name,
+ uri,
+ uri,
+ "0.0.0",
+ )
html += get_doc(model, plugin)
- ports_html = ''
+ ports_html = ""
for p in model.triples([plugin, lv2.port, None]):
ports_html += port_doc(model, p[2])
if len(ports_html):
- html += '''
+ html += (
+ """
<h2 class="sec">Ports</h2>
<div class="content">
%s
- </div>''' % ports_html
+ </div>"""
+ % ports_html
+ )
- html += ' </body></html>'
+ html += " </body></html>"
return html
-if __name__ == '__main__':
- 'LV2 plugin documentation generator'
+if __name__ == "__main__":
+ "LV2 plugin documentation generator"
if len(sys.argv) < 2:
- print('Usage: %s OUTDIR FILE...' % sys.argv[0])
+ print("Usage: %s OUTDIR FILE..." % sys.argv[0])
sys.exit(1)
outdir = sys.argv[1]
files = sys.argv[2:]
model = rdflib.ConjunctiveGraph()
for f in files:
- model.parse(f, format='n3')
+ model.parse(f, format="n3")
- style_uri = os.path.abspath(os.path.join(outdir, 'style.css'))
+ style_uri = os.path.abspath(os.path.join(outdir, "style.css"))
for p in model.triples([None, rdf.type, lv2.Plugin]):
plugin = p[0]
html = plugin_doc(model, plugin, style_uri)
path = uri_to_path(plugin)
- outpath = os.path.join(outdir, path + '.html')
+ outpath = os.path.join(outdir, path + ".html")
try:
os.makedirs(os.path.dirname(outpath))
except OSError:
@@ -137,6 +151,6 @@ if __name__ == '__main__':
else:
raise
- print('Writing <%s> documentation to %s' % (plugin, outpath))
- with open(outpath, 'w') as out:
+ print("Writing <%s> documentation to %s" % (plugin, outpath))
+ with open(outpath, "w") as out:
out.write(html)
diff --git a/lv2specgen/lv2specgen.py b/lv2specgen/lv2specgen.py
index 8cad043..10b7cf9 100755
--- a/lv2specgen/lv2specgen.py
+++ b/lv2specgen/lv2specgen.py
@@ -254,9 +254,7 @@ def prettifyHtml(m, markup, subject, classlist, proplist, instalist):
# Syntax highlight all Turtle code
if have_pygments:
- code_rgx = re.compile(
- '<pre class="turtle-code">(.*?)</pre>', re.DOTALL
- )
+ code_rgx = re.compile('<pre class="turtle-code">(.*?)</pre>', re.DOTALL)
while True:
code = code_rgx.search(markup)
if not code:
@@ -373,9 +371,7 @@ def getDetailedDocumentation(m, subject, classlist, proplist, instalist):
if d:
doc = getObject(d)
if doc.datatype == lv2.Markdown:
- markup += formatDoc(
- m, subject, doc, classlist, proplist, instalist
- )
+ markup += formatDoc(m, subject, doc, classlist, proplist, instalist)
else:
html = getLiteralString(doc)
markup += prettifyHtml(
@@ -687,9 +683,7 @@ def extraInfo(term, m):
getTermLink(getObject(p), term, getPredicate(p)), first
)
elif isLiteral(getObject(p)):
- doc += getProperty(
- linkifyCodeIdentifiers(str(getObject(p))), first
- )
+ doc += getProperty(linkifyCodeIdentifiers(str(getObject(p))), first)
elif isBlank(getObject(p)):
doc += getProperty(str(blankNodeDesc(getObject(p), m)), first)
else:
@@ -1020,9 +1014,7 @@ def specAuthors(m, subject):
for d in sorted(dev):
if not first:
devdoc += ", "
- devdoc += (
- '<span class="author" property="doap:developer">%s</span>' % d
- )
+ devdoc += '<span class="author" property="doap:developer">%s</span>' % d
first = False
if len(dev) == 1:
doc += (
@@ -1191,10 +1183,7 @@ def load_tags(path, docdir):
def getChildText(elt, tagname):
"Return the content of the first child node with a certain tag name."
for e in elt.childNodes:
- if (
- e.nodeType == xml.dom.Node.ELEMENT_NODE
- and e.tagName == tagname
- ):
+ if e.nodeType == xml.dom.Node.ELEMENT_NODE and e.tagName == tagname:
return e.firstChild.nodeValue
return ""
@@ -1395,9 +1384,9 @@ def specgen(
m = rdflib.ConjunctiveGraph()
# RDFLib adds its own prefixes, so kludge around "time" prefix conflict
- m.namespace_manager.bind('time',
- rdflib.URIRef('http://lv2plug.in/ns/ext/time#'),
- replace=True)
+ m.namespace_manager.bind(
+ "time", rdflib.URIRef("http://lv2plug.in/ns/ext/time#"), replace=True
+ )
manifest_path = os.path.join(os.path.dirname(specloc), "manifest.ttl")
if os.path.exists(manifest_path):
@@ -1468,9 +1457,7 @@ def specgen(
# Generate Term HTML
classlist = docTerms("Class", classlist, m, classlist, proplist, instalist)
- proplist = docTerms(
- "Property", proplist, m, classlist, proplist, instalist
- )
+ proplist = docTerms("Property", proplist, m, classlist, proplist, instalist)
if instances:
instlist = docTerms(
"Instance", instalist, m, classlist, proplist, instalist
diff --git a/plugins/literasc.py b/plugins/literasc.py
index 6fd5d5b..82ee226 100755
--- a/plugins/literasc.py
+++ b/plugins/literasc.py
@@ -13,115 +13,124 @@ import os
import re
import sys
+
def format_text(text):
- 'Format a text (comment) fragment and return it as a marked up string'
- return '\n\n' + re.sub('\n *', '\n', text.strip()) + '\n\n'
+ "Format a text (comment) fragment and return it as a marked up string"
+ return "\n\n" + re.sub("\n *", "\n", text.strip()) + "\n\n"
+
def format_code(lang, code):
- if code.strip() == '':
+ if code.strip() == "":
return code
- head = '[source,%s]' % lang
- sep = '-' * len(head) + '\n'
- return head + '\n' + sep + code.strip('\n') + '\n' + sep
+ head = "[source,%s]" % lang
+ sep = "-" * len(head) + "\n"
+ return head + "\n" + sep + code.strip("\n") + "\n" + sep
+
def format_c_source(filename, file):
- output = '=== %s ===\n' % os.path.basename(filename)
- chunk = ''
- prev_c = 0
- in_comment = False
+ output = "=== %s ===\n" % os.path.basename(filename)
+ chunk = ""
+ prev_c = 0
+ in_comment = False
in_comment_start = False
- n_stars = 0
- code = ''
+ n_stars = 0
+ code = ""
for line in file:
code += line
# Skip initial license comment
- if code[0:2] == '/*':
- code = code[code.find('*/') + 2:]
+ if code[0:2] == "/*":
+ code = code[code.find("*/") + 2 :]
for c in code:
- if prev_c == '/' and c == '*':
+ if prev_c == "/" and c == "*":
in_comment_start = True
n_stars = 1
elif in_comment_start:
- if c == '*':
+ if c == "*":
n_stars += 1
else:
if n_stars > 1:
- output += format_code('c', chunk[0:len(chunk) - 1])
- chunk = ''
+ output += format_code("c", chunk[0 : len(chunk) - 1])
+ chunk = ""
in_comment = True
else:
- chunk += '*' + c
+ chunk += "*" + c
in_comment_start = False
- elif in_comment and prev_c == '*' and c == '/':
+ elif in_comment and prev_c == "*" and c == "/":
if n_stars > 1:
- output += format_text(chunk[0:len(chunk) - 1])
+ output += format_text(chunk[0 : len(chunk) - 1])
else:
- output += format_code('c', '/* ' + chunk[0:len(chunk) - 1] + '*/')
+ output += format_code(
+ "c", "/* " + chunk[0 : len(chunk) - 1] + "*/"
+ )
in_comment = False
in_comment_start = False
- chunk = ''
- elif in_comment_start and c == '*':
+ chunk = ""
+ elif in_comment_start and c == "*":
n_stars += 1
else:
chunk += c
prev_c = c
- return output + format_code('c', chunk)
+ return output + format_code("c", chunk)
+
def format_ttl_source(filename, file):
- output = '=== %s ===\n' % os.path.basename(filename)
+ output = "=== %s ===\n" % os.path.basename(filename)
in_comment = False
- chunk = ''
+ chunk = ""
for line in file:
- is_comment = line.strip().startswith('#')
+ is_comment = line.strip().startswith("#")
if in_comment:
if is_comment:
- chunk += line.strip().lstrip('# ') + ' \n'
+ chunk += line.strip().lstrip("# ") + " \n"
else:
output += format_text(chunk)
in_comment = False
chunk = line
else:
if is_comment:
- output += format_code('turtle', chunk)
+ output += format_code("turtle", chunk)
in_comment = True
- chunk = line.strip().lstrip('# ') + ' \n'
+ chunk = line.strip().lstrip("# ") + " \n"
else:
chunk += line
if in_comment:
return output + format_text(chunk)
else:
- return output + format_code('turtle', chunk)
+ return output + format_code("turtle", chunk)
+
def gen(out, filenames):
for filename in filenames:
file = open(filename)
if not file:
- sys.stderr.write('Failed to open file %s\n' % filename)
+ sys.stderr.write("Failed to open file %s\n" % filename)
continue
- if filename.endswith('.c') or filename.endswith('.h'):
+ if filename.endswith(".c") or filename.endswith(".h"):
out.write(format_c_source(filename, file))
- elif filename.endswith('.ttl') or filename.endswith('.ttl.in'):
+ elif filename.endswith(".ttl") or filename.endswith(".ttl.in"):
out.write(format_ttl_source(filename, file))
- elif filename.endswith('.txt'):
+ elif filename.endswith(".txt"):
for line in file:
out.write(line)
- out.write('\n')
+ out.write("\n")
else:
- sys.stderr.write("Unknown source format `%s'" % (
- filename[filename.find('.'):]))
+ sys.stderr.write(
+ "Unknown source format `%s'" % (filename[filename.find(".") :])
+ )
file.close()
+
if __name__ == "__main__":
if len(sys.argv) < 2:
- sys.stderr.write('Usage: %s FILENAME...\n' % sys.argv[1])
+ sys.stderr.write("Usage: %s FILENAME...\n" % sys.argv[1])
sys.exit(1)
gen(sys.argv[1:])