dianfu commented on a change in pull request #8863: [FLINK-12962][python]
Allows pyflink to be pip installed.
URL: https://github.com/apache/flink/pull/8863#discussion_r297532944
##########
File path: flink-python/pyflink/find_flink_home.py
##########
@@ -30,12 +40,31 @@ def _find_flink_home():
return os.environ['FLINK_HOME']
else:
try:
- flink_root_dir =
os.path.abspath(os.path.dirname(os.path.abspath(__file__)) + "/../../")
+ current_dir =
os.path.abspath(os.path.dirname(os.path.abspath(__file__)))
+ flink_root_dir = os.path.abspath(current_dir + "/../../")
build_target = flink_root_dir + "/build-target"
- pyflink_file = build_target + "/bin/pyflink-gateway-server.sh"
- if os.path.isfile(pyflink_file):
+ if is_flink_home(build_target):
os.environ['FLINK_HOME'] = build_target
return build_target
+
+ if sys.version < "3":
+ import imp
+ try:
+ module_home = imp.find_module("pyflink")[1]
+ if is_flink_home(module_home):
+ os.environ['FLINK_HOME'] = module_home
+ return module_home
+ except ImportError:
+ pass
+ else:
+ from importlib.util import find_spec
+ try:
+ module_home = os.path.dirname(find_spec("pyflink").origin)
Review comment:
Most of the code in the if/else is duplicate. We can put only the
module_name statement in the if/else to eliminate duplication.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services