Improve build slightly

pull/23243/head
Richard Belleville 5 years ago
parent 80f0c331f9
commit 08e117ae80
  1. 1
      setup.py
  2. 5
      src/python/grpcio/_parallel_compile_patch.py
  3. 45
      src/python/grpcio/commands.py

@ -383,6 +383,7 @@ COMMAND_CLASS = {
'build_py': commands.BuildPy,
'build_ext': commands.BuildExt,
'gather': commands.Gather,
'clean': commands.Clean,
}
# Ensure that package data is copied over before any commands have been run:

@ -22,7 +22,10 @@ import os
try:
BUILD_EXT_COMPILER_JOBS = int(
os.environ.get('GRPC_PYTHON_BUILD_EXT_COMPILER_JOBS', '1'))
os.environ['GRPC_PYTHON_BUILD_EXT_COMPILER_JOBS'])
except KeyError:
import multiprocessing
BUILD_EXT_COMPILER_JOBS = multiprocessing.cpu_count()
except ValueError:
BUILD_EXT_COMPILER_JOBS = 1

@ -13,6 +13,8 @@
# limitations under the License.
"""Provides distutils command classes for the GRPC Python setup process."""
from __future__ import print_function
import distutils
import glob
import os
@ -218,7 +220,10 @@ class BuildExt(build_ext.build_ext):
if platform.system() != 'Windows':
return False
# TODO(lidiz) Remove the generated a.out for success tests.
cc_test = subprocess.Popen(['cc', '-x', 'c', '-std=c++11', '-'],
cc_test = subprocess.Popen([
distutils.ccompiler.executable_filename, '-x', 'c',
'-std=c++11', '-'
],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
@ -290,3 +295,41 @@ class Gather(setuptools.Command):
self.distribution.install_requires)
if self.test and self.distribution.tests_require:
self.distribution.fetch_build_eggs(self.distribution.tests_require)
class Clean(setuptools.Command):
"""Command to clean build artifacts."""
description = 'Clean build artifacts.'
user_options = []
_FILE_PATTERNS = [
'python_build',
'src/python/grpcio/__pycache__/',
'src/python/grpcio/grpc/_cython/cygrpc.cpp',
'src/python/grpcio/grpc/_cython/*.so',
'src/python/grpcio/grpcio.egg-info/',
]
_CURRENT_DIRECTORY = os.path.normpath(
os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../.."))
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
for path_spec in self._FILE_PATTERNS:
this_glob = os.path.normpath(
os.path.join(Clean._CURRENT_DIRECTORY, path_spec))
abs_paths = glob.glob(this_glob)
for path in abs_paths:
if not str(path).startswith(Clean._CURRENT_DIRECTORY):
raise ValueError(
"Cowardly refusing to delete {}.".format(path))
print("Removing {}".format(os.path.relpath(path)))
if os.path.isfile(path):
os.remove(str(path))
else:
shutil.rmtree(str(path))

Loading…
Cancel
Save