diff options
author | Matthew Peveler <matt.peveler@gmail.com> | 2020-05-30 02:57:52 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-29 19:57:52 -0400 |
commit | af1e383a123efb4281c49bc77e2b4581b591c83d (patch) | |
tree | c993805fc100a0280a698e57bab1189ea05abe05 | |
parent | 273e07c071de446457a57352b2973729e947e703 (diff) | |
download | asciidoc-py3-af1e383a123efb4281c49bc77e2b4581b591c83d.tar.gz |
clean-up filters to adhere to flake8 (#118)
Signed-off-by: Matthew Peveler <matt.peveler@gmail.com>
-rw-r--r-- | asciidocapi.py | 31 | ||||
-rwxr-xr-x | filters/code/code-filter.py | 133 | ||||
-rwxr-xr-x | filters/graphviz/graphviz2png.py | 75 | ||||
-rwxr-xr-x | filters/latex/latex2img.py | 76 | ||||
-rwxr-xr-x | filters/music/music2png.py | 69 | ||||
-rwxr-xr-x | filters/unwraplatex.py | 8 | ||||
-rw-r--r-- | tests/data/barchart.py | 6 | ||||
-rwxr-xr-x | tests/testasciidoc.py | 2 |
8 files changed, 249 insertions, 151 deletions
diff --git a/asciidocapi.py b/asciidocapi.py index 84bbcfd..745aa10 100644 --- a/asciidocapi.py +++ b/asciidocapi.py @@ -52,7 +52,9 @@ under the terms of the GNU General Public License (GPL). """ -import sys,os,re +import sys +import os +import re API_VERSION = '0.1.2' MIN_ASCIIDOC_VERSION = '8.4.1' # Minimum acceptable AsciiDoc version. @@ -82,13 +84,15 @@ class Options(object): """ def __init__(self, values=[]): self.values = values[:] + def __call__(self, name, value=None): """Shortcut for append method.""" self.append(name, value) + def append(self, name, value=None): - if type(value) in (int,float): + if type(value) in (int, float): value = str(value) - self.values.append((name,value)) + self.values.append((name, value)) class Version(object): @@ -159,7 +163,9 @@ class Version(object): return True def __eq__(self, other): - if self.major == other.major and self.minor == other.minor and self.micro == other.micro: + if self.major == other.major \ + and self.minor == other.minor \ + and self.micro == other.micro: return True return False @@ -194,18 +200,21 @@ class AsciiDocAPI(object): else: # try to find sibling paths this_path = os.path.dirname(os.path.realpath(__file__)) - for fname in ['asciidoc.py','asciidoc.pyc','asciidoc']: + for fname in ['asciidoc.py', 'asciidoc.pyc', 'asciidoc']: cmd = find_in_path(fname, path=this_path) - if cmd: break + if cmd: + break else: # Try shell search paths. - for fname in ['asciidoc.py','asciidoc.pyc','asciidoc']: + for fname in ['asciidoc.py', 'asciidoc.pyc', 'asciidoc']: cmd = find_in_path(fname) - if cmd: break + if cmd: + break else: # Finally try current working directory. - for cmd in ['asciidoc.py','asciidoc.pyc','asciidoc']: - if os.path.isfile(cmd): break + for cmd in ['asciidoc.py', 'asciidoc.pyc', 'asciidoc']: + if os.path.isfile(cmd): + break else: raise AsciiDocError('failed to locate asciidoc') self.cmd = os.path.realpath(cmd) @@ -219,7 +228,7 @@ class AsciiDocAPI(object): for an explanation of why a seemingly straight-forward job turned out quite complicated. ''' - if os.path.splitext(self.cmd)[1] in ['.py','.pyc']: + if os.path.splitext(self.cmd)[1] in ['.py', '.pyc']: sys.path.insert(0, os.path.dirname(self.cmd)) try: try: diff --git a/filters/code/code-filter.py b/filters/code/code-filter.py index ac9e775..40689c7 100755 --- a/filters/code/code-filter.py +++ b/filters/code/code-filter.py @@ -50,7 +50,9 @@ COPYING granted under the terms of the GNU General Public License (GPL). ''' -import os, sys, re +import os +import sys +import re VERSION = '1.1.2' @@ -60,52 +62,58 @@ backend = None tabsize = 8 keywordtags = { 'html': - ('<strong>','</strong>'), + ('<strong>', '</strong>'), 'css': - ('<strong>','</strong>'), + ('<strong>', '</strong>'), 'docbook': - ('<emphasis role="strong">','</emphasis>'), + ('<emphasis role="strong">', '</emphasis>'), 'linuxdoc': - ('','') + ('', '') } commenttags = { 'html': - ('<i>','</i>'), + ('<i>', '</i>'), 'css': - ('<i>','</i>'), + ('<i>', '</i>'), 'docbook': - ('<emphasis>','</emphasis>'), + ('<emphasis>', '</emphasis>'), 'linuxdoc': - ('','') + ('', '') } keywords = { 'python': - ('and', 'del', 'for', 'is', 'raise', 'assert', 'elif', 'from', - 'lambda', 'return', 'break', 'else', 'global', 'not', 'try', 'class', - 'except', 'if', 'or', 'while', 'continue', 'exec', 'import', 'pass', - 'yield', 'def', 'finally', 'in', 'print'), + ( + 'and', 'del', 'for', 'is', 'raise', 'assert', 'elif', 'from', + 'lambda', 'return', 'break', 'else', 'global', 'not', 'try', 'class', + 'except', 'if', 'or', 'while', 'continue', 'exec', 'import', 'pass', + 'yield', 'def', 'finally', 'in', 'print' + ), 'ruby': - ('__FILE__', 'and', 'def', 'end', 'in', 'or', 'self', 'unless', - '__LINE__', 'begin', 'defined?' 'ensure', 'module', 'redo', 'super', - 'until', 'BEGIN', 'break', 'do', 'false', 'next', 'rescue', 'then', - 'when', 'END', 'case', 'else', 'for', 'nil', 'retry', 'true', 'while', - 'alias', 'class', 'elsif', 'if', 'not', 'return', 'undef', 'yield'), + ( + '__FILE__', 'and', 'def', 'end', 'in', 'or', 'self', 'unless', + '__LINE__', 'begin', 'defined?' 'ensure', 'module', 'redo', 'super', + 'until', 'BEGIN', 'break', 'do', 'false', 'next', 'rescue', 'then', + 'when', 'END', 'case', 'else', 'for', 'nil', 'retry', 'true', 'while', + 'alias', 'class', 'elsif', 'if', 'not', 'return', 'undef', 'yield' + ), 'c++': - ('asm', 'auto', 'bool', 'break', 'case', 'catch', 'char', 'class', - 'const', 'const_cast', 'continue', 'default', 'delete', 'do', 'double', - 'dynamic_cast', 'else', 'enum', 'explicit', 'export', 'extern', - 'false', 'float', 'for', 'friend', 'goto', 'if', 'inline', 'int', - 'long', 'mutable', 'namespace', 'new', 'operator', 'private', - 'protected', 'public', 'register', 'reinterpret_cast', 'return', - 'short', 'signed', 'sizeof', 'static', 'static_cast', 'struct', - 'switch', 'template', 'this', 'throw', 'true', 'try', 'typedef', - 'typeid', 'typename', 'union', 'unsigned', 'using', 'virtual', 'void', - 'volatile', 'wchar_t', 'while') + ( + 'asm', 'auto', 'bool', 'break', 'case', 'catch', 'char', 'class', + 'const', 'const_cast', 'continue', 'default', 'delete', 'do', 'double', + 'dynamic_cast', 'else', 'enum', 'explicit', 'export', 'extern', + 'false', 'float', 'for', 'friend', 'goto', 'if', 'inline', 'int', + 'long', 'mutable', 'namespace', 'new', 'operator', 'private', + 'protected', 'public', 'register', 'reinterpret_cast', 'return', + 'short', 'signed', 'sizeof', 'static', 'static_cast', 'struct', + 'switch', 'template', 'this', 'throw', 'true', 'try', 'typedef', + 'typeid', 'typename', 'union', 'unsigned', 'using', 'virtual', 'void', + 'volatile', 'wchar_t', 'while' + ) } block_comments = { - 'python': ("'''","'''"), + 'python': ("'''", "'''"), 'ruby': None, - 'c++': ('/*','*/') + 'c++': ('/*', '*/') } inline_comments = { 'python': '#', @@ -113,54 +121,60 @@ inline_comments = { 'c++': '//' } + def print_stderr(line): sys.stderr.write(line+os.linesep) + def sub_keyword(mo): '''re.subs() argument to tag keywords.''' word = mo.group('word') if word in keywords[language]: - stag,etag = keywordtags[backend] + stag, etag = keywordtags[backend] return stag+word+etag else: return word + def code_filter(): '''This function does all the work.''' global language, backend inline_comment = inline_comments[language] blk_comment = block_comments[language] if blk_comment: - blk_comment = (re.escape(block_comments[language][0]), - re.escape(block_comments[language][1])) - stag,etag = commenttags[backend] + blk_comment = ( + re.escape(block_comments[language][0]), + re.escape(block_comments[language][1]) + ) + stag, etag = commenttags[backend] in_comment = 0 # True if we're inside a multi-line block comment. - tag_comment = 0 # True if we should tag the current line as a comment. + tag_comment = 0 # True if we should tag the current line as a comment. line = sys.stdin.readline() while line: line = line.rstrip() line = line.expandtabs(tabsize) # Escape special characters. - line = line.replace('&','&') - line = line.replace('<','<') - line = line.replace('>','>') + line = line.replace('&', '&') + line = line.replace('<', '<') + line = line.replace('>', '>') # Process block comment. if blk_comment: if in_comment: - if re.match(r'.*'+blk_comment[1]+r'$',line): + if re.match(r'.*'+blk_comment[1]+r'$', line): in_comment = 0 else: - if re.match(r'^\s*'+blk_comment[0]+r'.*'+blk_comment[1],line): + if re.match(r'^\s*'+blk_comment[0]+r'.*'+blk_comment[1], line): # Single line block comment. tag_comment = 1 - elif re.match(r'^\s*'+blk_comment[0],line): + elif re.match(r'^\s*'+blk_comment[0], line): # Start of multi-line block comment. tag_comment = 1 in_comment = 1 else: tag_comment = 0 if tag_comment: - if line: line = stag+line+etag + if line: + line = stag+line+etag else: if inline_comment: pos = line.find(inline_comment) @@ -168,45 +182,51 @@ def code_filter(): pos = -1 if pos >= 0: # Process inline comment. - line = re.sub(r'\b(?P<word>\w+)\b',sub_keyword,line[:pos]) \ + line = re.sub(r'\b(?P<word>\w+)\b', sub_keyword, line[:pos]) \ + stag + line[pos:] + etag else: - line = re.sub(r'\b(?P<word>\w+)\b',sub_keyword,line) + line = re.sub(r'\b(?P<word>\w+)\b', sub_keyword, line) sys.stdout.write(line + os.linesep) line = sys.stdin.readline() + def usage(msg=''): if msg: print_stderr(msg) print_stderr('Usage: code-filter -b backend -l language [ -t tabsize ]') print_stderr(' [ --help | -h ] [ --version | -v ]') + def main(): global language, backend, tabsize # Process command line options. import getopt - opts,args = getopt.getopt(sys.argv[1:], + opts, args = getopt.getopt( + sys.argv[1:], 'b:l:ht:v', - ['help','version']) + ['help', 'version'] + ) if len(args) > 0: usage() sys.exit(1) - for o,v in opts: - if o in ('--help','-h'): + for o, v in opts: + if o in ('--help', '-h'): print(__doc__) sys.exit(0) - if o in ('--version','-v'): + if o in ('--version', '-v'): print('code-filter version %s' % (VERSION,)) sys.exit(0) - if o == '-b': backend = v + if o == '-b': + backend = v if o == '-l': v = v.lower() - if v == 'c': v = 'c++' + if v == 'c': + v = 'c++' language = v if o == '-t': try: tabsize = int(v) - except: + except BaseException: usage('illegal tabsize') sys.exit(1) if tabsize <= 0: @@ -227,13 +247,16 @@ def main(): # Do the work. code_filter() + if __name__ == "__main__": try: main() except (KeyboardInterrupt, SystemExit): pass - except: - print_stderr("%s: unexpected exit status: %s" % - (os.path.basename(sys.argv[0]), sys.exc_info()[1])) + except BaseException: + print_stderr( + "%s: unexpected exit status: %s" % + (os.path.basename(sys.argv[0]), sys.exc_info()[1]) + ) # Exit with previous sys.exit() status or zero if no sys.exit(). sys.exit(sys.exc_info()[1]) diff --git a/filters/graphviz/graphviz2png.py b/filters/graphviz/graphviz2png.py index 0035843..a13c67d 100755 --- a/filters/graphviz/graphviz2png.py +++ b/filters/graphviz/graphviz2png.py @@ -1,19 +1,6 @@ #!/usr/bin/env python3 -import os -import sys -import subprocess -import argparse - -__AUTHOR__ = "Gouichi Iisaka <iisaka51@gmail.com>" -__VERSION__ = '1.1.5' - -class EApp(Exception): - '''Application specific exception.''' - pass - -class Application(): - ''' +''' NAME graphviz2png - Converts textual graphviz notation to PNG file @@ -63,12 +50,32 @@ LICENSE Copyright (C) 2008-2009 Gouichi Iisaka. Free use of this software is granted under the terms of the GNU General Public License (GPL). - ''' +''' +import os +import sys +import subprocess +import argparse + +__AUTHOR__ = "Gouichi Iisaka <iisaka51@gmail.com>" +__VERSION__ = '1.1.5' + + +class EApp(Exception): + '''Application specific exception.''' + pass + + +class Application(): def __init__(self, argv=None): # Run dot, get the list of supported formats. It's prefixed by some junk. - format_output = subprocess.Popen(["dot", "-T?"], stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()[1].decode('utf-8') - # The junk contains : and ends with :. So we split it, then strip the final endline, then split the list for future usage. + format_output = subprocess.Popen( + ["dot", "-T?"], + stderr=subprocess.PIPE, + stdout=subprocess.PIPE + ).communicate()[1].decode('utf-8') + # The junk contains : and ends with :. So we split it, then strip the + # final endline, then split the list for future usage. supported_formats = format_output.split(": ")[2][:-1].split(" ") if not argv: @@ -79,13 +86,25 @@ LICENSE self.version += 'Copyright(c) 2008-2009: %s\n' % __AUTHOR__ self.parser = argparse.ArgumentParser(usage=self.usage) - self.parser.add_argument("-o", "--outfile", action="store", dest="outfile", help="Output file") - self.parser.add_argument("-L", "--layout", action="store", dest="layout", default="dot", - choices=['dot', 'neato', 'twopi', 'circo', 'fdp'], help="Layout type") - self.parser.add_argument("-F", "--format", action="store", dest="format", default="png", - choices=supported_formats, help="Format type") - self.parser.add_argument("--debug", action="store_true", dest="do_debug", help=argparse.SUPPRESS) - self.parser.add_argument("-v", "--verbose", action="store_true", dest="do_verbose", default=False, help="verbose output") + self.parser.add_argument( + "-o", "--outfile", action="store", dest="outfile", help="Output file" + ) + self.parser.add_argument( + "-L", "--layout", action="store", dest="layout", default="dot", + choices=['dot', 'neato', 'twopi', 'circo', 'fdp'], help="Layout type" + ) + self.parser.add_argument( + "-F", "--format", action="store", dest="format", default="png", + choices=supported_formats, help="Format type" + ) + self.parser.add_argument( + "--debug", action="store_true", dest="do_debug", help=argparse.SUPPRESS + ) + self.parser.add_argument( + "-v", "--verbose", + action="store_true", dest="do_verbose", default=False, + help="verbose output" + ) self.parser.add_argument("infile", action="store", help="Input file") self.parser.add_argument('--version', action='version', version=self.version) self.options = self.parser.parse_args() @@ -112,7 +131,12 @@ LICENSE saved_cwd = os.getcwd() os.chdir(outdir) try: - cmd = '%s -T%s "%s" > "%s"' % (self.options.layout, self.options.format, infile, outfile) + cmd = '%s -T%s "%s" > "%s"' % ( + self.options.layout, + self.options.format, + infile, + outfile + ) self.systemcmd(cmd) finally: os.chdir(saved_cwd) @@ -147,6 +171,7 @@ LICENSE if self.options.infile == '-': sys.stdout.write(' ') + if __name__ == "__main__": app = Application() app.run() diff --git a/filters/latex/latex2img.py b/filters/latex/latex2img.py index 8e03614..a446dd7 100755 --- a/filters/latex/latex2img.py +++ b/filters/latex/latex2img.py @@ -58,7 +58,9 @@ COPYING granted under the terms of the MIT License. ''' -import os, sys, tempfile +import os +import sys +import tempfile from hashlib import md5 VERSION = '0.2.0' @@ -80,27 +82,34 @@ TEX_FOOTER = r'''\end{document}''' # Globals. verbose = False -class EApp(Exception): pass # Application specific exception. + +class EApp(Exception): + pass # Application specific exception. + def print_stderr(line): sys.stderr.write(line + os.linesep) + def print_verbose(line): if verbose: print_stderr(line) + def write_file(filename, data, mode='w', encoding='utf-8'): if 'b' in mode: encoding = None with open(filename, mode, encoding=encoding) as f: f.write(data) + def read_file(filename, mode='r', encoding='utf-8'): if 'b' in mode: encoding = None with open(filename, mode, encoding=encoding) as f: return f.read() + def run(cmd): global verbose if verbose: @@ -111,6 +120,7 @@ def run(cmd): if os.system(cmd): raise EApp('failed command: %s' % cmd) + def latex2img(infile, outfile, imgfmt, dpi, modified): ''' Convert LaTeX input file infile to image file named outfile. @@ -122,7 +132,7 @@ def latex2img(infile, outfile, imgfmt, dpi, modified): texfile = tempfile.mktemp(suffix='.tex', dir=os.path.dirname(outfile)) basefile = os.path.splitext(texfile)[0] dvifile = basefile + '.dvi' - temps = [basefile + ext for ext in ('.tex','.dvi', '.aux', '.log')] + temps = [basefile + ext for ext in ('.tex', '.dvi', '.aux', '.log')] skip = False if infile == '-': tex = sys.stdin.read() @@ -130,7 +140,7 @@ def latex2img(infile, outfile, imgfmt, dpi, modified): checksum = md5((tex + imgfmt + str(dpi)).encode('utf-8')).digest() md5_file = os.path.splitext(outfile)[0] + '.md5' if os.path.isfile(md5_file) and os.path.isfile(outfile) and \ - checksum == read_file(md5_file,'rb'): + checksum == read_file(md5_file, 'rb'): skip = True else: if not os.path.isfile(infile): @@ -156,14 +166,14 @@ def latex2img(infile, outfile, imgfmt, dpi, modified): cmd += ' --no-fonts' cmd += ' --scale=1.4' cmd += ' --exact' - cmd += ' -o "%s" "%s"' % (outfile,dvifile) + cmd += ' -o "%s" "%s"' % (outfile, dvifile) else: # Convert DVI file to PNG. cmd = 'dvipng' if dpi: cmd += ' -D %s' % dpi cmd += ' -T tight -x 1000 -z 9 -bg Transparent --truecolor' - cmd += ' -o "%s" "%s" ' % (outfile,dvifile) + cmd += ' -o "%s" "%s" ' % (outfile, dvifile) run(cmd) finally: os.chdir(saved_pwd) @@ -175,21 +185,25 @@ def latex2img(infile, outfile, imgfmt, dpi, modified): print_verbose('writing: %s' % md5_file) write_file(md5_file, checksum, 'wb') + def usage(msg=''): if msg: print_stderr(msg) - print_stderr('\n' - 'usage:\n' - ' latex2img [options] INFILE\n' - '\n' - 'options:\n' - ' -D DPI\n' - ' -o OUTFILE\n' - ' -f FORMAT\n' - ' -m\n' - ' -v\n' - ' --help\n' - ' --version') + print_stderr( + '\n' + 'usage:\n' + ' latex2img [options] INFILE\n' + '\n' + 'options:\n' + ' -D DPI\n' + ' -o OUTFILE\n' + ' -f FORMAT\n' + ' -m\n' + ' -v\n' + ' --help\n' + ' --version' + ) + def main(): # Process command line options. @@ -199,19 +213,24 @@ def main(): imgfmt = 'png' modified = False import getopt - opts,args = getopt.getopt(sys.argv[1:], 'D:o:mhvf:', ['help','version']) - for o,v in opts: - if o in ('--help','-h'): + opts, args = getopt.getopt(sys.argv[1:], 'D:o:mhvf:', ['help', 'version']) + for o, v in opts: + if o in ('--help', '-h'): print(__doc__) sys.exit(0) - if o =='--version': + if o == '--version': print(('latex2img version %s' % (VERSION,))) sys.exit(0) - if o == '-D': dpi = v - if o == '-o': outfile = v - if o == '-m': modified = True - if o == '-v': verbose = True - if o == '-f': imgfmt = v + if o == '-D': + dpi = v + if o == '-o': + outfile = v + if o == '-m': + modified = True + if o == '-v': + verbose = True + if o == '-f': + imgfmt = v if len(args) != 1: usage() sys.exit(1) @@ -219,7 +238,7 @@ def main(): if dpi and not dpi.isdigit(): usage('invalid DPI') sys.exit(1) - if not imgfmt in {'png', 'svg'}: + if imgfmt not in {'png', 'svg'}: usage('Invalid image format. Valid values are "png" or "svg".') sys.exit(1) if outfile is None: @@ -233,6 +252,7 @@ def main(): if infile == '-': sys.stdout.write(' ') + if __name__ == "__main__": try: main() diff --git a/filters/music/music2png.py b/filters/music/music2png.py index 185137c..4458108 100755 --- a/filters/music/music2png.py +++ b/filters/music/music2png.py @@ -50,7 +50,9 @@ COPYING granted under the terms of the GNU General Public License (GPL). ''' -import os, sys, tempfile +import os +import sys +import tempfile from hashlib import md5 VERSION = '0.1.2' @@ -58,27 +60,34 @@ VERSION = '0.1.2' # Globals. verbose = False -class EApp(Exception): pass # Application specific exception. + +class EApp(Exception): + pass # Application specific exception. + def print_stderr(line): sys.stderr.write(line + os.linesep) + def print_verbose(line): if verbose: print_stderr(line) + def write_file(filename, data, mode='w', encoding='utf-8'): if 'b' in mode: encoding = None with open(filename, mode, encoding=encoding) as f: f.write(data) + def read_file(filename, mode='r', encoding='utf-8'): if 'b' in mode: encoding = None with open(filename, mode, encoding=encoding) as f: return f.read() + def run(cmd): global verbose if not verbose: @@ -87,6 +96,7 @@ def run(cmd): if os.system(cmd): raise EApp('failed command: %s' % cmd) + def music2png(format, infile, outfile, modified): '''Convert ABC notation in file infile to cropped PNG file named outfile.''' outfile = os.path.abspath(outfile) @@ -102,7 +112,7 @@ def music2png(format, infile, outfile, modified): filename = os.path.splitext(outfile)[0] + '.md5' if modified: if os.path.isfile(filename) and os.path.isfile(outfile) and \ - checksum == read_file(filename,'rb'): + checksum == read_file(filename, 'rb'): skip = True else: write_file(filename, checksum, 'wb') @@ -122,7 +132,7 @@ def music2png(format, infile, outfile, modified): else: format = 'abc' # Write temporary source file. - write_file('%s.%s' % (basefile,format), source) + write_file('%s.%s' % (basefile, format), source) abc = basefile + '.abc' ly = basefile + '.ly' png = basefile + '.png' @@ -130,8 +140,8 @@ def music2png(format, infile, outfile, modified): os.chdir(outdir) try: if format == 'abc': - run('abc2ly -o "%s" "%s"' % (ly,abc)) - run('lilypond --png -o "%s" "%s"' % (basefile,ly)) + run('abc2ly -o "%s" "%s"' % (ly, abc)) + run('lilypond --png -o "%s" "%s"' % (basefile, ly)) os.rename(png, outfile) finally: os.chdir(saved_pwd) @@ -144,20 +154,24 @@ def music2png(format, infile, outfile, modified): print_verbose('deleting: %s' % f) os.remove(f) + def usage(msg=''): if msg: print_stderr(msg) - print_stderr('\n' - 'usage:\n' - ' music2png [options] INFILE\n' - '\n' - 'options:\n' - ' -f FORMAT\n' - ' -o OUTFILE\n' - ' -m\n' - ' -v\n' - ' --help\n' - ' --version') + print_stderr( + '\n' + 'usage:\n' + ' music2png [options] INFILE\n' + '\n' + 'options:\n' + ' -f FORMAT\n' + ' -o OUTFILE\n' + ' -m\n' + ' -v\n' + ' --help\n' + ' --version' + ) + def main(): # Process command line options. @@ -166,18 +180,22 @@ def main(): outfile = None modified = False import getopt - opts,args = getopt.getopt(sys.argv[1:], 'f:o:mhv', ['help','version']) - for o,v in opts: - if o in ('--help','-h'): + opts, args = getopt.getopt(sys.argv[1:], 'f:o:mhv', ['help', 'version']) + for o, v in opts: + if o in ('--help', '-h'): print(__doc__) sys.exit(0) - if o =='--version': + if o == '--version': print(('music2png version %s' % (VERSION,))) sys.exit(0) - if o == '-f': format = v - if o == '-o': outfile = v - if o == '-m': modified = True - if o == '-v': verbose = True + if o == '-f': + format = v + if o == '-o': + outfile = v + if o == '-m': + modified = True + if o == '-v': + verbose = True if len(args) != 1: usage() sys.exit(1) @@ -196,6 +214,7 @@ def main(): if infile == '-': sys.stdout.write(' ') + if __name__ == "__main__": try: main() diff --git a/filters/unwraplatex.py b/filters/unwraplatex.py index 57c84cf..05a7581 100755 --- a/filters/unwraplatex.py +++ b/filters/unwraplatex.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -''' +""" NAME unwraplatex - Removes delimiters from LaTeX source text @@ -8,15 +8,15 @@ SYNOPSIS DESCRIPTION This filter reads LaTeX source text from STDIN and removes the - surrounding \[ and \] delimiters. -''' + surrounding \\[ and \\] delimiters. +""" import re import sys sys.stdout.write( re.sub( - "(?s)\A(?:\\\\\[\s*)?(.*?)(?:\\\\\])?\Z", "\\1", + r"(?s)\A(?:\\\[\s*)?(.*?)(?:\\\])?\Z", "\\1", sys.stdin.read().rstrip() ) ) diff --git a/tests/data/barchart.py b/tests/data/barchart.py index e2edf74..3472cde 100644 --- a/tests/data/barchart.py +++ b/tests/data/barchart.py @@ -1,2 +1,4 @@ -print("No barchart to avoid depending on Pychart for the tests.\n" - "See also: http://asciidoc.org/faq.html#_is_it_possible_to_include_charts_in_asciidoc_documents") +print( + "No barchart to avoid depending on Pychart for the tests.\n" + "See also: http://asciidoc.org/faq.html#_is_it_possible_to_include_charts_in_asciidoc_documents" # noqa: E501 +) diff --git a/tests/testasciidoc.py b/tests/testasciidoc.py index 6c3ffa5..85f34a4 100755 --- a/tests/testasciidoc.py +++ b/tests/testasciidoc.py @@ -300,7 +300,7 @@ class AsciiDocTests(object): first = True while not lines.eol(): s = lines.read_until(r'^%+$') - s = [l for l in s if l] # Drop blank lines. + s = [line for line in s if len(line) > 0] # Drop blank lines. # Must be at least one non-blank line in addition to delimiter. if len(s) > 1: # Optional globals precede all tests. |