AlenkaF commented on code in PR #13311:
URL: https://github.com/apache/arrow/pull/13311#discussion_r930505957


##########
python/setup.py:
##########
@@ -227,6 +228,118 @@ def initialize_options(self):
         '_hdfsio',
         'gandiva']
 
+    def _run_cmake_pyarrow_cpp(self):
+        # check if build_type is correctly passed / set
+        if self.build_type.lower() not in ('release', 'debug'):
+            raise ValueError("--build-type (or PYARROW_BUILD_TYPE) needs to "
+                             "be 'release' or 'debug'")
+
+        # The directory containing this setup.py
+        source = os.path.dirname(os.path.abspath(__file__))
+        # The directory containing this PyArrow cpp CMakeLists.txt
+        source_pyarrow_cpp = pjoin(source, "pyarrow/src")
+
+        # The directory for the module being built
+        build_cmd = self.get_finalized_command('build')
+        saved_cwd = os.getcwd()
+        build_dir = pjoin(saved_cwd, 'build', 'dist')
+        build_include = pjoin(saved_cwd, 'build', 'dist', 'include')
+        build_lib = pjoin(os.getcwd(), build_cmd.build_lib)
+
+        # The directory containing Arrow C++ build
+        arrow_build_dir = os.environ.get('ARROW_BUILD_DIR', 'build')
+        if self.inplace:
+            # a bit hacky
+            build_lib = saved_cwd
+        if not os.path.isdir(build_dir):
+            self.mkpath(build_dir)
+        if not os.path.isdir(build_lib):
+            self.mkpath(build_lib)
+        if not os.path.isdir(build_include):
+            self.mkpath(build_include)
+
+        # Change to the build directory
+        with changed_dir(build_dir):
+            # cmake args
+            cmake_options = [
+                '-DCMAKE_INSTALL_PREFIX=' +
+                str(pjoin(saved_cwd, 'build/dist')),
+                '-DCMAKE_BUILD_TYPE={0}'.format(self.build_type.lower()),
+                '-DARROW_BUILD_DIR=' + str(arrow_build_dir),
+                '-DPYTHON_EXECUTABLE=%s' % sys.executable,
+                '-DPython3_EXECUTABLE=%s' % sys.executable,
+            ]
+
+            # Check for specific options
+            def append_cmake_bool(value, varname):
+                cmake_options.append('-D{0}={1}'.format(
+                    varname, 'on' if value else 'off'))
+
+            append_cmake_bool(self.with_dataset, 'PYARROW_WITH_DATASET')
+            append_cmake_bool(self.with_parquet_encryption,
+                              'PYARROW_WITH_PARQUET_ENCRYPTION')
+            append_cmake_bool(self.with_hdfs,
+                              'PYARROW_WITH_HDFS')
+
+            # Windows
+            if self.cmake_generator:
+                cmake_options += ['-G', self.cmake_generator]
+
+            # build args
+            build_tool_args = []
+            if os.environ.get('PYARROW_PARALLEL'):
+                build_tool_args.append('--')
+                build_tool_args.append(
+                    '-j{0}'.format(os.environ['PYARROW_PARALLEL']))
+
+            # run cmake
+            print("-- Running cmake for pyarrow cpp")
+            self.spawn(['cmake'] + cmake_options + [source_pyarrow_cpp])
+            print("-- Finished cmake for pyarrow cpp")
+            # run make & install
+            print("-- Running cmake build and install for pyarrow cpp")
+            self.spawn(['cmake', '--build', '.', '--target', 'install'] +
+                       build_tool_args)
+            print("-- Finished cmake build and install for pyarrow cpp")
+
+            # Move the libraries to the place expected by the Python build
+            try:
+                os.makedirs(pjoin(build_lib, 'pyarrow'))
+            except OSError:
+                pass
+
+            # helper function
+            def copy_libs(folder_name):
+                for libname in os.listdir(pjoin(build_dir, folder_name)):
+                    if "python" in libname:
+                        libname_path = pjoin(build_lib, "pyarrow", libname)
+                        if os.path.exists(libname_path):
+                            os.remove(libname_path)
+                        print(
+                            f"Copying {pjoin(build_dir, folder_name, libname)}"
+                            f" to {pjoin(build_lib, 'pyarrow', libname)}")
+                        shutil.copy(pjoin(build_dir, folder_name, libname),
+                                    pjoin(build_lib, "pyarrow"))
+
+            # Move libraries to python/pyarrow
+            # For windows builds, move dll from bin
+            for folder in ['lib', 'lib64', 'bin']:
+                try:
+                    copy_libs(folder)
+                except OSError:

Review Comment:
   Oh, actually in the Windows build there is a `lib` and `bin` folder and the 
later one is the one that needs to get copied as it includes 
`bin/arrow_python.dll` :/
   
   I guess I will make the windows copying separate ...



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

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to