def test_method_forwarding_windows(self, *unused_mocks): # Test that the correct calls are being forwarded to the subprocess module # and that the shell=True flag is added when we are on Windows. processes.force_shell = True processes.call(['subprocess', 'call'], shell=False, other_arg=True) processes.subprocess.call.assert_called_once_with( ['subprocess', 'call'], shell=True, other_arg=True) processes.check_call( ['subprocess', 'check_call'], shell=False, other_arg=True) processes.subprocess.check_call.assert_called_once_with( ['subprocess', 'check_call'], shell=True, other_arg=True) processes.check_output( ['subprocess', 'check_output'], shell=False, other_arg=True) processes.subprocess.check_output.assert_called_once_with( ['subprocess', 'check_output'], shell=True, other_arg=True) processes.Popen(['subprocess', 'Popen'], shell=False, other_arg=True) processes.subprocess.Popen.assert_called_once_with( ['subprocess', 'Popen'], shell=True, other_arg=True)
def _populate_requirements_cache(requirements_file, cache_dir): # The 'pip download' command will not download again if it finds the # tarball with the proper version already present. # It will get the packages downloaded in the order they are presented in # the requirements file and will not download package dependencies. cmd_args = [ 'pip', 'install', '--download', cache_dir, '-r', requirements_file, # Download from PyPI source distributions. '--no-binary', ':all:'] logging.info('Executing command: %s', cmd_args) result = processes.call(cmd_args) if result != 0: raise RuntimeError( 'Failed to execute command: %s. Exit code %d', cmd_args, result)
def _dependency_file_copy(from_path, to_path): """Copies a local file to a GCS file or vice versa.""" logging.info('file copy from %s to %s.', from_path, to_path) if from_path.startswith('gs://') or to_path.startswith('gs://'): command_args = ['gsutil', '-m', '-q', 'cp', from_path, to_path] logging.info('Executing command: %s', command_args) result = processes.call(command_args) if result != 0: raise ValueError( 'Failed to copy GCS file from %s to %s.' % (from_path, to_path)) else: # Branch used only for unit tests and integration tests. # In such environments GCS support is not available. if not os.path.isdir(os.path.dirname(to_path)): logging.info('Created folder (since we have not done yet, and any errors ' 'will follow): %s ', os.path.dirname(to_path)) os.mkdir(os.path.dirname(to_path)) shutil.copyfile(from_path, to_path)
def _dependency_file_copy(from_path, to_path): """Copies a local file to a GCS file or vice versa.""" logging.info('file copy from %s to %s.', from_path, to_path) if from_path.startswith('gs://') or to_path.startswith('gs://'): command_args = ['gsutil', '-m', '-q', 'cp', from_path, to_path] logging.info('Executing command: %s', command_args) result = processes.call(command_args) if result != 0: raise ValueError('Failed to copy GCS file from %s to %s.' % (from_path, to_path)) else: # Branch used only for unit tests and integration tests. # In such environments GCS support is not available. if not os.path.isdir(os.path.dirname(to_path)): logging.info( 'Created folder (since we have not done yet, and any errors ' 'will follow): %s ', os.path.dirname(to_path)) os.mkdir(os.path.dirname(to_path)) shutil.copyfile(from_path, to_path)
def _build_setup_package(setup_file, temp_dir, build_setup_args=None): saved_current_directory = os.getcwd() try: os.chdir(os.path.dirname(setup_file)) if build_setup_args is None: build_setup_args = [ 'python', os.path.basename(setup_file), 'sdist', '--dist-dir', temp_dir] logging.info('Executing command: %s', build_setup_args) result = processes.call(build_setup_args) if result != 0: raise RuntimeError( 'Failed to execute command: %s. Exit code %d', build_setup_args, result) output_files = glob.glob(os.path.join(temp_dir, '*.tar.gz')) if not output_files: raise RuntimeError( 'File %s not found.' % os.path.join(temp_dir, '*.tar.gz')) return output_files[0] finally: os.chdir(saved_current_directory)
def _build_setup_package(setup_file, temp_dir, build_setup_args=None): saved_current_directory = os.getcwd() try: os.chdir(os.path.dirname(setup_file)) if build_setup_args is None: build_setup_args = [ 'python', os.path.basename(setup_file), 'sdist', '--dist-dir', temp_dir ] logging.info('Executing command: %s', build_setup_args) result = processes.call(build_setup_args) if result != 0: raise RuntimeError('Failed to execute command: %s. Exit code %d', build_setup_args, result) output_files = glob.glob(os.path.join(temp_dir, '*.tar.gz')) if not output_files: raise RuntimeError('File %s not found.' % os.path.join(temp_dir, '*.tar.gz')) return output_files[0] finally: os.chdir(saved_current_directory)
def _populate_requirements_cache(requirements_file, cache_dir): # The 'pip download' command will not download again if it finds the # tarball with the proper version already present. # It will get the packages downloaded in the order they are presented in # the requirements file and will not download package dependencies. cmd_args = [ 'pip', 'install', '--download', cache_dir, '-r', requirements_file, # Download from PyPI source distributions. '--no-binary', ':all:' ] logging.info('Executing command: %s', cmd_args) result = processes.call(cmd_args) if result != 0: raise RuntimeError('Failed to execute command: %s. Exit code %d', cmd_args, result)