Skip to content
Permalink
Browse files

Apply autopep8

  • Loading branch information
Thrameos committed Mar 10, 2020
1 parent f8c888f commit bdc654ec137062e36d3205ec74162682436378f6
@@ -29,9 +29,12 @@
'JVMNotFoundException', 'JVMNotSupportedException'
]


def versionTest():
if sys.version_info < (3,):
raise ImportError("Python 2 is not supported")


versionTest()


@@ -213,15 +216,17 @@ def startJVM(*args, **kwargs):
% (','.join([str(i) for i in kwargs])))

try:
_jpype.startup(jvmpath, tuple(args), ignoreUnrecognized, convertStrings)
_jpype.startup(jvmpath, tuple(args),
ignoreUnrecognized, convertStrings)
except RuntimeError as ex:
source = str(ex)
if "UnsupportedClassVersion" in source:
import re
match = re.search("([0-9]+)\.[0-9]+", source)
if match:
version = int(match.group(1))-44
raise RuntimeError("%s is older than required Java version %d"%(jvmpath, version)) from ex
raise RuntimeError("%s is older than required Java version %d" % (
jvmpath, version)) from ex
raise

_jpype._java_lang_Class = None
@@ -374,7 +379,6 @@ def synchronized(obj):
raise TypeError("synchronized only applies to java objects")



# Naming compatibility
@deprecated("getDefaultJVMPath")
def get_default_jvm_path(*args, **kwargs):
@@ -14,6 +14,7 @@
# limitations under the License.
#
# *****************************************************************************
import datetime
from collections.abc import Sequence
from collections.abc import Mapping

@@ -49,7 +50,8 @@ def __len__(self):
return self.size()

def __delitem__(self, i):
raise TypeError("'%s' does not support item deletion, use remove() method"%type(self).__name__)
raise TypeError(
"'%s' does not support item deletion, use remove() method" % type(self).__name__)


def _sliceAdjust(slc, size):
@@ -136,7 +138,7 @@ def __getitem__(self, ndx):
item = self.get(ndx)
if item is None:
if not self.containsKey(ndx):
raise KeyError('%s'%ndx)
raise KeyError('%s' % ndx)
return item

def __setitem__(self, ndx, v):
@@ -162,13 +164,15 @@ def __delitem__(self, i):
class _JMapEntry(object):
def __len__(self):
return 2
def __getitem__(self,x):
if x==0:

def __getitem__(self, x):
if x == 0:
return self.getKey()
if x==1:
if x == 1:
return self.getValue()
raise IndexError("Pairs are always length 2")


@_jcustomizer.JImplementationFor('java.util.Iterator')
class _JIterator(object):
""" Customizer for ``java.util.Iterator``
@@ -211,34 +215,35 @@ def __iter__(self):

next = __next__


# These methods need a home.
import datetime
@_jcustomizer.JConversion("java.time.Instant", exact=datetime.datetime)
def _JInstantConversion(jcls, obj):
utc = obj.replace(tzinfo=datetime.timezone.utc).timestamp()
sec = int(utc)
nsec = int((utc-sec)*1e9)
return jcls.ofEpochSecond(sec, nsec)


@_jcustomizer.JConversion("java.nio.file.Path", attribute="__fspath__")
def _JPathConvert(jcls, obj):
Paths = _jpype.JClass("java.nio.file.Paths")
return Paths.get(obj.__fspath__())


@_jcustomizer.JConversion("java.io.File", attribute="__fspath__")
def _JFileConvert(jcls, obj):
return jcls(obj.__fspath__())


@_jcustomizer.JConversion("java.util.Collection", instanceof=Sequence)
def _JSequenceConvert(jcls, obj):
return _jclass.JClass('java.util.Arrays').asList(obj)


@_jcustomizer.JConversion("java.util.Map", instanceof=Mapping)
def _JMapConvert(jcls, obj):
hm = _jclass.JClass('java.util.HashMap')()
for p,v in obj.items():
for p, v in obj.items():
hm[p] = v
return hm



@@ -17,6 +17,7 @@

__all__ = ['JImplementationFor', 'JConversion']


def JConversion(cls, exact=None, instanceof=None, attribute=None):
""" Decorator to define a method as a converted a Java type.
@@ -259,5 +260,7 @@ def getClassHints(name):
_jpype._hints[name] = hints
return hints


_jpype._hints = {}
getClassHints("java.lang.IndexOutOfBoundsException").registerClassBase(IndexError)
getClassHints("java.lang.IndexOutOfBoundsException").registerClassBase(
IndexError)
@@ -79,7 +79,6 @@ def __ne__(self, other):
return True



def _getDefaultJavaObject(obj):
""" Determine the type of the object based the type of a value.
@@ -324,10 +324,10 @@ def _javahome_binary(self):
current = StrictVersion(platform.mac_ver()[0][:4])
if current >= StrictVersion('10.6') and current < StrictVersion('10.9'):
return subprocess.check_output(
['/usr/libexec/java_home']).strip()
['/usr/libexec/java_home']).strip()


def _checkJVMArch(jvmPath, maxsize = sys.maxsize):
def _checkJVMArch(jvmPath, maxsize=sys.maxsize):
import struct
IMAGE_FILE_MACHINE_I386 = 332
IMAGE_FILE_MACHINE_IA64 = 512
@@ -16,6 +16,7 @@
# *****************************************************************************
from ._core import deprecated


@deprecated("class_.getConstructors()")
def getConstructors(clas):
return clas.class_.getConstructors()[:]
@@ -49,5 +49,5 @@
zip_safe=False,
ext_modules=[jpypeLib],
distclass=setupext.dist.Distribution,
use_scm_version = True,
use_scm_version=True,
)
@@ -17,7 +17,7 @@ class BuildExtCommand(build_ext):

# extra compile args
copt = {'msvc': [],
'unix': ['-ggdb',],
'unix': ['-ggdb', ],
'mingw32': [],
}
# extra link args
@@ -42,7 +42,7 @@ def initialize_options(self, *args):
for k, v in cfg_vars.items():
if not isinstance(v, str):
continue
if not k=="OPT" and not "FLAGS" in k:
if not k == "OPT" and not "FLAGS" in k:
continue
for r, t in replacement.items():
if v.find(r) != -1:
@@ -54,8 +54,9 @@ def _set_cflags(self):
# set compiler flags
c = self.compiler.compiler_type
if c == 'unix' and self.distribution.enable_coverage:
self.extensions[0].extra_compile_args.extend(['-O0', '--coverage', '-ftest-coverage'])
self.extensions[0].extra_link_args.extend(['--coverage'])
self.extensions[0].extra_compile_args.extend(
['-O0', '--coverage', '-ftest-coverage'])
self.extensions[0].extra_link_args.extend(['--coverage'])
if c in self.copt:
for e in self.extensions:
e.extra_compile_args.extend(self.copt[c])
@@ -27,14 +27,15 @@ def run(self):

# Try to use the cach if we are not requested build
if not java:
src = os.path.join('native','jars')
dest = os.path.join('build','lib')
src = os.path.join('native', 'jars')
dest = os.path.join('build', 'lib')
if os.path.exists(src):
distutils.log.info("Using Jar cache")
copy_tree(src, dest)
return

distutils.log.info("Jar cache is missing, using --enable-build-jar to recreate it.")
distutils.log.info(
"Jar cache is missing, using --enable-build-jar to recreate it.")

# build the jar
buildDir = os.path.join("..", "build")
@@ -52,6 +53,5 @@ def run(self):
# Coverage tool requires special placement of the source
if self.distribution.enable_coverage:
import shutil
shutil.copyfile(os.path.join("build","lib","org.jpype.jar"), os.path.join("native", "org.jpype.jar"))


shutil.copyfile(os.path.join("build", "lib", "org.jpype.jar"), os.path.join(
"native", "org.jpype.jar"))
@@ -3,7 +3,7 @@
import os
from setuptools.command.build_ext import build_ext

# This setup target constructs a prototype Makefile suitable for compiling
# This setup target constructs a prototype Makefile suitable for compiling
# the _jpype extension module. It is intended to help with development
# of the extension library on unix systems.
#
@@ -12,9 +12,11 @@
#
# Then edit with the desired options


class FeatureNotice(Warning):
""" indicate notices about features """


class Makefile(object):
def __init__(self, actual):
self.actual = actual
@@ -27,13 +29,15 @@ def __init__(self, actual):
def captureCompile(self, x):
command = x[0]
x = x[1:]
includes = [ i for i in x if i.startswith("-I")]
x = [ i for i in x if not i.startswith("-I")]
includes = [i for i in x if i.startswith("-I")]
x = [i for i in x if not i.startswith("-I")]
i0 = None
i1 = None
for i,v in enumerate(x):
if v == '-c': i1=i
elif v == '-o': i0=i
for i, v in enumerate(x):
if v == '-c':
i1 = i
elif v == '-o':
i0 = i
pre = set(x[:i1])
post = x[i0+2:]

@@ -49,8 +53,8 @@ def captureLink(self, x):
self.library = x[-1]
print(x[-3:])
x = x[:-3]
self.objects = [ i for i in x if i.endswith(".o")]
self.link_options = [ i for i in x if not i.endswith(".o")]
self.objects = [i for i in x if i.endswith(".o")]
self.link_options = [i for i in x if not i.endswith(".o")]
u = self.objects[0].split("/")
self.build_dir = "/".join(u[:2])

@@ -76,14 +80,14 @@ def write(self):
includes = " ".join(self.includes)
sources = " \\\n ".join(self.sources)
with open("Makefile", "w") as fd:
print("LIB = %s"%library, file=fd)
print("CC = %s"%compile_command, file=fd)
print("LINK = %s"%link_command, file=fd)
print("CFLAGS = %s %s"%(compile_pre,compile_post), file=fd)
print("INCLUDES = %s"%includes, file=fd)
print("BUILD = %s"%build, file=fd)
print("LINKFLAGS = %s"%link_flags, file=fd)
print("SRCS = %s"%sources, file=fd)
print("LIB = %s" % library, file=fd)
print("CC = %s" % compile_command, file=fd)
print("LINK = %s" % link_command, file=fd)
print("CFLAGS = %s %s" % (compile_pre, compile_post), file=fd)
print("INCLUDES = %s" % includes, file=fd)
print("BUILD = %s" % build, file=fd)
print("LINKFLAGS = %s" % link_flags, file=fd)
print("SRCS = %s" % sources, file=fd)
print("""
all: $(LIB)
@@ -128,7 +132,7 @@ class BuildMakefileCommand(build_ext):

# extra compile args
copt = {'msvc': [],
'unix': ['-ggdb',],
'unix': ['-ggdb', ],
'mingw32': [],
}
# extra link args
@@ -151,7 +155,7 @@ def initialize_options(self, *args):
for k, v in cfg_vars.items():
if not isinstance(v, str):
continue
if not k=="OPT" and not "FLAGS" in k:
if not k == "OPT" and not "FLAGS" in k:
continue
for r, t in replacement.items():
if v.find(r) != -1:
@@ -163,16 +167,16 @@ def _set_cflags(self):
# set compiler flags
c = self.compiler.compiler_type
if c == 'unix' and self.distribution.enable_coverage:
self.extensions[0].extra_compile_args.extend(['-O0', '--coverage', '-ftest-coverage'])
self.extensions[0].extra_link_args.extend(['--coverage'])
self.extensions[0].extra_compile_args.extend(
['-O0', '--coverage', '-ftest-coverage'])
self.extensions[0].extra_link_args.extend(['--coverage'])
if c in self.copt:
for e in self.extensions:
e.extra_compile_args.extend(self.copt[c])
if c in self.lopt:
for e in self.extensions:
e.extra_link_args.extend(self.lopt[c])


def build_extensions(self):
# We need to create the thunk code
self.run_command("build_java")
@@ -196,4 +200,3 @@ def build_extensions(self):

def __init__(self, *args):
build_ext.__init__(self, *args)

@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import fnmatch
import os
import distutils.cmd
import distutils.log
@@ -15,7 +16,6 @@ def translate(s, cfrom, cto):
def translate(s, cfrom, cto):
return s.translate(str.maketrans(cfrom, cto))

import fnmatch

# Python2/3 don't agree on how glob should work

@@ -20,5 +20,3 @@ def run_tests(self):

errno = pytest.main(shlex.split(self.pytest_args))
sys.exit(errno)


0 comments on commit bdc654e

Please sign in to comment.
You can’t perform that action at this time.