Skip to content

Commit

Permalink
Get JDK/JRE path pythonically (#399)
Browse files Browse the repository at this point in the history
* Get JDK/JRE path pythonically

* Run os.readlink() only on Unix-like OS

* Copy environ to Popen for 'which java(c)'

* Switch to check_output

* Use os.path.realpath

* Fix bytes/unicode
  • Loading branch information
KeyWeeUsr authored Feb 4, 2019
1 parent 8e04a69 commit afd9b42
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: generic

os:
- osx
- linux
- osx

env:
- PYTHON_VERSION="2.7" JAVA_VERSION="8"
Expand Down
22 changes: 12 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
import subprocess32 as subprocess
except ImportError:
import subprocess
import os
from os import environ
from os.path import dirname, join, exists
from os.path import dirname, join, exists, realpath
import sys
from platform import machine
from setup_sdist import SETUP_KWARGS
Expand Down Expand Up @@ -168,12 +169,11 @@ def compile_native_invocation_handler(*possible_homes):
JDK_HOME = TMP_JDK_HOME

else:
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 not PY2:
JDK_HOME = JDK_HOME.decode('utf-8')
JDK_HOME = realpath(
subprocess.check_output(
['which', 'javac']
).decode('utf-8').strip()
).replace('bin/javac', '')

if not JDK_HOME or not exists(JDK_HOME):
raise Exception('Unable to determine JDK_HOME')
Expand All @@ -183,9 +183,11 @@ def compile_native_invocation_handler(*possible_homes):
JRE_HOME = join(JDK_HOME, 'jre')

if PLATFORM != 'win32' and 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 = realpath(
subprocess.check_output(
['which', 'java']
).decode('utf-8').strip()
).replace('bin/java', '')

# This dictionary converts values from platform.machine()
# to a "cpu" string. It is needed to set the correct lib path,
Expand Down

0 comments on commit afd9b42

Please sign in to comment.