def create_binary(self, binary): if binary.compatibility: interpreter = self.select_interpreter(binary.compatibility) else: interpreter = self.interpreter distpath = tempfile.mktemp(dir=self._distdir, prefix=binary.name) run_info = self.context.run_tracker.run_info build_properties = {} build_properties.update( run_info.add_basic_info(run_id=None, timestamp=time.time())) build_properties.update(run_info.add_scm_info()) pexinfo = binary.pexinfo.copy() pexinfo.build_properties = build_properties builder = PEXBuilder(distpath, pex_info=pexinfo, interpreter=interpreter) chroot = PythonChroot(targets=[binary], builder=builder, platforms=binary.platforms, interpreter=interpreter, conn_timeout=self.conn_timeout) pex_path = os.path.join(self._distdir, '%s.pex' % binary.name) builder = chroot.dump() try: builder.build(pex_path) finally: builder.chroot().delete()
def _run_python_test(self, target): po = None rv = PythonTestResult.exception() coverage_rc = None coverage_enabled = 'PANTS_PY_COVERAGE' in os.environ try: builder = PEXBuilder(interpreter=self.interpreter) builder.info.entry_point = target.entry_point builder.info.ignore_errors = target._soft_dependencies chroot = PythonChroot(target, self.root_dir, extra_targets=self.generate_test_targets(), builder=builder, platforms=('current', ), interpreter=self.interpreter, conn_timeout=self._conn_timeout) builder = chroot.dump() builder.freeze() test_args = PythonTestBuilder.generate_junit_args(target) test_args.extend(self.args) if coverage_enabled: coverage_rc, args = self.cov_setup(target, builder.chroot()) test_args.extend(args) sources = [ os.path.join(target.target_base, source) for source in target.sources ] po = PEX(builder.path(), interpreter=self.interpreter).run( args=test_args + sources, blocking=False, setsid=True) # TODO(wickman) If coverage is enabled, write an intermediate .html that points to # each of the coverage reports generated and webbrowser.open to that page. rv = PythonTestBuilder.wait_on(po, timeout=target.timeout) except Exception as e: import traceback print('Failed to run test!', file=sys.stderr) traceback.print_exc() rv = PythonTestResult.exception() finally: if coverage_rc: os.unlink(coverage_rc) if po and po.returncode != 0: try: os.killpg(po.pid, signal.SIGTERM) except OSError as e: if e.errno == errno.EPERM: print("Unable to kill process group: %d" % po.pid) elif e.errno != errno.ESRCH: rv = PythonTestResult.exception() self.successes[target._create_id()] = rv return rv
def _run_python_test(self, target): po = None rv = PythonTestResult.exception() coverage_rc = None coverage_enabled = "PANTS_PY_COVERAGE" in os.environ try: builder = PEXBuilder() builder.info().entry_point = "pytest" builder.info().ignore_errors = target._soft_dependencies chroot = PythonChroot( target, self.root_dir, extra_targets=self.generate_test_targets(), builder=builder, conn_timeout=self._conn_timeout, ) builder = chroot.dump() builder.freeze() test_args = PythonTestBuilder.generate_junit_args(target) test_args.extend(self.args) if coverage_enabled: coverage_rc, args = self.cov_setup(target, builder.chroot()) test_args.extend(args) sources = [os.path.join(target.target_base, source) for source in target.sources] po = PEX(builder.path()).run(args=test_args + sources, blocking=False, setsid=True) # TODO(wickman) If coverage is enabled, write an intermediate .html that points to # each of the coverage reports generated and webbrowser.open to that page. rv = PythonTestBuilder.wait_on(po, timeout=target.timeout) except KeyboardInterrupt: print("Test interrupted by user") rv = PythonTestResult.cancelled() except Exception as e: import traceback print("Failed to run test!", file=sys.stderr) traceback.print_exc() rv = PythonTestResult.exception() finally: if coverage_rc: os.unlink(coverage_rc) if po and po.returncode != 0: try: os.killpg(po.pid, signal.SIGTERM) except OSError as e: if e.errno == errno.EPERM: print("Unable to kill process group: %d" % po.pid) elif e.errno != errno.ESRCH: rv = PythonTestResult.exception() self.successes[target._create_id()] = rv return rv
def _run_python_test(self, target): po = None rv = PythonTestResult.exception() coverage_rc = None coverage_enabled = 'PANTS_PY_COVERAGE' in os.environ try: builder = PEXBuilder(interpreter=self.interpreter) builder.info.entry_point = target.entry_point builder.info.ignore_errors = target._soft_dependencies chroot = PythonChroot( target, self.root_dir, extra_requirements=self.generate_test_targets(), builder=builder, platforms=('current',), interpreter=self.interpreter, conn_timeout=self._conn_timeout) builder = chroot.dump() builder.freeze() test_args = PythonTestBuilder.generate_junit_args(target) test_args.extend(self.args) if coverage_enabled: coverage_rc, args = self.cov_setup(target, builder.chroot()) test_args.extend(args) sources = target.sources_relative_to_buildroot() po = PEX(builder.path(), interpreter=self.interpreter).run( args=test_args + sources, blocking=False, setsid=True) # TODO(wickman) If coverage is enabled, write an intermediate .html that points to # each of the coverage reports generated and webbrowser.open to that page. rv = PythonTestBuilder.wait_on(po, timeout=target.timeout) except Exception as e: import traceback print('Failed to run test!', file=sys.stderr) traceback.print_exc() rv = PythonTestResult.exception() finally: if coverage_rc: os.unlink(coverage_rc) if po and po.returncode != 0: try: os.killpg(po.pid, signal.SIGTERM) except OSError as e: if e.errno == errno.EPERM: print("Unable to kill process group: %d" % po.pid) elif e.errno != errno.ESRCH: rv = PythonTestResult.exception() self.successes[target.id] = rv return rv
def temporary_pex_builder(self, interpreter=None, pex_info=None, parent_dir=None): """Yields a PEXBuilder and cleans up its chroot when it goes out of context.""" path = tempfile.mkdtemp(dir=parent_dir) builder = PEXBuilder(path=path, interpreter=interpreter, pex_info=pex_info) yield builder builder.chroot().delete()