From 8db917503b59e5464a02338f55180f0fd965a4c8 Mon Sep 17 00:00:00 2001 From: Olivier Jolly Date: Fri, 5 Feb 2016 00:49:16 +0100 Subject: [PATCH] Improve pep8 compliance --- pylintrc | 4 ++-- rnsutils/instrument.py | 2 +- rnsutils/lookup.py | 4 ++++ rnsutils/utils.py | 11 +++++++++++ rnsutils/xrnireencode.py | 6 +++--- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/pylintrc b/pylintrc index df38b63..4a01be3 100644 --- a/pylintrc +++ b/pylintrc @@ -127,7 +127,7 @@ expected-line-ending-format= bad-functions=map,filter,input # Good variable names which should always be accepted, separated by a comma -good-names=i,j,k,ex,Run,_ +good-names=i,j,k,ex,e,Run,_ # Bad variable names which should always be refused, separated by a comma bad-names=foo,bar,baz,toto,tutu,tata @@ -326,7 +326,7 @@ max-args=5 ignored-argument-names=_.* # Maximum number of locals for function / method body -max-locals=15 +max-locals=18 # Maximum number of return / yield for function / method body max-returns=6 diff --git a/rnsutils/instrument.py b/rnsutils/instrument.py index 98ca58b..820145f 100644 --- a/rnsutils/instrument.py +++ b/rnsutils/instrument.py @@ -275,6 +275,6 @@ if __name__ == "__main__": instrument = RenoiseInstrument('basic.xrni') pprint.pprint(instrument) pprint.pprint(instrument.samples) - #  s = instrument.samples[0] + # s = instrument.samples[0] # print(s.foo()) instrument.save('generated.xrni') diff --git a/rnsutils/lookup.py b/rnsutils/lookup.py index 9c523ed..b9718e3 100644 --- a/rnsutils/lookup.py +++ b/rnsutils/lookup.py @@ -1,3 +1,4 @@ +"""lookup for mapping xml elements into custom python wrappers""" from lxml import etree from lxml.objectify import ObjectifyElementClassLookup @@ -5,10 +6,13 @@ from .instrument import RenoiseSample, RenoiseModulationSet class RenoiseClassLookup(etree.CustomElementClassLookup): + """mapping class for xml element to python class""" + def __init__(self): super(RenoiseClassLookup, self).__init__(fallback=ObjectifyElementClassLookup()) def lookup(self, node_type, document, namespace, name): + """mapping method for xml element to python class""" if name == 'Sample': return RenoiseSample elif name == 'ModulationSet': diff --git a/rnsutils/utils.py b/rnsutils/utils.py index b7c85f2..cfcbefb 100644 --- a/rnsutils/utils.py +++ b/rnsutils/utils.py @@ -1,3 +1,5 @@ +"""project wide utilities, notably audio format guessing and encoding""" + import logging import subprocess @@ -6,6 +8,9 @@ import tempfile def guesstimate_audio_extension(data): + """:arg data audio file content + :return file format extension guessed from file content""" + if len(data) > 8 and data[0:8] == b'fLaC\0\0\0\x22': return "flac" if len(data) > 3 and data[0:3] == b'Ogg': @@ -19,7 +24,10 @@ ENCODING_OGG = "ogg" def _call_encoder(func): + """decorator for creating a temporary file, calling an encoder and cleaning temporary files""" + def inner(sample_content): + """actual wrapping function to create and clean temporary files around audio encoding""" out_format = guesstimate_audio_extension(sample_content) in_filename = tempfile.NamedTemporaryFile(suffix='.wav', delete=False).name out_filename = tempfile.NamedTemporaryFile(suffix='.{}'.format(out_format), delete=False).name @@ -42,17 +50,20 @@ def _call_encoder(func): @_call_encoder def _encode_flac(in_filename, out_filename): + """encode :arg in_filename into :arg out_filename using flac""" return subprocess.Popen(["flac", in_filename, "-f", "-o", out_filename], stderr=subprocess.STDOUT, stdout=subprocess.PIPE) @_call_encoder def _encode_ogg(in_filename, out_filename): + """encode :arg in_filename into :arg out_filename using ogg vorbis""" return subprocess.Popen(["oggenc", in_filename, "-o", out_filename], stderr=subprocess.STDOUT, stdout=subprocess.PIPE) def encode_audio_file(sample_content, encoding): + """encode :arg sample_content as audio file content into :arg encoding format""" if encoding == ENCODING_FLAC: return _encode_flac(sample_content) elif encoding == ENCODING_OGG: diff --git a/rnsutils/xrnireencode.py b/rnsutils/xrnireencode.py index 4e13083..1f9eb49 100644 --- a/rnsutils/xrnireencode.py +++ b/rnsutils/xrnireencode.py @@ -64,7 +64,7 @@ def main(argv=None): # process options opts = parser.parse_args(argv) - except Exception as e: + except Exception as e: # pylint: disable=broad-except indent = len(program_name) * " " sys.stderr.write(program_name + ": " + repr(e) + "\n") sys.stderr.write(indent + " for help use --help") @@ -89,14 +89,14 @@ def main(argv=None): renoise_instrument.sample_data] # save the output file - filename_without_extension, extension = os.path.splitext(os.path.basename(xrni_filename)) + filename_without_extension, _ = os.path.splitext(os.path.basename(xrni_filename)) output_filename = os.path.join(opts.output_dir or os.path.dirname(xrni_filename), '{}.{}.xrni'.format(filename_without_extension, opts.encoding)) renoise_instrument.save(output_filename) if not opts.quiet: print("Saved {}".format(output_filename)) - except Exception: + except Exception: # pylint: disable=broad-except if not opts.quiet: print("FAILED") logging.exception("Failed to reencode instrument")