From b214ff1f8ba68bbd5a5bfed7e56ca2e06fccfddd Mon Sep 17 00:00:00 2001 From: dessant Date: Thu, 23 Mar 2017 19:56:02 +0200 Subject: [PATCH] pep8 fixes --- jnius/__init__.py | 6 ++- jnius/reflect.py | 12 ++++-- jnius/signatures.py | 12 ++++-- jnius_config.py | 6 +++ setup.py | 94 ++++++++++++++++++++++++++------------------- 5 files changed, 82 insertions(+), 48 deletions(-) diff --git a/jnius/__init__.py b/jnius/__init__.py index 4f2b5f8..819a7ff 100644 --- a/jnius/__init__.py +++ b/jnius/__init__.py @@ -9,14 +9,15 @@ All the documentation is available at: http://pyjnius.readthedocs.org __version__ = '1.1-dev' -from .jnius import * -from .reflect import * +from .jnius import * # noqa +from .reflect import * # noqa # XXX monkey patch methods that cannot be in cython. # Cython doesn't allow to set new attribute on methods it compiled HASHCODE_MAX = 2 ** 31 - 1 + class PythonJavaClass_(PythonJavaClass): @java_method('()I', name='hashCode') @@ -35,6 +36,7 @@ class PythonJavaClass_(PythonJavaClass): def equals(self, other): return self.hashCode() == other.hashCode() + PythonJavaClass = PythonJavaClass_ diff --git a/jnius/reflect.py b/jnius/reflect.py index 202ad69..a85b832 100644 --- a/jnius/reflect.py +++ b/jnius/reflect.py @@ -118,9 +118,10 @@ def get_signature(cls_tp): if ret: return ret # don't do it in recursive way for the moment, - # error on the JNI/android: JNI ERROR (app bug): local reference table overflow (max=512) - # - #ensureclass(tp) + # error on the JNI/android: JNI ERROR (app bug): local reference table + # overflow (max=512) + + # ensureclass(tp) return 'L{0};'.format(tp.replace('.', '/')) @@ -136,12 +137,15 @@ def ensureclass(clsname): registers.append(clsname) autoclass(clsname) + def lower_name(s): return s[:1].lower() + s[1:] if s else '' + def bean_getter(s): return (s.startswith('get') and len(s) > 3 and s[3].isupper()) or (s.startswith('is') and len(s) > 2 and s[2].isupper()) + def autoclass(clsname): jniname = clsname.replace('.', '/') cls = MetaJavaClass.get_javaclass(jniname) @@ -150,7 +154,7 @@ def autoclass(clsname): classDict = {} - #c = Class.forName(clsname) + # c = Class.forName(clsname) c = find_javaclass(clsname) if c is None: raise Exception('Java class {0} not found'.format(c)) diff --git a/jnius/signatures.py b/jnius/signatures.py index 9bc1830..bbcf35b 100644 --- a/jnius/signatures.py +++ b/jnius/signatures.py @@ -40,9 +40,11 @@ from . import java_method ''' Type specifiers for primitives ''' + class _JavaSignaturePrimitive(object): _spec = "" + def _MakeSignaturePrimitive(name, spec): class __Primitive(_JavaSignaturePrimitive): ''' PyJnius signature for Java %s type ''' % name @@ -52,6 +54,7 @@ def _MakeSignaturePrimitive(name, spec): return __Primitive + jboolean = _MakeSignaturePrimitive("boolean", "Z") jbyte = _MakeSignaturePrimitive("byte", "B") jchar = _MakeSignaturePrimitive("char", "C") @@ -62,6 +65,7 @@ jlong = _MakeSignaturePrimitive("long", "J") jshort = _MakeSignaturePrimitive("short", "S") jvoid = _MakeSignaturePrimitive("void", "V") + def JArray(of_type): ''' Signature helper for identifying arrays of a given object or primitive type. ''' @@ -69,6 +73,7 @@ def JArray(of_type): spec = "[" + _jni_type_spec(of_type) return _MakeSignaturePrimitive("array", spec) + def with_signature(returns, takes): ''' Alternative version of @java_method that takes JavaClass objects to produce the method signature. ''' @@ -76,8 +81,9 @@ def with_signature(returns, takes): sig = signature(returns, takes) return java_method(sig) + def signature(returns, takes): - ''' Produces a JNI method signature, taking the provided arguments + ''' Produces a JNI method signature, taking the provided arguments and returning the given return type. ''' out_takes = [] @@ -86,9 +92,10 @@ def signature(returns, takes): return "(" + "".join(out_takes) + ")" + _jni_type_spec(returns) + def _jni_type_spec(jclass): ''' Produces a JNI type specification string for the given argument. - If the argument is a jnius.JavaClass, it produces the JNI type spec + If the argument is a jnius.JavaClass, it produces the JNI type spec for the class. Signature primitives return their stored type spec. ''' @@ -96,4 +103,3 @@ def _jni_type_spec(jclass): return "L" + jclass.__javaclass__ + ";" elif issubclass(jclass, _JavaSignaturePrimitive): return jclass._spec - \ No newline at end of file diff --git a/jnius_config.py b/jnius_config.py index bb5ba95..cb90394 100644 --- a/jnius_config.py +++ b/jnius_config.py @@ -12,12 +12,14 @@ vm_running = False options = [] classpath = None + def set_options(*opts): "Sets the list of options to the JVM. Removes any previously set options." if vm_running: raise ValueError("VM is already running, can't set options") globals()['options'] = opts + def add_options(*opts): "Appends options to the list of VM options." if vm_running: @@ -25,6 +27,7 @@ def add_options(*opts): global options options.extend(opts) + def get_options(): "Retrieves the current list of VM options." global options @@ -40,6 +43,7 @@ def set_classpath(*path): global classpath classpath = path + def add_classpath(*path): """ Appends items to the classpath for the JVM to use. @@ -53,6 +57,7 @@ def add_classpath(*path): else: classpath.extend(path) + def get_classpath(): "Retrieves the classpath the JVM will use." from os import environ @@ -67,6 +72,7 @@ def get_classpath(): return [realpath('.')] + def expand_classpath(): from glob import glob paths = [] diff --git a/setup.py b/setup.py index 1f8d2e3..a2490ac 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,8 @@ from os.path import dirname, join, exists import sys from platform import machine -PY3 = sys.version_info >= (3,0,0) +PY3 = sys.version_info >= (3, 0, 0) + def getenv(key): val = environ.get(key) @@ -20,6 +21,7 @@ def getenv(key): return val return val + files = [ 'jni.pxi', 'jnius_conversion.pxi', @@ -68,8 +70,9 @@ if platform == 'android': library_dirs = ['libs/' + getenv('ARCH')] elif platform == 'darwin': import subprocess - framework = subprocess.Popen('/usr/libexec/java_home', - shell=True, stdout=subprocess.PIPE).communicate()[0] + framework = subprocess.Popen( + '/usr/libexec/java_home', + stdout=subprocess.PIPE, shell=True).communicate()[0] if PY3: framework = framework.decode() framework = framework.strip() @@ -81,7 +84,10 @@ elif platform == 'darwin': include_dirs = [join(framework, 'System/Library/Frameworks/JavaVM.framework/Versions/Current/Headers')] else: lib_location = 'jre/lib/server/libjvm.dylib' - include_dirs = ['{0}/include'.format(framework), '{0}/include/darwin'.format(framework)] + include_dirs = [ + '{0}/include'.format(framework), + '{0}/include/darwin'.format(framework) + ] else: import subprocess # otherwise, we need to search the JDK_HOME @@ -96,8 +102,9 @@ else: if jdk_home[-3:] == 'bin': jdk_home = jdk_home[:-4] else: - jdk_home = subprocess.Popen('readlink -f `which javac` | sed "s:bin/javac::"', - shell=True, stdout=subprocess.PIPE).communicate()[0].strip() + jdk_home = subprocess.Popen( + 'readlink -f `which javac` | sed "s:bin/javac::"', + shell=True, stdout=subprocess.PIPE).communicate()[0].strip() if jdk_home is not None and PY3: jdk_home = jdk_home.decode() if not jdk_home or not exists(jdk_home): @@ -107,17 +114,20 @@ else: if exists(join(jdk_home, 'jre')): jre_home = join(jdk_home, 'jre') if not jre_home: - jre_home = subprocess.Popen('readlink -f `which java` | sed "s:bin/java::"', - shell=True, stdout=subprocess.PIPE).communicate()[0].strip() + jre_home = subprocess.Popen( + 'readlink -f `which java` | sed "s:bin/java::"', + shell=True, stdout=subprocess.PIPE).communicate()[0].strip() if not jre_home: raise Exception('Unable to determine JRE_HOME') # This dictionary converts values from platform.machine() to a "cpu" string. - # It is needed to set the correct lib path, found in the jre_home, eg. /lib//. - machine2cpu = {"i686" : "i386", - "x86_64" : "amd64", - "armv7l" : "arm", - } + # It is needed to set the correct lib path, found in the jre_home, eg. + # /lib//. + machine2cpu = { + "i686" : "i386", + "x86_64" : "amd64", + "armv7l" : "arm" + } if machine() in machine2cpu.keys(): cpu = machine2cpu[machine()] else: @@ -133,13 +143,15 @@ else: lib_location = 'jre/lib/{}/server/libjvm.so'.format(cpu) include_dirs = [ - join(jdk_home, 'include'), - incl_dir] + join(jdk_home, 'include'), + incl_dir + ] if platform == 'win32': library_dirs = [ - join(jdk_home, 'lib'), - join(jre_home, 'bin', 'server')] + join(jdk_home, 'lib'), + join(jre_home, 'bin', 'server') + ] # generate the config.pxi with open(join(dirname(__file__), 'jnius', 'config.pxi'), 'w') as fd: @@ -156,27 +168,29 @@ with open(join('jnius', '__init__.py')) as fd: version = versionline[0].split("'")[-2] # create the extension -setup(name='jnius', - version=version, - cmdclass={'build_ext': build_ext}, - packages=['jnius'], - py_modules=['jnius_config'], - url='https://pyjnius.readthedocs.io', - author='Kivy Team and other contributors', - author_email='kivy-dev@googlegroups.com', - license='MIT', - description='Python library to access Java classes', - install_requires=install_requires, - ext_package='jnius', - ext_modules=[ - Extension( - 'jnius', [join('jnius', x) for x in files], - libraries=libraries, - library_dirs=library_dirs, - include_dirs=include_dirs, - extra_link_args=extra_link_args) - ], - classifiers=[ +setup( + name='jnius', + version=version, + cmdclass={'build_ext': build_ext}, + packages=['jnius'], + py_modules=['jnius_config'], + url='https://pyjnius.readthedocs.io', + author='Kivy Team and other contributors', + author_email='kivy-dev@googlegroups.com', + license='MIT', + description='Python library to access Java classes', + install_requires=install_requires, + ext_package='jnius', + ext_modules=[ + Extension( + 'jnius', [join('jnius', x) for x in files], + libraries=libraries, + library_dirs=library_dirs, + include_dirs=include_dirs, + extra_link_args=extra_link_args + ) + ], + classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', @@ -189,4 +203,6 @@ setup(name='jnius', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', - 'Topic :: Software Development :: Libraries :: Application Frameworks']) + 'Topic :: Software Development :: Libraries :: Application Frameworks' + ] +)