From d8b4e69f5990c6606d537d4ace8d4ca6aa581472 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sat, 29 Apr 2023 13:44:44 +0200 Subject: [PATCH 01/45] try to use a strategy in test snippet to include more jdk versions during testing. --- .azure/scripts/test.yml | 96 ++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 45 deletions(-) diff --git a/.azure/scripts/test.yml b/.azure/scripts/test.yml index 3177c59ab..8d48c2b08 100644 --- a/.azure/scripts/test.yml +++ b/.azure/scripts/test.yml @@ -1,48 +1,54 @@ # This task tests individual platforms and versions +strategy: + matrix: + jdk_version: + - '8' + - '11' + steps: -- task: UsePythonVersion@0 - inputs: - versionSpec: '$(python.version)' - -- template: jdk.yml - parameters: - version: 11 - -- script: | - python setup.py build_ext --inplace - displayName: 'Build module' - -- script: | - pip install numpy jedi typing_extensions - python -c "import jpype" - displayName: 'Check module' - -- script: | - python setup.py test_java - pip install -r test-requirements.txt - displayName: 'Install test' - -- script: | - python -m pytest -v --junit-xml=build/test/test.xml test/jpypetest --checkjni - displayName: 'Test JDK 11' - condition: eq(variables['jpypetest.fast'], 'false') - -- script: | - python -m pytest -v --junit-xml=build/test/test.xml test/jpypetest --checkjni --fast - displayName: 'Test JDK 11 (fast)' - condition: eq(variables['jpypetest.fast'], 'true') - -# presence of jpype/ seems to confuse entry_points so `cd` elsewhere -- script: | - pip install . - mkdir empty - cd empty - python -m PyInstaller.utils.run_tests --include_only jpype._pyinstaller. - displayName: 'Test PyInstaller result' - -- task: PublishTestResults@2 - condition: succeededOrFailed() - inputs: - testResultsFiles: 'build/test/test.xml' - testRunTitle: 'Publish test results for Python $(python.version) with JDK 11' + - task: UsePythonVersion@0 + inputs: + versionSpec: '$(python.version)' + + - template: jdk.yml + parameters: + version: ${{ matrix.jdk_version }} + + - script: | + python setup.py build_ext --inplace + displayName: 'Build module' + + - script: | + pip install numpy jedi typing_extensions + python -c "import jpype" + displayName: 'Check module' + + - script: | + python setup.py test_java + pip install -r test-requirements.txt + displayName: 'Install test' + + - script: | + python -m pytest -v --junit-xml=build/test/test.xml test/jpypetest --checkjni + displayName: 'Test JDK ${{ matrix.jdk_version }}' + condition: eq(variables['jpypetest.fast'], 'false') + + - script: | + python -m pytest -v --junit-xml=build/test/test.xml test/jpypetest --checkjni --fast + displayName: 'Test JDK ${{ matrix.jdk_version }} (fast)' + condition: eq(variables['jpypetest.fast'], 'true') + + # presence of jpype/ seems to confuse entry_points so `cd` elsewhere + - script: | + pip install . + mkdir empty + cd empty + python -m PyInstaller.utils.run_tests --include_only jpype._pyinstaller. + displayName: 'Test PyInstaller result' + + - task: PublishTestResults@2 + condition: succeededOrFailed() + inputs: + testResultsFiles: 'build/test/test.xml' + testRunTitle: 'Publish test results for Python $(python.version) with JDK ${{ matrix.jdk_version }}' From b7b3b8eec20c670a2fa2c6a7cdf3685944850dbe Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sat, 29 Apr 2023 14:15:15 +0200 Subject: [PATCH 02/45] try a mixture of jdk and python versions --- .azure/build.yml | 9 ++++ .azure/scripts/test.yml | 95 +++++++++++++++++++---------------------- 2 files changed, 53 insertions(+), 51 deletions(-) diff --git a/.azure/build.yml b/.azure/build.yml index 4b16e8e04..e4378b613 100644 --- a/.azure/build.yml +++ b/.azure/build.yml @@ -56,24 +56,31 @@ jobs: linux-3.8: imageName: "ubuntu-latest" python.version: '3.8' + jdk.version: '8' linux-3.9: imageName: "ubuntu-latest" python.version: '3.9' + jdk.version: '11' linux-3.10: imageName: "ubuntu-latest" python.version: '3.10' + jdk.version: '17' linux-3.11: imageName: "ubuntu-latest" python.version: '3.11' + jdk.version: '17' windows-3.7: imageName: "windows-2019" python.version: '3.7' + jdk.version: '8' windows-3.8: imageName: "windows-2019" python.version: '3.8' + jdk.version: '11' windows-3.9: imageName: "windows-2019" python.version: '3.9' + jdk.version: '17' #jpypetest.fast: 'true' windows-3.10: imageName: "windows-2019" @@ -81,9 +88,11 @@ jobs: windows-3.11: imageName: "windows-2019" python.version: '3.11' + jdk.version: '17' mac-3.9: imageName: "macos-11" python.version: '3.9' + jdk.version: '11' jpypetest.fast: 'true' pool: diff --git a/.azure/scripts/test.yml b/.azure/scripts/test.yml index 8d48c2b08..ed9af0c39 100644 --- a/.azure/scripts/test.yml +++ b/.azure/scripts/test.yml @@ -1,54 +1,47 @@ # This task tests individual platforms and versions -strategy: - matrix: - jdk_version: - - '8' - - '11' - steps: - - task: UsePythonVersion@0 - inputs: - versionSpec: '$(python.version)' - - - template: jdk.yml - parameters: - version: ${{ matrix.jdk_version }} - - - script: | - python setup.py build_ext --inplace - displayName: 'Build module' - - - script: | - pip install numpy jedi typing_extensions - python -c "import jpype" - displayName: 'Check module' - - - script: | - python setup.py test_java - pip install -r test-requirements.txt - displayName: 'Install test' - - - script: | - python -m pytest -v --junit-xml=build/test/test.xml test/jpypetest --checkjni - displayName: 'Test JDK ${{ matrix.jdk_version }}' - condition: eq(variables['jpypetest.fast'], 'false') - - - script: | - python -m pytest -v --junit-xml=build/test/test.xml test/jpypetest --checkjni --fast - displayName: 'Test JDK ${{ matrix.jdk_version }} (fast)' - condition: eq(variables['jpypetest.fast'], 'true') - - # presence of jpype/ seems to confuse entry_points so `cd` elsewhere - - script: | - pip install . - mkdir empty - cd empty - python -m PyInstaller.utils.run_tests --include_only jpype._pyinstaller. - displayName: 'Test PyInstaller result' - - - task: PublishTestResults@2 - condition: succeededOrFailed() - inputs: - testResultsFiles: 'build/test/test.xml' - testRunTitle: 'Publish test results for Python $(python.version) with JDK ${{ matrix.jdk_version }}' +- task: UsePythonVersion@0 + inputs: + versionSpec: '$(python.version)' +- task: UseJavaVersion@1 + inputs: + versionSpec: '$(jdk.version)' + +- script: | + python setup.py build_ext --inplace + displayName: 'Build module' + +- script: | + pip install numpy jedi typing_extensions + python -c "import jpype" + displayName: 'Check module' + +- script: | + python setup.py test_java + pip install -r test-requirements.txt + displayName: 'Install test' + +- script: | + python -m pytest -v --junit-xml=build/test/test.xml test/jpypetest --checkjni + displayName: 'Test JDK 11' + condition: eq(variables['jpypetest.fast'], 'false') + +- script: | + python -m pytest -v --junit-xml=build/test/test.xml test/jpypetest --checkjni --fast + displayName: 'Test JDK 11 (fast)' + condition: eq(variables['jpypetest.fast'], 'true') + +# presence of jpype/ seems to confuse entry_points so `cd` elsewhere +- script: | + pip install . + mkdir empty + cd empty + python -m PyInstaller.utils.run_tests --include_only jpype._pyinstaller. + displayName: 'Test PyInstaller result' + +- task: PublishTestResults@2 + condition: succeededOrFailed() + inputs: + testResultsFiles: 'build/test/test.xml' + testRunTitle: 'Publish test results for Python $(python.version) with JDK 11' From c86d99a35f2983c4c34140c4bb251e08420d5c49 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sat, 29 Apr 2023 14:27:40 +0200 Subject: [PATCH 03/45] try tool installer --- .azure/scripts/test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.azure/scripts/test.yml b/.azure/scripts/test.yml index ed9af0c39..f534b81c3 100644 --- a/.azure/scripts/test.yml +++ b/.azure/scripts/test.yml @@ -3,10 +3,10 @@ steps: - task: UsePythonVersion@0 inputs: versionSpec: '$(python.version)' -- task: UseJavaVersion@1 +- task: ToolInstaller@1 inputs: - versionSpec: '$(jdk.version)' - + toolName: 'jdk' + version: '$(jdk.version)' - script: | python setup.py build_ext --inplace displayName: 'Build module' From 2b68c2a44214715e271b2f0e7cd3b159020b7a00 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sat, 29 Apr 2023 17:50:53 +0200 Subject: [PATCH 04/45] try JavaToolInstaller --- .azure/scripts/test.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.azure/scripts/test.yml b/.azure/scripts/test.yml index f534b81c3..0d55e1bb9 100644 --- a/.azure/scripts/test.yml +++ b/.azure/scripts/test.yml @@ -3,10 +3,13 @@ steps: - task: UsePythonVersion@0 inputs: versionSpec: '$(python.version)' -- task: ToolInstaller@1 + +- task: JavaToolInstaller@0 inputs: - toolName: 'jdk' - version: '$(jdk.version)' + versionSpec: '$(jdk.version)' + jdkArchitectureOption: 'x64' + jdkSourceOption: 'PreInstalled' + - script: | python setup.py build_ext --inplace displayName: 'Build module' From 62093dca14e51b98bfa55fd6800f205d260a2b37 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sat, 29 Apr 2023 18:04:55 +0200 Subject: [PATCH 05/45] use JavaToolInstaller in jdk.yml --- .azure/scripts/jdk.yml | 14 +++++--------- .azure/scripts/test.yml | 8 +++----- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.azure/scripts/jdk.yml b/.azure/scripts/jdk.yml index d37fd5808..e8362b8aa 100644 --- a/.azure/scripts/jdk.yml +++ b/.azure/scripts/jdk.yml @@ -3,12 +3,8 @@ parameters: type: string default: 8 -steps: -- script: | - set v="##vso[task.setvariable variable=JAVA_HOME]%JAVA_HOME_${{parameters.version}}_X64%" - echo %v:"=% - condition: eq(variables['Agent.OS'], 'Windows_NT') - -- script: | - echo "##vso[task.setvariable variable=JAVA_HOME]$(JAVA_HOME_${{parameters.version}}_X64)" - condition: ne(variables['Agent.OS'], 'Windows_NT') +- task: JavaToolInstaller@0 + inputs: + versionSpec: '$(parameters.version)' + jdkArchitectureOption: 'x64' + jdkSourceOption: 'PreInstalled' diff --git a/.azure/scripts/test.yml b/.azure/scripts/test.yml index 0d55e1bb9..1820a34df 100644 --- a/.azure/scripts/test.yml +++ b/.azure/scripts/test.yml @@ -4,11 +4,9 @@ steps: inputs: versionSpec: '$(python.version)' -- task: JavaToolInstaller@0 - inputs: - versionSpec: '$(jdk.version)' - jdkArchitectureOption: 'x64' - jdkSourceOption: 'PreInstalled' +- template: jdk.yml + parameters: + version: '$(jdk.version)' - script: | python setup.py build_ext --inplace From 0ac018b14666f0a53b0a1efd14abdf1f79736f10 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sat, 29 Apr 2023 18:09:13 +0200 Subject: [PATCH 06/45] steps --- .azure/scripts/jdk.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.azure/scripts/jdk.yml b/.azure/scripts/jdk.yml index e8362b8aa..02581c40a 100644 --- a/.azure/scripts/jdk.yml +++ b/.azure/scripts/jdk.yml @@ -3,8 +3,9 @@ parameters: type: string default: 8 -- task: JavaToolInstaller@0 - inputs: - versionSpec: '$(parameters.version)' - jdkArchitectureOption: 'x64' - jdkSourceOption: 'PreInstalled' +steps: + - task: JavaToolInstaller@0 + inputs: + versionSpec: '$(parameters.version)' + jdkArchitectureOption: 'x64' + jdkSourceOption: 'PreInstalled' From c9025abda6ded82830446ee03a222f62fd402176 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sat, 29 Apr 2023 18:18:40 +0200 Subject: [PATCH 07/45] use another variable expansion technique --- .azure/scripts/jdk.yml | 2 +- .azure/scripts/test.yml | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.azure/scripts/jdk.yml b/.azure/scripts/jdk.yml index 02581c40a..7ffbe4d84 100644 --- a/.azure/scripts/jdk.yml +++ b/.azure/scripts/jdk.yml @@ -6,6 +6,6 @@ parameters: steps: - task: JavaToolInstaller@0 inputs: - versionSpec: '$(parameters.version)' + versionSpec: ${{ parameters.version }} jdkArchitectureOption: 'x64' jdkSourceOption: 'PreInstalled' diff --git a/.azure/scripts/test.yml b/.azure/scripts/test.yml index 1820a34df..d8f528f31 100644 --- a/.azure/scripts/test.yml +++ b/.azure/scripts/test.yml @@ -24,12 +24,12 @@ steps: - script: | python -m pytest -v --junit-xml=build/test/test.xml test/jpypetest --checkjni - displayName: 'Test JDK 11' + displayName: 'Test JDK $(jdk.version)' condition: eq(variables['jpypetest.fast'], 'false') - script: | python -m pytest -v --junit-xml=build/test/test.xml test/jpypetest --checkjni --fast - displayName: 'Test JDK 11 (fast)' + displayName: 'Test JDK $(jdk.version) (fast)' condition: eq(variables['jpypetest.fast'], 'true') # presence of jpype/ seems to confuse entry_points so `cd` elsewhere @@ -44,5 +44,4 @@ steps: condition: succeededOrFailed() inputs: testResultsFiles: 'build/test/test.xml' - testRunTitle: 'Publish test results for Python $(python.version) with JDK 11' - + testRunTitle: 'Publish test results for Python $(python.version) with JDK $(jdk.version)' From 8384638f1332533a9f9158d77a29791c49851580 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sat, 29 Apr 2023 18:33:06 +0200 Subject: [PATCH 08/45] add missing version --- .azure/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.azure/build.yml b/.azure/build.yml index e4378b613..93ff30401 100644 --- a/.azure/build.yml +++ b/.azure/build.yml @@ -53,6 +53,7 @@ jobs: linux-3.7: imageName: "ubuntu-latest" python.version: '3.7' + jdk.version: '8' linux-3.8: imageName: "ubuntu-latest" python.version: '3.8' From e5480b09fb9ee4a9a34cf493addef6fbcbeb6047 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sat, 29 Apr 2023 18:33:22 +0200 Subject: [PATCH 09/45] fix type --- .azure/scripts/jdk.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure/scripts/jdk.yml b/.azure/scripts/jdk.yml index 7ffbe4d84..614ae6b47 100644 --- a/.azure/scripts/jdk.yml +++ b/.azure/scripts/jdk.yml @@ -1,7 +1,7 @@ parameters: - name: version type: string - default: 8 + default: '8' steps: - task: JavaToolInstaller@0 From b711ae12312776ad8ba8cd760ccfc6314c8345f8 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sat, 29 Apr 2023 19:11:54 +0200 Subject: [PATCH 10/45] generate sane displayName --- .azure/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.azure/build.yml b/.azure/build.yml index 93ff30401..69998495c 100644 --- a/.azure/build.yml +++ b/.azure/build.yml @@ -54,6 +54,7 @@ jobs: imageName: "ubuntu-latest" python.version: '3.7' jdk.version: '8' + displayName: '${{ matrix.imageName }}-py-${{ matrix.python.version }}-JDK${{ matrix.jdk.version }}' linux-3.8: imageName: "ubuntu-latest" python.version: '3.8' From 12779374e0c0df2e528a2c49c7268ebf5bf7e42f Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sat, 29 Apr 2023 19:17:19 +0200 Subject: [PATCH 11/45] revert --- .azure/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.azure/build.yml b/.azure/build.yml index 69998495c..93ff30401 100644 --- a/.azure/build.yml +++ b/.azure/build.yml @@ -54,7 +54,6 @@ jobs: imageName: "ubuntu-latest" python.version: '3.7' jdk.version: '8' - displayName: '${{ matrix.imageName }}-py-${{ matrix.python.version }}-JDK${{ matrix.jdk.version }}' linux-3.8: imageName: "ubuntu-latest" python.version: '3.8' From f6922035c9cd19b66b9d11dd8fe33aab024ac7eb Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sat, 29 Apr 2023 19:18:50 +0200 Subject: [PATCH 12/45] missing vars. --- .azure/build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.azure/build.yml b/.azure/build.yml index 93ff30401..518804206 100644 --- a/.azure/build.yml +++ b/.azure/build.yml @@ -86,6 +86,7 @@ jobs: windows-3.10: imageName: "windows-2019" python.version: '3.10' + jdk.version: '11' windows-3.11: imageName: "windows-2019" python.version: '3.11' @@ -93,7 +94,7 @@ jobs: mac-3.9: imageName: "macos-11" python.version: '3.9' - jdk.version: '11' + jdk.version: '17' jpypetest.fast: 'true' pool: From 283b39f608bed7a06e5ddce74693c7ed8c3b1272 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Sat, 29 Apr 2023 13:34:44 +0200 Subject: [PATCH 13/45] added new jni versions ranged from 9 to 21 (from openjdk) --- native/jni_include/jni.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/native/jni_include/jni.h b/native/jni_include/jni.h index a380acf71..04e7dbfc6 100644 --- a/native/jni_include/jni.h +++ b/native/jni_include/jni.h @@ -1179,6 +1179,11 @@ JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved); #define JNI_VERSION_1_6 0x00010006 #define JNI_VERSION_1_7 0x00010007 #define JNI_VERSION_1_8 0x00010008 +#define JNI_VERSION_9 0x00090000 +#define JNI_VERSION_10 0x000a0000 +#define JNI_VERSION_19 0x00130000 +#define JNI_VERSION_20 0x00140000 +#define JNI_VERSION_21 0x00150000 #define JNI_OK (0) /* no error */ #define JNI_ERR (-1) /* generic error */ From 21166bad014ad9a27a50c7da4883f65ff245630b Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Mon, 19 Aug 2024 23:58:05 +0200 Subject: [PATCH 14/45] wip --- jpype/_jvmfinder.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jpype/_jvmfinder.py b/jpype/_jvmfinder.py index 64b656c2b..0202aae45 100644 --- a/jpype/_jvmfinder.py +++ b/jpype/_jvmfinder.py @@ -37,7 +37,6 @@ class JVMNotFoundException(ValueError): To avoid this exception specify the JAVA_HOME environment variable as a valid jre or jdk root directory. """ - pass class JVMNotSupportedException(ValueError): @@ -49,7 +48,6 @@ class JVMNotSupportedException(ValueError): 32 vs 64 bit, or the JVM is older than the version used to compile JPype. """ - pass def getDefaultJVMPath(): @@ -74,6 +72,9 @@ def getDefaultJVMPath(): return finder.get_jvm_path() +get_default_jvm_path = getDefaultJVMPath + + class JVMFinder(object): """ JVM library finder base class From 3ad084a6a4d5ef450e5e7ca51fe26801db7039ad Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 00:04:39 +0200 Subject: [PATCH 15/45] remove py 3.7 --- .azure/build.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.azure/build.yml b/.azure/build.yml index 5226e47b1..a07ee84b6 100644 --- a/.azure/build.yml +++ b/.azure/build.yml @@ -50,10 +50,7 @@ jobs: dependsOn: Deps strategy: matrix: - linux-3.7: - imageName: "ubuntu-latest" - python.version: '3.7' - linux-3.8: + linux-3.8: # todo: 3.8 will be EOL on October 31, 2024 imageName: "ubuntu-latest" python.version: '3.8' jdk.version: '8' From 3e7a75b85f192ab5508c22cadcfc66b77ed314de Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 00:27:50 +0200 Subject: [PATCH 16/45] add win-py312-jdk-17 to matrix --- .azure/build.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.azure/build.yml b/.azure/build.yml index a07ee84b6..efef78da9 100644 --- a/.azure/build.yml +++ b/.azure/build.yml @@ -50,6 +50,7 @@ jobs: dependsOn: Deps strategy: matrix: + # Linux linux-3.8: # todo: 3.8 will be EOL on October 31, 2024 imageName: "ubuntu-latest" python.version: '3.8' @@ -69,11 +70,11 @@ jobs: linux-3.12: imageName: "ubuntu-latest" python.version: '3.12' + # Windows windows-3.8: imageName: "windows-2019" python.version: '3.8' jdk.version: '8' - windows-3.9: imageName: "windows-2019" python.version: '3.9' @@ -85,6 +86,11 @@ jobs: imageName: "windows-2019" python.version: '3.11' jdk.version: '17' + windows-3.12: + imageName: "windows-2019" + python.version: '3.12' + jdk.version: '21' + # OSX mac-3.9: imageName: "macos-11" python.version: '3.9' @@ -104,7 +110,7 @@ jobs: matrix: linux-3.8: imageName: "ubuntu-16.04" - jdk_version: "1.11" + jdk_version: "1.11" # fixme: this version is simply ignored. python.version: '3.8' pool: vmImage: $(imageName) From 89f905d3a54cc4e53009618cdaa5a1b95ab6252e Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 00:37:18 +0200 Subject: [PATCH 17/45] use macos-12 image --- .azure/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.azure/build.yml b/.azure/build.yml index efef78da9..7b5b3efef 100644 --- a/.azure/build.yml +++ b/.azure/build.yml @@ -92,8 +92,8 @@ jobs: jdk.version: '21' # OSX mac-3.9: - imageName: "macos-11" - python.version: '3.9' + imageName: "macos-12" + python.version: '3.12' jpypetest.fast: 'true' jdk.version: '17' From 986c61c460e40ebefcbe37056ed5b7c1f75a0b40 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 00:40:44 +0200 Subject: [PATCH 18/45] test old py and j for osx --- .azure/build.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.azure/build.yml b/.azure/build.yml index 7b5b3efef..82d410425 100644 --- a/.azure/build.yml +++ b/.azure/build.yml @@ -91,7 +91,12 @@ jobs: python.version: '3.12' jdk.version: '21' # OSX - mac-3.9: + mac-3.8: + imageName: "macos-12" + python.version: '3.8' + jpypetest.fast: 'true' + jdk.version: '8' + mac-3.12: imageName: "macos-12" python.version: '3.12' jpypetest.fast: 'true' From e23f1de3770da43c3a0e8cfae6a08ed57c1fb960 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 00:43:13 +0200 Subject: [PATCH 19/45] try to fix debug job (how to trigger it?) --- .azure/build.yml | 7 ++++--- .azure/scripts/debug.yml | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.azure/build.yml b/.azure/build.yml index 82d410425..a68a77328 100644 --- a/.azure/build.yml +++ b/.azure/build.yml @@ -73,7 +73,7 @@ jobs: # Windows windows-3.8: imageName: "windows-2019" - python.version: '3.8' + python.version: '3.8' # todo: 3.8 will be EOL on October 31, 2024 jdk.version: '8' windows-3.9: imageName: "windows-2019" @@ -93,7 +93,7 @@ jobs: # OSX mac-3.8: imageName: "macos-12" - python.version: '3.8' + python.version: '3.8' # todo: 3.8 will be EOL on October 31, 2024 jpypetest.fast: 'true' jdk.version: '8' mac-3.12: @@ -115,11 +115,12 @@ jobs: matrix: linux-3.8: imageName: "ubuntu-16.04" - jdk_version: "1.11" # fixme: this version is simply ignored. + jdk.version: "11" python.version: '3.8' pool: vmImage: $(imageName) steps: + - template: - template: scripts/deps.yml - template: scripts/debug.yml diff --git a/.azure/scripts/debug.yml b/.azure/scripts/debug.yml index 4f8d9ca08..7341ed53c 100644 --- a/.azure/scripts/debug.yml +++ b/.azure/scripts/debug.yml @@ -5,6 +5,10 @@ steps: inputs: versionSpec: '$(python.version)' +- template: jdk.yml + parameters: + version: '$(jdk.version)' + - script: | sudo apt install gdb pip install ./ From 6722c6dfee58c960d75ab24a6603714bbc79d87c Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 10:43:29 +0200 Subject: [PATCH 20/45] test sqlite only for jvm versions > 8 --- test/jpypetest/test_sql_sqlite.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/test/jpypetest/test_sql_sqlite.py b/test/jpypetest/test_sql_sqlite.py index a63b4e02c..0b6156b64 100644 --- a/test/jpypetest/test_sql_sqlite.py +++ b/test/jpypetest/test_sql_sqlite.py @@ -1,15 +1,15 @@ # This file is Public Domain and may be used without restrictions, # because nobody should have to waste their lives typing this again. -import jpype -from jpype.types import * -from jpype import java -import jpype.dbapi2 as dbapi2 -import common import datetime import decimal +import sys import threading -java = jpype.java +import common +import jpype +import jpype.dbapi2 as dbapi2 +from jpype import java, isJVMStarted +from jpype.types import * try: import zlib @@ -20,12 +20,22 @@ db_name = "jdbc:sqlite::memory:" +if isJVMStarted(): + java_version = str(jpype.java.lang.System.getProperty("java.version")) + java_version = java_version.split(".") + + if java_version[0] == "8":# and sys.platform == "win": + raise common.unittest.SkipTest("sqlite unsupported on this config.") + + class ConnectTestCase(common.JPypeTestCase): def setUp(self): common.JPypeTestCase.setUp(self) if common.fast: raise common.unittest.SkipTest("fast") + + def testConnect(self): cx = dbapi2.connect(db_name) self.assertIsInstance(cx, dbapi2.Connection) From 3a7f44e488a25a8d5af9c251cacbdb263375e161 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 10:44:53 +0200 Subject: [PATCH 21/45] shut up mypy --- test/jpypetest/test_sql_sqlite.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/jpypetest/test_sql_sqlite.py b/test/jpypetest/test_sql_sqlite.py index 0b6156b64..e296e5c0a 100644 --- a/test/jpypetest/test_sql_sqlite.py +++ b/test/jpypetest/test_sql_sqlite.py @@ -21,8 +21,7 @@ if isJVMStarted(): - java_version = str(jpype.java.lang.System.getProperty("java.version")) - java_version = java_version.split(".") + java_version = str(jpype.java.lang.System.getProperty("java.version")).split(".") if java_version[0] == "8":# and sys.platform == "win": raise common.unittest.SkipTest("sqlite unsupported on this config.") From dc75df26c31682e05f370357ee0035dae1a26da5 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 10:49:34 +0200 Subject: [PATCH 22/45] f --- .azure/build.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.azure/build.yml b/.azure/build.yml index a68a77328..a3a33e43e 100644 --- a/.azure/build.yml +++ b/.azure/build.yml @@ -120,7 +120,5 @@ jobs: pool: vmImage: $(imageName) steps: - - template: - template: scripts/deps.yml - template: scripts/debug.yml - From 43d40057440d4e70d4ffeaece85119cd9633de78 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 10:53:14 +0200 Subject: [PATCH 23/45] imports --- test/jpypetest/test_sql_generic.py | 1 - test/jpypetest/test_sql_sqlite.py | 1 - 2 files changed, 2 deletions(-) diff --git a/test/jpypetest/test_sql_generic.py b/test/jpypetest/test_sql_generic.py index d2381a2ec..69e1128c9 100644 --- a/test/jpypetest/test_sql_generic.py +++ b/test/jpypetest/test_sql_generic.py @@ -1,5 +1,4 @@ # This file is Public Domain and may be used without restrictions. -from jpype.types import * import jpype.dbapi2 as dbapi2 import common import time diff --git a/test/jpypetest/test_sql_sqlite.py b/test/jpypetest/test_sql_sqlite.py index e296e5c0a..530987037 100644 --- a/test/jpypetest/test_sql_sqlite.py +++ b/test/jpypetest/test_sql_sqlite.py @@ -2,7 +2,6 @@ # because nobody should have to waste their lives typing this again. import datetime import decimal -import sys import threading import common From 1e18114dbb892bc1a585f486456920ad2b8ee021 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 10:55:16 +0200 Subject: [PATCH 24/45] update AUTHORS.rst --- AUTHORS.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 45b48bf96..029f3e03a 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -2,8 +2,8 @@ Authors ------- The original author: Steve Menard - -Current Maintainer: Luis Nell +Current Lead Developer: Karl Einar Nelson +Current Maintainer: Martin K. Scherer Huge thanks to these CONTRIBUTORS: From d7352b4492ddbbaabc346cfb54c7d78881d4325a Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 10:55:41 +0200 Subject: [PATCH 25/45] imports --- test/jpypetest/conftest.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/jpypetest/conftest.py b/test/jpypetest/conftest.py index ecdf6ee03..2661b9062 100755 --- a/test/jpypetest/conftest.py +++ b/test/jpypetest/conftest.py @@ -16,8 +16,6 @@ # # ***************************************************************************** import pytest -import _jpype -import jpype import common From 335809d8d83db0f6b48b7fc37e1450f069c0c431 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 10:56:08 +0200 Subject: [PATCH 26/45] imports (locally in WinJVMFinder) --- jpype/_jvmfinder.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/jpype/_jvmfinder.py b/jpype/_jvmfinder.py index 70d7abb0a..f19c1aa36 100644 --- a/jpype/_jvmfinder.py +++ b/jpype/_jvmfinder.py @@ -23,10 +23,7 @@ __all__ = ['getDefaultJVMPath', 'JVMNotFoundException', 'JVMNotSupportedException'] -try: - import winreg -except ImportError: - winreg = None # type: ignore[assignment] + class JVMNotFoundException(ValueError): @@ -392,8 +389,11 @@ def _get_from_registry(self): :return: The path found in the registry, or None """ - if not winreg: + try: + import winreg + except ImportError: return None + for location in reg_keys: try: jreKey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, location) From f9e2b7887f68fc80e774ac3e1fd8a30f936a286d Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 11:05:49 +0200 Subject: [PATCH 27/45] [ci] name jobs with python and jdk suffix --- .azure/build.yml | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/.azure/build.yml b/.azure/build.yml index a3a33e43e..c5f8473c7 100644 --- a/.azure/build.yml +++ b/.azure/build.yml @@ -51,52 +51,54 @@ jobs: strategy: matrix: # Linux - linux-3.8: # todo: 3.8 will be EOL on October 31, 2024 + linux-py3.8-jdk8: # todo: 3.8 will be EOL on October 31, 2024 imageName: "ubuntu-latest" python.version: '3.8' jdk.version: '8' - linux-3.9: + linux-py3.9-jdk11: imageName: "ubuntu-latest" python.version: '3.9' jdk.version: '11' - linux-3.10: + linux-py3.10-jdk17: imageName: "ubuntu-latest" python.version: '3.10' jdk.version: '17' - linux-3.11: + linux-py3.11-jdk17: imageName: "ubuntu-latest" python.version: '3.11' jdk.version: '17' - linux-3.12: + linux-py3.12-jdk17: imageName: "ubuntu-latest" python.version: '3.12' + jdk.version: '17' # Windows - windows-3.8: + windows-py3.8-jdk8: imageName: "windows-2019" python.version: '3.8' # todo: 3.8 will be EOL on October 31, 2024 jdk.version: '8' - windows-3.9: + windows-py3.9-jdk11: imageName: "windows-2019" python.version: '3.9' jdk.version: '11' - windows-3.10: + windows-py3.10-jdk8: imageName: "windows-2019" python.version: '3.10' - windows-3.11: + jdk.version: '8' + windows-py3.11-jdk17: imageName: "windows-2019" python.version: '3.11' jdk.version: '17' - windows-3.12: + windows-py3.12-jdk21: imageName: "windows-2019" python.version: '3.12' jdk.version: '21' - # OSX - mac-3.8: + # OSX, we only test an old Python version with JDK8 and recent Py with recent JDK. + mac-py3.8-jdk8: imageName: "macos-12" python.version: '3.8' # todo: 3.8 will be EOL on October 31, 2024 jpypetest.fast: 'true' jdk.version: '8' - mac-3.12: + mac-py3.12-jdk17: imageName: "macos-12" python.version: '3.12' jpypetest.fast: 'true' @@ -113,7 +115,7 @@ jobs: dependsOn: Deps strategy: matrix: - linux-3.8: + linux-py3.8-jdk11: imageName: "ubuntu-16.04" jdk.version: "11" python.version: '3.8' From 56e17eea4e9f444251d7d665c52820133d35a3f5 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 11:09:22 +0200 Subject: [PATCH 28/45] [ci] fail if jdk could not be set --- .azure/scripts/jdk.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.azure/scripts/jdk.yml b/.azure/scripts/jdk.yml index 614ae6b47..39f3e329e 100644 --- a/.azure/scripts/jdk.yml +++ b/.azure/scripts/jdk.yml @@ -9,3 +9,6 @@ steps: versionSpec: ${{ parameters.version }} jdkArchitectureOption: 'x64' jdkSourceOption: 'PreInstalled' + - bash: exit 1 + displayName: JDK ${{ parameters.version }} could not be set. + condition: eq(variables['Agent.JobStatus'], 'SucceededWithIssues') From 674312c98a3cf094271f369568f25adb75e23b2b Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 11:09:32 +0200 Subject: [PATCH 29/45] minor --- .azure/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure/build.yml b/.azure/build.yml index c5f8473c7..1ebe24559 100644 --- a/.azure/build.yml +++ b/.azure/build.yml @@ -15,7 +15,7 @@ trigger: - test/* variables: -# indicate whether the testsuite should skip long running tests or not. +# indicate whether the testsuite should skip long-running tests or not. - name: jpypetest.fast value: 'false' From ce75eea668b848f7e514e753c4cfd73cf96ef04d Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 11:19:20 +0200 Subject: [PATCH 30/45] replace impl test for windows jvmfinder --- jpype/_jvmfinder.py | 3 ++- test/jpypetest/test_jvmfinder.py | 14 ++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/jpype/_jvmfinder.py b/jpype/_jvmfinder.py index f19c1aa36..071fb6365 100644 --- a/jpype/_jvmfinder.py +++ b/jpype/_jvmfinder.py @@ -382,7 +382,8 @@ def __init__(self): def check(self, jvm): _checkJVMArch(jvm) - def _get_from_registry(self): + @staticmethod + def _get_from_registry(): """ Retrieves the path to the default Java installation stored in the Windows registry diff --git a/test/jpypetest/test_jvmfinder.py b/test/jpypetest/test_jvmfinder.py index 4e16a7b2e..d833b4582 100644 --- a/test/jpypetest/test_jvmfinder.py +++ b/test/jpypetest/test_jvmfinder.py @@ -16,8 +16,8 @@ # # ***************************************************************************** # part of JPype1; author Martin K. Scherer; 2014 - - +import pathlib +import sys import unittest from unittest import mock import common @@ -175,14 +175,12 @@ def testCheckArch(self): self.assertRaises(JVMNotSupportedException): jpype._jvmfinder._checkJVMArch('path', 2**32) + @unittest.skipIf(sys.platform != "win", "only on windows") def testWindowsRegistry(self): finder = jpype._jvmfinder.WindowsJVMFinder() - with mock.patch("jpype._jvmfinder.winreg") as winregmock: - winregmock.QueryValueEx.return_value = ('success', '') - self.assertEqual(finder._get_from_registry(), 'success') - winregmock.OpenKey.side_effect = OSError() - self.assertEqual(finder._get_from_registry(), None) - + jvm_home = pathlib.Path(finder.get_jvm_path()) + assert jvm_home.exists() + assert jvm_home.is_dir() if __name__ == '__main__': unittest.main() From 155abab3dcd12833df2a8f7b43f1abdbb7cf40bc Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 11:27:00 +0200 Subject: [PATCH 31/45] modernize jvmfinder a bit --- jpype/_jvmfinder.py | 84 ++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 50 deletions(-) diff --git a/jpype/_jvmfinder.py b/jpype/_jvmfinder.py index 071fb6365..eda6af74c 100644 --- a/jpype/_jvmfinder.py +++ b/jpype/_jvmfinder.py @@ -21,9 +21,9 @@ import sys __all__ = ['getDefaultJVMPath', - 'JVMNotFoundException', 'JVMNotSupportedException'] - - + 'get_default_jvm_path', + 'JVMNotFoundException', + 'JVMNotSupportedException'] class JVMNotFoundException(ValueError): @@ -47,7 +47,7 @@ class JVMNotSupportedException(ValueError): """ -def getDefaultJVMPath(): +def getDefaultJVMPath() -> str: """ Retrieves the path to the default or first found JVM library @@ -72,21 +72,17 @@ def getDefaultJVMPath(): get_default_jvm_path = getDefaultJVMPath -class JVMFinder(object): +class JVMFinder: """ JVM library finder base class """ + # Library file name + _libfile = "libjvm.so" - def __init__(self): - """ - Sets up members - """ - # Library file name - self._libfile = "libjvm.so" - - # Predefined locations - self._locations = ("/usr/lib/jvm", "/usr/java") + # Predefined locations + _locations = ("/usr/lib/jvm", "/usr/java") + def __init__(self): # Search methods self._methods = (self._get_from_java_home, self._get_from_known_locations) @@ -128,7 +124,8 @@ def find_libjvm(self, java_home): "environment variable is pointing " "to correct installation.") - def find_possible_homes(self, parents): + @staticmethod + def find_possible_homes(parents): """ Generator that looks for the first-level children folders that could be Java installations, according to their name @@ -251,21 +248,17 @@ class LinuxJVMFinder(JVMFinder): Linux JVM library finder class """ - def __init__(self): - """ - Sets up members - """ - # Call the parent constructor - JVMFinder.__init__(self) + # Java bin file + _java = "/usr/bin/java" - # Java bin file - self._java = "/usr/bin/java" + # Library file name + _libfile = "libjvm.so" - # Library file name - self._libfile = "libjvm.so" + # Predefined locations + _locations = ("/usr/lib/jvm", "/usr/java", "/opt/sun") - # Predefined locations - self._locations = ("/usr/lib/jvm", "/usr/java", "/opt/sun") + def __init__(self): + super().__init__() # Search methods self._methods = (self._get_from_java_home, @@ -294,23 +287,20 @@ class DarwinJVMFinder(LinuxJVMFinder): """ Mac OS X JVM library finder class """ + # Library file name + _libfile = "libjli.dylib" + # Predefined locations + _locations = ('/Library/Java/JavaVirtualMachines',) def __init__(self): """ Sets up members """ - # Call the parent constructor - LinuxJVMFinder.__init__(self) - - # Library file name - self._libfile = "libjli.dylib" + super().__init__() self._methods = list(self._methods) self._methods.append(self._javahome_binary) - # Predefined locations - self._locations = ('/Library/Java/JavaVirtualMachines',) - def _javahome_binary(self): """ for osx > 10.5 we have the nice util /usr/libexec/java_home available. Invoke it and @@ -321,7 +311,8 @@ def _javahome_binary(self): from packaging.version import Version current = Version(platform.mac_ver()[0][:4]) - if current >= Version('10.6') and current < Version('10.9'): + # TODO: check if the java_home tool is still available and fix the version boundaries. + if Version('10.6') <= current: #< Version('10.9'): return subprocess.check_output( ['/usr/libexec/java_home']).strip() @@ -356,25 +347,18 @@ def _checkJVMArch(jvmPath, maxsize=sys.maxsize): raise JVMNotSupportedException("Unable to determine JVM Type") -reg_keys = [r"SOFTWARE\JavaSoft\Java Runtime Environment", - r"SOFTWARE\JavaSoft\JRE", - ] - - class WindowsJVMFinder(JVMFinder): """ Windows JVM library finder class """ + reg_keys = [r"SOFTWARE\JavaSoft\Java Runtime Environment", + r"SOFTWARE\JavaSoft\JRE", + ] + # Library file name + _libfile = "jvm.dll" def __init__(self): - """ - Sets up members - """ - # Call the parent constructor - JVMFinder.__init__(self) - - # Library file name - self._libfile = "jvm.dll" + super().__init__() # Search methods self._methods = (self._get_from_java_home, self._get_from_registry) @@ -395,7 +379,7 @@ def _get_from_registry(): except ImportError: return None - for location in reg_keys: + for location in WindowsJVMFinder.reg_keys: try: jreKey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, location) cv = winreg.QueryValueEx(jreKey, "CurrentVersion") From 27557f305c282eadac0ea6d0e03d7cb326531ab7 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 11:49:48 +0200 Subject: [PATCH 32/45] [ci] condition does not work... another shot --- .azure/scripts/jdk.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.azure/scripts/jdk.yml b/.azure/scripts/jdk.yml index 39f3e329e..fcdaa327d 100644 --- a/.azure/scripts/jdk.yml +++ b/.azure/scripts/jdk.yml @@ -9,6 +9,11 @@ steps: versionSpec: ${{ parameters.version }} jdkArchitectureOption: 'x64' jdkSourceOption: 'PreInstalled' - - bash: exit 1 +# FIXME: we'd want to stop the execution of the whole pipeline, if the JDK could not be set. +# - bash: exit 1 +# displayName: JDK ${{ parameters.version }} could not be set. +# condition: eq(variables['Agent.JobStatus'], 'SucceededWithIssues') + - bash: | + echo AGENT_JOBSTATUS = $AGENT_JOBSTATUS + if [[ "$AGENT_JOBSTATUS" == "SucceededWithIssues" ]]; then exit 1; fi displayName: JDK ${{ parameters.version }} could not be set. - condition: eq(variables['Agent.JobStatus'], 'SucceededWithIssues') From 529c5df490553fd97a526711e2739c57b7d84e22 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 11:55:48 +0200 Subject: [PATCH 33/45] try to switch to PublishCodeCoverageResults version 2 --- .azure/scripts/coverage.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.azure/scripts/coverage.yml b/.azure/scripts/coverage.yml index 77c8ae1d8..2f68c2b35 100644 --- a/.azure/scripts/coverage.yml +++ b/.azure/scripts/coverage.yml @@ -28,18 +28,18 @@ steps: bash <(curl -s https://codecov.io/bash) -f coverage.xml -f coverage_py.xml -f coverage_java.xml -X gcov displayName: 'Report' -- task: PublishCodeCoverageResults@1 +- task: PublishCodeCoverageResults@2 inputs: codeCoverageTool: 'JaCoCo' summaryFileLocation: coverage_java.xml pathToSources: native/java -- task: PublishCodeCoverageResults@1 +- task: PublishCodeCoverageResults@2 inputs: codeCoverageTool: 'cobertura' summaryFileLocation: coverage.xml -- task: PublishCodeCoverageResults@1 +- task: PublishCodeCoverageResults@2 inputs: codeCoverageTool: 'cobertura' summaryFileLocation: coverage_py.xml From 640c65f20b144d7189309d1be91ce06d67ceb17e Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Tue, 20 Aug 2024 12:10:43 +0200 Subject: [PATCH 34/45] proper display name --- .azure/scripts/jdk.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.azure/scripts/jdk.yml b/.azure/scripts/jdk.yml index fcdaa327d..25121dfc2 100644 --- a/.azure/scripts/jdk.yml +++ b/.azure/scripts/jdk.yml @@ -9,11 +9,7 @@ steps: versionSpec: ${{ parameters.version }} jdkArchitectureOption: 'x64' jdkSourceOption: 'PreInstalled' -# FIXME: we'd want to stop the execution of the whole pipeline, if the JDK could not be set. -# - bash: exit 1 -# displayName: JDK ${{ parameters.version }} could not be set. -# condition: eq(variables['Agent.JobStatus'], 'SucceededWithIssues') - bash: | echo AGENT_JOBSTATUS = $AGENT_JOBSTATUS if [[ "$AGENT_JOBSTATUS" == "SucceededWithIssues" ]]; then exit 1; fi - displayName: JDK ${{ parameters.version }} could not be set. + displayName: JDK ${{ parameters.version }} set as JAVA_HOME. From 5b3d65bbdabf99c84dda8da49c30cdb96d36e05e Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 21 Aug 2024 01:36:27 +0200 Subject: [PATCH 35/45] minor --- jpype/_jvmfinder.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/jpype/_jvmfinder.py b/jpype/_jvmfinder.py index eda6af74c..1217b9b55 100644 --- a/jpype/_jvmfinder.py +++ b/jpype/_jvmfinder.py @@ -25,9 +25,11 @@ 'JVMNotFoundException', 'JVMNotSupportedException'] +from typing import Sequence + class JVMNotFoundException(ValueError): - """ Exception raised when no JVM was found in the search path. + """Exception raised when no JVM was found in the search path. This exception is raised when the all of the places searched did not contain a JVM. The locations searched depend on the machine architecture. @@ -37,7 +39,7 @@ class JVMNotFoundException(ValueError): class JVMNotSupportedException(ValueError): - """ Exception raised when the JVM is not supported. + """Exception raised when the JVM is not supported. This exception is raised after a search found a valid Java home directory was found, but the JVM shared library found is not supported. Typically @@ -48,8 +50,7 @@ class JVMNotSupportedException(ValueError): def getDefaultJVMPath() -> str: - """ - Retrieves the path to the default or first found JVM library + """Retrieves the path to the default or first found JVM library. Returns: The path to the JVM shared library file @@ -73,14 +74,12 @@ def getDefaultJVMPath() -> str: class JVMFinder: - """ - JVM library finder base class - """ + """JVM library finder base class.""" # Library file name - _libfile = "libjvm.so" + _libfile: str = "libjvm.so" # Predefined locations - _locations = ("/usr/lib/jvm", "/usr/java") + _locations: Sequence = ("/usr/lib/jvm", "/usr/java") def __init__(self): # Search methods @@ -88,12 +87,10 @@ def __init__(self): self._get_from_known_locations) def find_libjvm(self, java_home): - """ - Recursively looks for the given file + """Recursively looks for the given file. Parameters: java_home(str): A Java home folder - filename(str): filename: Name of the file to find Returns: The first found file path, or None @@ -244,9 +241,7 @@ def _get_from_known_locations(self): class LinuxJVMFinder(JVMFinder): - """ - Linux JVM library finder class - """ + """Linux JVM library finder class.""" # Java bin file _java = "/usr/bin/java" From 20f82271bbe57e692a64e6f97cfcecba29413b63 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 21 Aug 2024 01:36:36 +0200 Subject: [PATCH 36/45] minor2 --- test/jpypetest/common.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/jpypetest/common.py b/test/jpypetest/common.py index 05e00e1e2..9531c615f 100644 --- a/test/jpypetest/common.py +++ b/test/jpypetest/common.py @@ -21,7 +21,6 @@ import jpype import logging from os import path -import sys import unittest # Extensively used as common.unittest. CLASSPATH = None @@ -143,7 +142,3 @@ def assertElementsAlmostEqual(self, a, b): def useEqualityFunc(self, func): return UseFunc(self, func, 'assertEqual') - - -if __name__ == '__main__': - unittest.main() From 146509d8566ae8c8db4048329a117df9ab03461e Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 21 Aug 2024 01:37:14 +0200 Subject: [PATCH 37/45] removed obsolete tests (nobody is going to fix or rewrite) --- test/jpypetest/test_jvmfinder.py | 72 +++++--------------------------- 1 file changed, 10 insertions(+), 62 deletions(-) diff --git a/test/jpypetest/test_jvmfinder.py b/test/jpypetest/test_jvmfinder.py index d833b4582..8c1b3c34d 100644 --- a/test/jpypetest/test_jvmfinder.py +++ b/test/jpypetest/test_jvmfinder.py @@ -16,15 +16,15 @@ # # ***************************************************************************** # part of JPype1; author Martin K. Scherer; 2014 +# from unittest import mock +import os import pathlib import sys import unittest from unittest import mock -import common -import os -import jpype._jvmfinder -from jpype._jvmfinder import * +from jpype._jvmfinder import (LinuxJVMFinder, JVMNotSupportedException, DarwinJVMFinder, + WindowsJVMFinder) class JVMFinderTest(unittest.TestCase): @@ -52,7 +52,7 @@ def test_find_libjvm(self): # contains broken and working jvms mockwalk.return_value = walk_fake - finder = jpype._jvmfinder.LinuxJVMFinder() + finder = LinuxJVMFinder() p = finder.find_libjvm('arbitrary java home') self.assertEqual( p, os.path.join('jre/lib/amd64/server', 'libjvm.so'), 'wrong jvm returned') @@ -62,7 +62,7 @@ def test_find_libjvm(self): walk_fake[-1] = ((), (), (),) mockwalk.return_value = walk_fake - finder = jpype._jvmfinder.LinuxJVMFinder() + finder = LinuxJVMFinder() with self.assertRaises(JVMNotSupportedException) as context: finder.find_libjvm('arbitrary java home') @@ -81,7 +81,7 @@ def test_get_from_bin(self, mock_real_path, mock_path_exists, mock_os_walk): mock_path_exists.return_value = True mock_real_path.return_value = '/usr/lib/jvm/java-6-openjdk-amd64/bin/java' - finder = jpype._jvmfinder.LinuxJVMFinder() + finder = LinuxJVMFinder() p = finder._get_from_bin() self.assertEqual( @@ -94,7 +94,7 @@ def testDarwinBinary(self, mock_mac_ver): expected = '/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home\n' - finder = jpype._jvmfinder.DarwinJVMFinder() + finder = DarwinJVMFinder() # fake check_output with mock.patch('subprocess.check_output') as mock_checkoutput: @@ -107,29 +107,8 @@ def testDarwinBinary(self, mock_mac_ver): p = finder._javahome_binary() self.assertEqual(p, None) - # FIXME this is testing the details of the implementation rather than the results. - # it is included only for coverage purposes. Revise this to be a more meaningful test - # next time it breaks. - # FIXME this test does passes locally but not in the CI. Disabling for now. - @common.unittest.skip # type: ignore - def testPlatform(self): - with mock.patch('jpype._jvmfinder.sys') as mocksys, mock.patch('jpype._jvmfinder.WindowsJVMFinder') as finder: - mocksys.platform = 'win32' - jpype._jvmfinder.getDefaultJVMPath() - self.assertIn(finder().get_jvm_path, finder.mock_calls) - - with mock.patch('jpype._jvmfinder.sys') as mocksys, mock.patch('jpype._jvmfinder.LinuxJVMFinder') as finder: - mocksys.platform = 'linux' - getDefaultJVMPath() - self.assertIn(finder().get_jvm_path, finder.mock_calls) - - with mock.patch('jpype._jvmfinder.sys') as mocksys, mock.patch('jpype._jvmfinder.DarwinJVMFinder') as finder: - mocksys.platform = 'darwin' - getDefaultJVMPath() - self.assertIn(finder().get_jvm_path, finder.mock_calls) - def testLinuxGetFromBin(self): - finder = jpype._jvmfinder.LinuxJVMFinder() + finder = LinuxJVMFinder() def f(s): return s @@ -144,40 +123,9 @@ def f(s): self.assertEqual( pathmock.dirname.mock_calls[0][1], (finder._java,)) - # FIXME this test is faking files using the mock system. Replace it with stub - # files so that we have a more accurate test rather than just testing the implementation. - # FIXME this fails in the CI but works locally. Disabling this for now. - @common.unittest.skip # type: ignore - def testCheckArch(self): - import struct - with mock.patch("builtins.open", mock.mock_open(read_data="data")) as mock_file, \ - self.assertRaises(JVMNotSupportedException): - jpype._jvmfinder._checkJVMArch('path', 2**32) - - data = struct.pack(' Date: Wed, 21 Aug 2024 01:37:32 +0200 Subject: [PATCH 38/45] added java version fixture --- test/jpypetest/conftest.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/jpypetest/conftest.py b/test/jpypetest/conftest.py index 2661b9062..b77f02072 100755 --- a/test/jpypetest/conftest.py +++ b/test/jpypetest/conftest.py @@ -16,6 +16,7 @@ # # ***************************************************************************** import pytest + import common @@ -43,3 +44,13 @@ def common_opts(request): request.cls._convertStrings = request.config.getoption("--convertStrings") request.cls._jacoco = request.config.getoption("--jacoco") request.cls._checkjni = request.config.getoption("--checkjni") + + +@pytest.fixture(scope="session", autouse=True) +def java_version(request): + import subprocess, sys + java_version = subprocess.check_output([sys.executable, "-c", + "import jpype; jpype.startJVM(); print(jpype.java.lang.System.getProperty('java.version'))"]) + print("java_version", java_version) + request._java_version = java_version[0] + yield java_version \ No newline at end of file From b3a480238833cbea2fd62ac7f7f2c0b05ed31169 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Wed, 21 Aug 2024 12:57:25 +0200 Subject: [PATCH 39/45] skip --- test/jpypetest/conftest.py | 16 +++++++++------- test/jpypetest/test_sql_sqlite.py | 20 +++++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/test/jpypetest/conftest.py b/test/jpypetest/conftest.py index b77f02072..051cff752 100755 --- a/test/jpypetest/conftest.py +++ b/test/jpypetest/conftest.py @@ -15,6 +15,8 @@ # See NOTICE file for details. # # ***************************************************************************** +from functools import cache + import pytest import common @@ -46,11 +48,11 @@ def common_opts(request): request.cls._checkjni = request.config.getoption("--checkjni") -@pytest.fixture(scope="session", autouse=True) -def java_version(request): +#@pytest.fixture(scope="session", autouse=True) +@cache +def java_version(): + print("hi from java_version()") import subprocess, sys - java_version = subprocess.check_output([sys.executable, "-c", - "import jpype; jpype.startJVM(); print(jpype.java.lang.System.getProperty('java.version'))"]) - print("java_version", java_version) - request._java_version = java_version[0] - yield java_version \ No newline at end of file + java_version = str(subprocess.check_output([sys.executable, "-c", + "import jpype; jpype.startJVM(); print(jpype.java.lang.System.getProperty('java.version'))"])) + return java_version.split(".") diff --git a/test/jpypetest/test_sql_sqlite.py b/test/jpypetest/test_sql_sqlite.py index 530987037..f845f75c9 100644 --- a/test/jpypetest/test_sql_sqlite.py +++ b/test/jpypetest/test_sql_sqlite.py @@ -3,11 +3,14 @@ import datetime import decimal import threading +from unittest import SkipTest + +import pytest import common import jpype import jpype.dbapi2 as dbapi2 -from jpype import java, isJVMStarted +from jpype import java from jpype.types import * try: @@ -18,12 +21,17 @@ db_name = "jdbc:sqlite::memory:" +def setUpModule(module): + from conftest import java_version + version = java_version() + print("setup module: jdk version", version) + if version[0] == "8": + pytest.skip("jdk8 unsupported", allow_module_level=True) -if isJVMStarted(): - java_version = str(jpype.java.lang.System.getProperty("java.version")).split(".") + # raise common.unittest.SkipTest("SQLite unsupported for JDK 8.") - if java_version[0] == "8":# and sys.platform == "win": - raise common.unittest.SkipTest("sqlite unsupported on this config.") +#def setUpModule(java_version): +# print("setuppppp", setUpModule.__name__) class ConnectTestCase(common.JPypeTestCase): @@ -32,8 +40,6 @@ def setUp(self): if common.fast: raise common.unittest.SkipTest("fast") - - def testConnect(self): cx = dbapi2.connect(db_name) self.assertIsInstance(cx, dbapi2.Connection) From d171b5008720a32b268be4d8402cabc5aa83abbc Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Thu, 22 Aug 2024 03:54:11 +0200 Subject: [PATCH 40/45] refactor --- test/jpypetest/common.py | 13 +++++++++++++ test/jpypetest/conftest.py | 11 ----------- test/jpypetest/test_sql_sqlite.py | 4 ++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/test/jpypetest/common.py b/test/jpypetest/common.py index 9531c615f..6b987c6f9 100644 --- a/test/jpypetest/common.py +++ b/test/jpypetest/common.py @@ -15,6 +15,7 @@ # See NOTICE file for details. # # ***************************************************************************** +from functools import lru_cache import pytest import _jpype @@ -142,3 +143,15 @@ def assertElementsAlmostEqual(self, a, b): def useEqualityFunc(self, func): return UseFunc(self, func, 'assertEqual') + + +@lru_cache(1) +def java_version(): + import subprocess + import sys + java_version = str(subprocess.check_output([sys.executable, "-c", + "import jpype; jpype.startJVM(); " + "print(jpype.java.lang.System.getProperty('java.version'))"]), + encoding='ascii') + print("java_version:", java_version) + return tuple(map(int, java_version.split("."))) diff --git a/test/jpypetest/conftest.py b/test/jpypetest/conftest.py index 051cff752..e613f87d9 100755 --- a/test/jpypetest/conftest.py +++ b/test/jpypetest/conftest.py @@ -15,7 +15,6 @@ # See NOTICE file for details. # # ***************************************************************************** -from functools import cache import pytest @@ -46,13 +45,3 @@ def common_opts(request): request.cls._convertStrings = request.config.getoption("--convertStrings") request.cls._jacoco = request.config.getoption("--jacoco") request.cls._checkjni = request.config.getoption("--checkjni") - - -#@pytest.fixture(scope="session", autouse=True) -@cache -def java_version(): - print("hi from java_version()") - import subprocess, sys - java_version = str(subprocess.check_output([sys.executable, "-c", - "import jpype; jpype.startJVM(); print(jpype.java.lang.System.getProperty('java.version'))"])) - return java_version.split(".") diff --git a/test/jpypetest/test_sql_sqlite.py b/test/jpypetest/test_sql_sqlite.py index f845f75c9..c485f680e 100644 --- a/test/jpypetest/test_sql_sqlite.py +++ b/test/jpypetest/test_sql_sqlite.py @@ -22,10 +22,10 @@ db_name = "jdbc:sqlite::memory:" def setUpModule(module): - from conftest import java_version + from common import java_version version = java_version() print("setup module: jdk version", version) - if version[0] == "8": + if version[0] == 8: pytest.skip("jdk8 unsupported", allow_module_level=True) # raise common.unittest.SkipTest("SQLite unsupported for JDK 8.") From 5f474f0ca2ed919c081844ce733f0b35c3d986e8 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Thu, 22 Aug 2024 04:05:55 +0200 Subject: [PATCH 41/45] fix version check --- test/jpypetest/test_sql_sqlite.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/test/jpypetest/test_sql_sqlite.py b/test/jpypetest/test_sql_sqlite.py index c485f680e..663028d44 100644 --- a/test/jpypetest/test_sql_sqlite.py +++ b/test/jpypetest/test_sql_sqlite.py @@ -24,15 +24,9 @@ def setUpModule(module): from common import java_version version = java_version() - print("setup module: jdk version", version) - if version[0] == 8: + if version[0] == 1 and version[1] == 8: pytest.skip("jdk8 unsupported", allow_module_level=True) - # raise common.unittest.SkipTest("SQLite unsupported for JDK 8.") - -#def setUpModule(java_version): -# print("setuppppp", setUpModule.__name__) - class ConnectTestCase(common.JPypeTestCase): def setUp(self): From 29838e8c7bff34d974bf5cb7edca154342eb344e Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Thu, 22 Aug 2024 04:11:37 +0200 Subject: [PATCH 42/45] cleanup --- test/jpypetest/common.py | 1 - test/jpypetest/test_sql_h2.py | 9 +++++++++ test/jpypetest/test_sql_hsqldb.py | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/test/jpypetest/common.py b/test/jpypetest/common.py index 6b987c6f9..8f7d45b2d 100644 --- a/test/jpypetest/common.py +++ b/test/jpypetest/common.py @@ -153,5 +153,4 @@ def java_version(): "import jpype; jpype.startJVM(); " "print(jpype.java.lang.System.getProperty('java.version'))"]), encoding='ascii') - print("java_version:", java_version) return tuple(map(int, java_version.split("."))) diff --git a/test/jpypetest/test_sql_h2.py b/test/jpypetest/test_sql_h2.py index e8471ca73..9c984cdb8 100644 --- a/test/jpypetest/test_sql_h2.py +++ b/test/jpypetest/test_sql_h2.py @@ -1,5 +1,7 @@ # This file is Public Domain and may be used without restrictions, # because nobody should have to waste their lives typing this again. +import pytest + import jpype from jpype.types import * from jpype import java @@ -19,6 +21,13 @@ db_name = "jdbc:h2:mem:testdb" +def setUpModule(module): + from common import java_version + version = java_version() + if version[0] == 1 and version[1] == 8: + pytest.skip("jdk8 unsupported", allow_module_level=True) + + class ConnectTestCase(common.JPypeTestCase): def setUp(self): diff --git a/test/jpypetest/test_sql_hsqldb.py b/test/jpypetest/test_sql_hsqldb.py index 231a3a8a0..c51950785 100644 --- a/test/jpypetest/test_sql_hsqldb.py +++ b/test/jpypetest/test_sql_hsqldb.py @@ -24,6 +24,14 @@ #first = "jdbc:derby:memory:myDb;create=True" +def setUpModule(module): + from common import java_version + import pytest + version = java_version() + if version[0] == 1 and version[1] == 8: + pytest.skip("jdk8 unsupported", allow_module_level=True) + + @common.unittest.skipUnless(zlib, "requires zlib") class ConnectTestCase(common.JPypeTestCase): def setUp(self): From 0e18bce46431725503fd728457149e206879c3dd Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Thu, 22 Aug 2024 04:16:11 +0200 Subject: [PATCH 43/45] minor --- .azure/scripts/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.azure/scripts/test.yml b/.azure/scripts/test.yml index 3535cf022..4a2e3df39 100644 --- a/.azure/scripts/test.yml +++ b/.azure/scripts/test.yml @@ -25,12 +25,12 @@ steps: - script: | python -m pytest -v --junit-xml=build/test/test.xml test/jpypetest --checkjni - displayName: 'Test JDK $(jdk.version)' + displayName: 'Test JDK $(jdk.version) and Python $(python.version)' condition: eq(variables['jpypetest.fast'], 'false') - script: | python -m pytest -v --junit-xml=build/test/test.xml test/jpypetest --checkjni --fast - displayName: 'Test JDK $(jdk.version) (fast)' + displayName: 'Test JDK $(jdk.version) and Python $(python.version) (fast)' condition: eq(variables['jpypetest.fast'], 'true') # presence of jpype/ seems to confuse entry_points so `cd` elsewhere From 80769f6746cbaab3ece789bfcc4e1ab68b6a482f Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Thu, 22 Aug 2024 04:21:55 +0200 Subject: [PATCH 44/45] minor2 --- test/jpypetest/test_sql_sqlite.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/jpypetest/test_sql_sqlite.py b/test/jpypetest/test_sql_sqlite.py index 663028d44..2de96715c 100644 --- a/test/jpypetest/test_sql_sqlite.py +++ b/test/jpypetest/test_sql_sqlite.py @@ -3,7 +3,6 @@ import datetime import decimal import threading -from unittest import SkipTest import pytest @@ -11,7 +10,7 @@ import jpype import jpype.dbapi2 as dbapi2 from jpype import java -from jpype.types import * +from jpype.types import JArray, JByte try: import zlib From 69bbe2e4bee8670c3005f6646820344ee0aed4dd Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Thu, 22 Aug 2024 04:48:11 +0200 Subject: [PATCH 45/45] fix mypy --- jpype/_jvmfinder.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jpype/_jvmfinder.py b/jpype/_jvmfinder.py index 1217b9b55..dcf423345 100644 --- a/jpype/_jvmfinder.py +++ b/jpype/_jvmfinder.py @@ -25,7 +25,7 @@ 'JVMNotFoundException', 'JVMNotSupportedException'] -from typing import Sequence +from typing import Sequence, Tuple class JVMNotFoundException(ValueError): @@ -79,7 +79,7 @@ class JVMFinder: _libfile: str = "libjvm.so" # Predefined locations - _locations: Sequence = ("/usr/lib/jvm", "/usr/java") + _locations: Tuple[str, ...] = ("/usr/lib/jvm", "/usr/java") def __init__(self): # Search methods @@ -285,7 +285,7 @@ class DarwinJVMFinder(LinuxJVMFinder): # Library file name _libfile = "libjli.dylib" # Predefined locations - _locations = ('/Library/Java/JavaVirtualMachines',) + _locations = ('/Library/Java/JavaVirtualMachines',) # type: ignore def __init__(self): """