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_r297519065
 
 

 ##########
 File path: flink-python/setup.py
 ##########
 @@ -42,31 +44,165 @@
 with io.open(os.path.join(this_directory, 'README.md'), 'r', encoding='utf-8') 
as f:
     long_description = f.read()
 
-setup(
-    name='pyflink',
-    version=VERSION,
-    packages=['pyflink',
-              'pyflink.table',
-              'pyflink.util',
-              'pyflink.datastream',
-              'pyflink.dataset',
-              'pyflink.common'],
-    url='http://flink.apache.org',
-    license='http://www.apache.org/licenses/LICENSE-2.0',
-    author='Flink Developers',
-    author_email='[email protected]',
-    install_requires=['py4j==0.10.8.1'],
-    tests_require=['pytest==4.4.1'],
-    description='Apache Flink Python API',
-    long_description=long_description,
-    long_description_content_type='text/markdown',
-    classifiers=[
-        'Development Status :: 1 - Planning',
-        'License :: OSI Approved :: Apache Software License',
-        'Programming Language :: Python :: 2.7',
-        'Programming Language :: Python :: 3.3',
-        'Programming Language :: Python :: 3.4',
-        'Programming Language :: Python :: 3.5',
-        'Programming Language :: Python :: 3.6',
-        'Programming Language :: Python :: 3.7']
-)
+TEMP_PATH = "deps"
+
+LIB_TEMP_PATH = os.path.join(TEMP_PATH, "lib")
+OPT_TEMP_PATH = os.path.join(TEMP_PATH, "opt")
+CONF_TEMP_PATH = os.path.join(TEMP_PATH, "conf")
+EXAMPLES_TEMP_PATH = os.path.join(TEMP_PATH, "examples")
+LICENSES_TEMP_PATH = os.path.join(TEMP_PATH, "licenses")
+SCRIPTS_TEMP_PATH = os.path.join(TEMP_PATH, "bin")
+
+LICENSE_FILE_TEMP_PATH = os.path.join("pyflink", "LICENSE")
+NOTICE_FILE_TEMP_PATH = os.path.join("pyflink", "NOTICE")
+README_FILE_TEMP_PATH = os.path.join("pyflink", "README.txt")
+
+in_flink_source = 
os.path.isfile("../flink-java/src/main/java/org/apache/flink/api/java/"
+                                 "ExecutionEnvironment.java")
+
+try:
+    if in_flink_source:
+
+        try:
+            os.mkdir(TEMP_PATH)
+        except:
+            print("Temp path for symlink to parent already exists 
{0}".format(TEMP_PATH),
+                  file=sys.stderr)
+            sys.exit(-1)
+
+        FLINK_HOME = os.path.abspath("../build-target")
+
+        incorrect_invocation_message = """
+If you are installing pyflink from flink source, you must first build Flink and
+run sdist.
+
+    To build Flink with maven you can run:
+      mvn -DskipTests clean package
+    Building the source dist is done in the flink-python directory:
+      cd flink-python
+      python setup.py sdist
+      pip install dist/*.tar.gz"""
+
+        LIB_PATH = os.path.join(FLINK_HOME, "lib")
+        OPT_PATH = os.path.join(FLINK_HOME, "opt")
+        CONF_PATH = os.path.join(FLINK_HOME, "conf")
+        EXAMPLES_PATH = os.path.join(FLINK_HOME, "examples")
+        LICENSES_PATH = os.path.join(FLINK_HOME, "licenses")
+        SCRIPTS_PATH = os.path.join(FLINK_HOME, "bin")
+
+        LICENSE_FILE_PATH = os.path.join(FLINK_HOME, "LICENSE")
+        NOTICE_FILE_PATH = os.path.join(FLINK_HOME, "NOTICE")
+        README_FILE_PATH = os.path.join(FLINK_HOME, "README.txt")
+
+        if not os.path.isdir(LIB_PATH):
+            print(incorrect_invocation_message, file=sys.stderr)
+            sys.exit(-1)
+
+        if getattr(os, "symlink", None) is not None:
+            os.symlink(LIB_PATH, LIB_TEMP_PATH)
+            os.symlink(OPT_PATH, OPT_TEMP_PATH)
+            os.symlink(CONF_PATH, CONF_TEMP_PATH)
+            os.symlink(EXAMPLES_PATH, EXAMPLES_TEMP_PATH)
+            os.symlink(LICENSES_PATH, LICENSES_TEMP_PATH)
+            os.symlink(SCRIPTS_PATH, SCRIPTS_TEMP_PATH)
+            os.symlink(LICENSE_FILE_PATH, LICENSE_FILE_TEMP_PATH)
+            os.symlink(NOTICE_FILE_PATH, NOTICE_FILE_TEMP_PATH)
+            os.symlink(README_FILE_PATH, README_FILE_TEMP_PATH)
+        else:
+            copytree(LIB_PATH, LIB_TEMP_PATH)
+            copytree(OPT_PATH, OPT_TEMP_PATH)
+            copytree(CONF_PATH, CONF_TEMP_PATH)
+            copytree(EXAMPLES_PATH, EXAMPLES_TEMP_PATH)
+            copytree(LICENSES_PATH, LICENSES_TEMP_PATH)
+            copytree(SCRIPTS_PATH, SCRIPTS_TEMP_PATH)
+            copy(LICENSE_FILE_PATH, LICENSE_FILE_TEMP_PATH)
+            copy(NOTICE_FILE_PATH, NOTICE_FILE_TEMP_PATH)
+            copy(README_FILE_PATH, README_FILE_TEMP_PATH)
+    else:
+        if not os.path.isdir(LIB_TEMP_PATH) or not 
os.path.isdir(OPT_TEMP_PATH) \
+                or not os.path.isdir(SCRIPTS_TEMP_PATH):
+            print("The flink core files are not found. Please make sure your 
installation package "
+                  "is complete, or do this in the flink-python directory of 
the flink source "
+                  "directory.")
+            sys.exit(-1)
+
+    script_names = ["pyflink-shell.sh", "find-flink-home.sh"]
+    scripts = [os.path.join(SCRIPTS_TEMP_PATH, script) for script in 
script_names]
+    scripts.append("pyflink/find_flink_home.py")
+
+    setup(
+        name='pyflink',
+        version=VERSION,
+        packages=['pyflink',
+                  'pyflink.table',
+                  'pyflink.util',
+                  'pyflink.datastream',
+                  'pyflink.dataset',
+                  'pyflink.common',
+                  'pyflink.lib',
+                  'pyflink.opt',
+                  'pyflink.conf',
+                  'pyflink.examples',
+                  'pyflink.licenses',
+                  'pyflink.bin'],
+        include_package_data=True,
+        package_dir={
+            'pyflink.lib': TEMP_PATH + '/lib',
+            'pyflink.opt': TEMP_PATH + '/opt',
+            'pyflink.conf': TEMP_PATH + '/conf',
+            'pyflink.examples': TEMP_PATH + '/examples',
+            'pyflink.licenses': TEMP_PATH + '/licenses',
+            'pyflink.bin': TEMP_PATH + '/bin'
+        },
+        package_data={
+            'pyflink': ['LICENSE', 'NOTICE', 'README.txt'],
+            'pyflink.lib': ['*.jar'],
+            'pyflink.opt': ['*.jar', '*.txt', '*/*.zip', '*/*.txt'],
 
 Review comment:
   What about `'pyflink.opt': ['*', '*/*']`?

----------------------------------------------------------------
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

Reply via email to