mirror of https://github.com/kivy/pyjnius.git
fix import in python 3.8/windows
This commit is contained in:
parent
4a60858133
commit
9ee1183cda
|
@ -22,8 +22,6 @@ jobs:
|
|||
|
||||
# exclude problematic combinations
|
||||
exclude:
|
||||
- os: windows-latest
|
||||
python: '3.8'
|
||||
- os: windows-latest
|
||||
python: '2.7'
|
||||
- os: macOs-latest
|
||||
|
|
|
@ -7,7 +7,7 @@ jobs:
|
|||
matrix:
|
||||
python:
|
||||
- '2.7'
|
||||
# - '3.6'
|
||||
- '3.6'
|
||||
- '3.7'
|
||||
- '3.8'
|
||||
java:
|
||||
|
@ -26,8 +26,6 @@ jobs:
|
|||
|
||||
# exclude problematic combinations
|
||||
exclude:
|
||||
- os: windows-latest
|
||||
python: '3.8'
|
||||
- os: windows-latest
|
||||
python: '2.7'
|
||||
- os: macOs-latest
|
||||
|
|
|
@ -9,9 +9,38 @@ All the documentation is available at: http://pyjnius.readthedocs.org
|
|||
|
||||
__version__ = '1.2.1.dev3'
|
||||
|
||||
from .env import get_jnius_lib_location
|
||||
from .jnius import * # noqa
|
||||
from .reflect import * # noqa
|
||||
from .env import get_jnius_lib_location, get_jdk_home
|
||||
|
||||
import os
|
||||
import sys
|
||||
if sys.platform == 'win32' and sys.version_info >= (3, 8):
|
||||
path = os.path.dirname(__file__)
|
||||
jdk_home = get_jdk_home(sys.platform)
|
||||
with os.add_dll_directory(path):
|
||||
for suffix in (
|
||||
('bin', 'client'),
|
||||
('bin', 'server'),
|
||||
('jre', 'bin', 'client'),
|
||||
('jre', 'bin', 'server'),
|
||||
):
|
||||
path = os.path.join(jdk_home, *suffix)
|
||||
if not os.path.isdir(path):
|
||||
continue
|
||||
|
||||
with os.add_dll_directory(path):
|
||||
try:
|
||||
from .jnius import * # noqa
|
||||
from .reflect import * # noqa
|
||||
except Exception as e:
|
||||
pass
|
||||
else:
|
||||
break
|
||||
else:
|
||||
raise Exception("Unable to create jni env, no jvm dll found.")
|
||||
else:
|
||||
from .jnius import * # noqa
|
||||
from .reflect import * # noqa
|
||||
|
||||
from six import with_metaclass
|
||||
|
||||
# XXX monkey patch methods that cannot be in cython.
|
||||
|
|
|
@ -10,6 +10,7 @@ from platform import machine
|
|||
from subprocess import Popen, check_output, PIPE
|
||||
from shlex import split
|
||||
|
||||
|
||||
PY2 = sys.version_info.major < 3
|
||||
|
||||
machine = machine() # not expected to change at runtime
|
||||
|
@ -140,6 +141,7 @@ def get_jdk_home(platform):
|
|||
|
||||
return jdk_home
|
||||
|
||||
|
||||
def get_osx_framework():
|
||||
framework = Popen(
|
||||
'/usr/libexec/java_home',
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
import sys
|
||||
import os
|
||||
from os.path import join
|
||||
from jnius.env import get_jdk_home
|
||||
from cpython.version cimport PY_MAJOR_VERSION
|
||||
|
||||
# on desktop, we need to create an env :)
|
||||
|
@ -43,7 +47,31 @@ cdef void create_jnienv() except *:
|
|||
args.nOptions = len(optarr)
|
||||
args.ignoreUnrecognized = JNI_FALSE
|
||||
|
||||
ret = JNI_CreateJavaVM(&jvm, <void **>&_platform_default_env, &args)
|
||||
if sys.version_info >= (3, 8):
|
||||
# uh, let's see if this works and cleanup later
|
||||
jdk_home = get_jdk_home('win32')
|
||||
for suffix in (
|
||||
('bin', 'client'),
|
||||
('bin', 'server'),
|
||||
('jre', 'bin', 'client'),
|
||||
('jre', 'bin', 'server'),
|
||||
):
|
||||
path = join(jdk_home, *suffix)
|
||||
if not os.path.isdir(path):
|
||||
continue
|
||||
with os.add_dll_directory(path):
|
||||
try:
|
||||
ret = JNI_CreateJavaVM(&jvm, <void **>&_platform_default_env, &args)
|
||||
except Exception as e:
|
||||
pass
|
||||
else:
|
||||
break
|
||||
else:
|
||||
raise Exception("Unable to create jni env, no jvm dll found.")
|
||||
|
||||
else:
|
||||
ret = JNI_CreateJavaVM(&jvm, <void **>&_platform_default_env, &args)
|
||||
|
||||
free(options)
|
||||
|
||||
if ret != JNI_OK:
|
||||
|
|
|
@ -2,7 +2,7 @@ include "config.pxi"
|
|||
import os
|
||||
from shlex import split
|
||||
from subprocess import check_output
|
||||
from os.path import dirname
|
||||
from os.path import dirname, join
|
||||
from os import readlink
|
||||
from sys import platform
|
||||
from .env import get_jnius_lib_location
|
||||
|
@ -64,6 +64,7 @@ cdef void create_jnienv() except *:
|
|||
cdef JavaVMOption *options
|
||||
cdef int ret
|
||||
cdef bytes py_bytes
|
||||
cdef void *handle
|
||||
import jnius_config
|
||||
|
||||
JAVA_HOME = os.getenv('JAVA_HOME') or find_java_home()
|
||||
|
@ -80,7 +81,8 @@ cdef void create_jnienv() except *:
|
|||
ELSE:
|
||||
lib_path = str_for_c(os.path.join(JAVA_HOME, JNIUS_LIB_SUFFIX))
|
||||
|
||||
cdef void *handle = dlopen(lib_path, RTLD_NOW | RTLD_GLOBAL)
|
||||
handle = dlopen(lib_path, RTLD_NOW | RTLD_GLOBAL)
|
||||
|
||||
if handle == NULL:
|
||||
raise SystemError("Error calling dlopen({0}: {1}".format(lib_path, dlerror()))
|
||||
|
||||
|
|
Loading…
Reference in New Issue