From 37cca5dbd8b74b4b4e9f802e3ca603355780e35d Mon Sep 17 00:00:00 2001 From: Chip Kent <5250374+chipkent@users.noreply.github.com> Date: Wed, 13 Dec 2023 13:45:04 -0700 Subject: [PATCH 1/8] Allow JAVA_HOME values to contain libexec and not lib. --- jpyutil.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jpyutil.py b/jpyutil.py index c66223d7..0d088a69 100644 --- a/jpyutil.py +++ b/jpyutil.py @@ -140,7 +140,7 @@ def find_jdk_home_dir(): jdk_home_dir = os.environ.get(name, None) if jdk_home_dir \ and os.path.exists(os.path.join(jdk_home_dir, 'include')) \ - and os.path.exists(os.path.join(jdk_home_dir, 'lib')): + and (os.path.exists(os.path.join(jdk_home_dir, 'lib') or os.path.exists(os.path.join(jdk_home_dir, 'libexec'))): return jdk_home_dir logger.debug('Checking Maven for JAVA_HOME...') try: From c2b40534941ceb55de153d4b286a67e12794ad36 Mon Sep 17 00:00:00 2001 From: Chip Kent <5250374+chipkent@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:08:02 -0700 Subject: [PATCH 2/8] Fixed bug --- jpyutil.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jpyutil.py b/jpyutil.py index 0d088a69..95145963 100644 --- a/jpyutil.py +++ b/jpyutil.py @@ -140,7 +140,7 @@ def find_jdk_home_dir(): jdk_home_dir = os.environ.get(name, None) if jdk_home_dir \ and os.path.exists(os.path.join(jdk_home_dir, 'include')) \ - and (os.path.exists(os.path.join(jdk_home_dir, 'lib') or os.path.exists(os.path.join(jdk_home_dir, 'libexec'))): + and (os.path.exists(os.path.join(jdk_home_dir, 'lib')) or os.path.exists(os.path.join(jdk_home_dir, 'libexec'))): return jdk_home_dir logger.debug('Checking Maven for JAVA_HOME...') try: From 2fb1493d47ea40694abb9681d15b02709d6b3bd7 Mon Sep 17 00:00:00 2001 From: Chip Kent <5250374+chipkent@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:14:00 -0700 Subject: [PATCH 3/8] Python 3.12 build --- .github/env/Linux/requirements.txt | 1 + .github/env/Windows/requirements.txt | 1 + .github/env/macOS/requirements.txt | 1 + .github/workflows/build.yml | 3 +++ 4 files changed, 6 insertions(+) diff --git a/.github/env/Linux/requirements.txt b/.github/env/Linux/requirements.txt index 06c8c463..a0d07ab7 100644 --- a/.github/env/Linux/requirements.txt +++ b/.github/env/Linux/requirements.txt @@ -1,3 +1,4 @@ +setuptools wheel auditwheel patchelf diff --git a/.github/env/Windows/requirements.txt b/.github/env/Windows/requirements.txt index 2309722a..0a8547bc 100644 --- a/.github/env/Windows/requirements.txt +++ b/.github/env/Windows/requirements.txt @@ -1 +1,2 @@ +setuptools wheel diff --git a/.github/env/macOS/requirements.txt b/.github/env/macOS/requirements.txt index 2309722a..0a8547bc 100644 --- a/.github/env/macOS/requirements.txt +++ b/.github/env/macOS/requirements.txt @@ -1 +1,2 @@ +setuptools wheel diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 41a3d359..b8685b18 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -50,18 +50,21 @@ jobs: - { machine: 'ubuntu-20.04', python: '3.9', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/Linux/bdist-wheel.sh' } - { machine: 'ubuntu-20.04', python: '3.10', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/Linux/bdist-wheel.sh' } - { machine: 'ubuntu-20.04', python: '3.11', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/Linux/bdist-wheel.sh' } + - { machine: 'ubuntu-20.04', python: '3.12', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/Linux/bdist-wheel.sh' } - { machine: 'windows-2022', python: '3.6', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.\.github\env\Windows\bdist-wheel.ps1' } - { machine: 'windows-2022', python: '3.7', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.\.github\env\Windows\bdist-wheel.ps1' } - { machine: 'windows-2022', python: '3.8', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.\.github\env\Windows\bdist-wheel.ps1' } - { machine: 'windows-2022', python: '3.9', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.\.github\env\Windows\bdist-wheel.ps1' } - { machine: 'windows-2022', python: '3.10', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.\.github\env\Windows\bdist-wheel.ps1' } - { machine: 'windows-2022', python: '3.11', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.\.github\env\Windows\bdist-wheel.ps1' } + - { machine: 'windows-2022', python: '3.12', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.\.github\env\Windows\bdist-wheel.ps1' } - { machine: 'macos-11', python: '3.6', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/macOS/bdist-wheel.sh' } - { machine: 'macos-11', python: '3.7', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/macOS/bdist-wheel.sh' } - { machine: 'macos-11', python: '3.8', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/macOS/bdist-wheel.sh' } - { machine: 'macos-11', python: '3.9', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/macOS/bdist-wheel.sh' } - { machine: 'macos-11', python: '3.10', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/macOS/bdist-wheel.sh' } - { machine: 'macos-11', python: '3.11', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/macOS/bdist-wheel.sh' } + - { machine: 'macos-11', python: '3.12', pythonArchitecture: 'x64', arch: 'amd64', cmd: '.github/env/macOS/bdist-wheel.sh' } # Add M1 powered runners when available # https://github.com/jpy-consortium/jpy/issues/110 From 4fa60201198c6e7ccf37828c1aeecae1b807ff2c Mon Sep 17 00:00:00 2001 From: Chip Kent <5250374+chipkent@users.noreply.github.com> Date: Wed, 13 Dec 2023 14:42:55 -0700 Subject: [PATCH 4/8] Remove possibly unnecessary JAVA_HOME checks and improve logging. --- jpyutil.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/jpyutil.py b/jpyutil.py index 95145963..520d51cf 100644 --- a/jpyutil.py +++ b/jpyutil.py @@ -138,9 +138,8 @@ def find_jdk_home_dir(): """ for name in JDK_HOME_VARS: jdk_home_dir = os.environ.get(name, None) - if jdk_home_dir \ - and os.path.exists(os.path.join(jdk_home_dir, 'include')) \ - and (os.path.exists(os.path.join(jdk_home_dir, 'lib')) or os.path.exists(os.path.join(jdk_home_dir, 'libexec'))): + if jdk_home_dir: + logger.debug(f'JAVA_HOME set by environment variable to {jdk_home_dir}') return jdk_home_dir logger.debug('Checking Maven for JAVA_HOME...') try: @@ -152,7 +151,9 @@ def find_jdk_home_dir(): if part.startswith('Java home:'): path = part.split(':')[1].strip() if path.endswith('jre'): - return path[0:-3] + java_home = path[0:-3] + logger.debug(f'JAVA_HOME set by maven to {java_home}') + return java_home except Exception: # maven probably isn't installed or not on PATH From 975df0d1d924de61edadce11554d7e521d85b9ff Mon Sep 17 00:00:00 2001 From: Chip Kent Date: Wed, 13 Dec 2023 15:25:50 -0700 Subject: [PATCH 5/8] Recursively find the directory containing the relevant JDK files. --- jpyutil.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/jpyutil.py b/jpyutil.py index 520d51cf..9d23b396 100644 --- a/jpyutil.py +++ b/jpyutil.py @@ -136,11 +136,37 @@ def find_jdk_home_dir(): dedicated environment variables. :return: pathname if found, else None """ + + def is_jdk_dir(path): + rst = os.path.exists(os.path.join(path, 'include')) and os.path.exists(os.path.join(path, 'lib')) + logger.debug(f'Checking {path} for JDK...: {"yes" if rst else "no"}') + return rst + + def walk_to_jdk(path): + if is_jdk_dir(path): + return path + + for root, dir_names, file_names in os.walk(path): + for d in dir_names: + p = os.path.join(path, d) + rst = walk_to_jdk(p) + + if rst: + return rst + + return None + for name in JDK_HOME_VARS: jdk_home_dir = os.environ.get(name, None) if jdk_home_dir: logger.debug(f'JAVA_HOME set by environment variable to {jdk_home_dir}') - return jdk_home_dir + jdk_dir = walk_to_jdk(jdk_home_dir) + + if jdk_dir: + return jdk_dir + else: + logger.debug(f'JAVA_HOME set by environment variable to {jdk_home_dir} but no JDK found.') + logger.debug('Checking Maven for JAVA_HOME...') try: output = subprocess.check_output(['mvn', '-v']) From 4427cde1b50e030b5fa564824cbae3acb271b61f Mon Sep 17 00:00:00 2001 From: Chip Kent <5250374+chipkent@users.noreply.github.com> Date: Wed, 13 Dec 2023 15:42:59 -0700 Subject: [PATCH 6/8] Upated readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 01488a4d..116ad046 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ Install a JDK 8, preferably the Oracle distribution. Set `JDK_HOME` or $ export JDK_HOME= $ export JAVA_HOME=$JDK_HOME + $ pip install setuptools wheel $ python setup.py build maven bdist_wheel On success, the wheel is found in the `dist` directory. @@ -68,12 +69,14 @@ SDK 7.1:: > SET DISTUTILS_USE_SDK=1 > C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\setenv /x64 /release > SET JDK_HOME= + > pip install setuptools wheel > python setup.py build maven bdist_wheel With Visual Studio 14 and higher it is much easier:: > SET VS100COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\ > SET JDK_HOME= + > pip install setuptools wheel > python setup.py build maven bdist_wheel On success, the wheel can be found in the `dist` directory. From 6e8572ffcfa803d944c9daa3f5f384805fead433 Mon Sep 17 00:00:00 2001 From: Chip Kent Date: Fri, 15 Dec 2023 12:42:36 -0700 Subject: [PATCH 7/8] Better java home error message --- jpyutil.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/jpyutil.py b/jpyutil.py index 9d23b396..dde0b3d4 100644 --- a/jpyutil.py +++ b/jpyutil.py @@ -160,13 +160,19 @@ def walk_to_jdk(path): jdk_home_dir = os.environ.get(name, None) if jdk_home_dir: logger.debug(f'JAVA_HOME set by environment variable to {jdk_home_dir}') + + if is_jdk_dir(jdk_home_dir): + return jdk_home_dir + jdk_dir = walk_to_jdk(jdk_home_dir) if jdk_dir: - return jdk_dir + logger.error(f'JAVA_HOME set by environment variable to {jdk_home_dir} but no no "include" or "lib" directory found. Possibly you meant {jdk_dir}?') else: - logger.debug(f'JAVA_HOME set by environment variable to {jdk_home_dir} but no JDK found.') - + logger.error(f'JAVA_HOME set by environment variable to {jdk_home_dir} but no no "include" or "lib" directory found. Does not appear to be a JDK directory.') + + exit(1) + logger.debug('Checking Maven for JAVA_HOME...') try: output = subprocess.check_output(['mvn', '-v']) From 89ded46a146fd65fb5de87cf065ac57779592227 Mon Sep 17 00:00:00 2001 From: Chip Kent Date: Fri, 15 Dec 2023 12:52:20 -0700 Subject: [PATCH 8/8] Fixed usage of walk. --- jpyutil.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/jpyutil.py b/jpyutil.py index dde0b3d4..3e9a073e 100644 --- a/jpyutil.py +++ b/jpyutil.py @@ -148,11 +148,10 @@ def walk_to_jdk(path): for root, dir_names, file_names in os.walk(path): for d in dir_names: - p = os.path.join(path, d) - rst = walk_to_jdk(p) + p = os.path.join(root, d) - if rst: - return rst + if p and is_jdk_dir(p): + return p return None