Esempio n. 1
0
  def execute(self, **pex_run_kwargs):
    (accept_predicate, reject_predicate) = Target.lang_discriminator('python')
    targets = self.require_homogeneous_targets(accept_predicate, reject_predicate)
    if targets:
      # We can't throw if the target isn't a python target, because perhaps we were called on a
      # JVM target, in which case we have to no-op and let scala repl do its thing.
      # TODO(benjy): Some more elegant way to coordinate how tasks claim targets.
      interpreter = self.select_interpreter_for_targets(targets)

      extra_requirements = []
      if self.get_options().ipython:
        entry_point = self.get_options().ipython_entry_point
        for req in self.get_options().ipython_requirements:
          extra_requirements.append(PythonRequirement(req))
      else:
        entry_point = 'code:interact'

      pex_info = PexInfo.default()
      pex_info.entry_point = entry_point
      with self.temporary_chroot(interpreter=interpreter,
                                 pex_info=pex_info,
                                 targets=targets,
                                 platforms=None,
                                 extra_requirements=extra_requirements) as chroot:
        pex = chroot.pex()
        self.context.release_lock()
        with stty_utils.preserve_stty_settings():
          with self.context.new_workunit(name='run', labels=[WorkUnit.RUN]):
            po = pex.run(blocking=False, **pex_run_kwargs)
            try:
              return po.wait()
            except KeyboardInterrupt:
              pass
Esempio n. 2
0
    def execute(self):
        target = self.require_single_root_target()
        if not isinstance(target, DockerTargetBase):
            return
        cmd = ['docker', 'run']

        if self.get_options().inherit_env:
            for k, v in os.environ.items():
                cmd.extend(['-e', "{0}={1}".format(k, v)])

        opts = self.get_options().opts
        if opts:
            cmd.extend(opts)

        cmd.append(self._image_name(target))

        command = self.get_options().command
        if command:
            cmd.append(command)

        args = self.get_options().args + self.get_passthru_args()
        if args:
            cmd.extend(args)

        with self.context.new_workunit(name='run',
                                       labels=[WorkUnitLabel.RUN]) as workunit:
            self.context.release_lock()
            with stty_utils.preserve_stty_settings():
                self._run_docker_command(workunit, cmd)
Esempio n. 3
0
    def execute(self):
        (accept_predicate,
         reject_predicate) = Target.lang_discriminator('java')
        targets = self.require_homogeneous_targets(accept_predicate,
                                                   reject_predicate)
        if targets:
            tools_classpath = self.tool_classpath(self._bootstrap_key)
            self.context.release_lock()
            with preserve_stty_settings():
                exclusives_classpath = self.get_base_classpath_for_target(
                    targets[0])
                classpath = self.classpath(
                    tools_classpath,
                    confs=self.confs,
                    exclusives_classpath=exclusives_classpath)

                print('')  # Start REPL output on a new line.
                try:
                    # NOTE: We execute with no workunit, as capturing REPL output makes it very sluggish.
                    execute_java(classpath=classpath,
                                 main=self.main,
                                 jvm_options=self.jvm_options,
                                 args=self.args)
                except KeyboardInterrupt:
                    # TODO(John Sirois): Confirm with Steve Gury that finally does not work on mac and an
                    # explicit catch of KeyboardInterrupt is required.
                    pass
Esempio n. 4
0
  def execute(self):
    (accept_predicate, reject_predicate) = Target.lang_discriminator('java')
    targets = self.require_homogeneous_targets(accept_predicate, reject_predicate)
    if targets:
      tools_classpath = self.tool_classpath('scala-repl')
      self.context.release_lock()
      with preserve_stty_settings():
        classpath = self.classpath(targets, cp=tools_classpath)

        # The scala repl requires -Dscala.usejavacp=true since Scala 2.8 when launching in the way
        # we do here (not passing -classpath as a program arg to scala.tools.nsc.MainGenericRunner).
        jvm_options = self.jvm_options
        if not any(opt.startswith('-Dscala.usejavacp=') for opt in jvm_options):
          jvm_options.append('-Dscala.usejavacp=true')

        print('')  # Start REPL output on a new line.
        try:
          # NOTE: We execute with no workunit, as capturing REPL output makes it very sluggish.
          DistributionLocator.cached().execute_java(classpath=classpath,
                                                    main=self.get_options().main,
                                                    jvm_options=jvm_options,
                                                    args=self.args)
        except KeyboardInterrupt:
          # TODO(John Sirois): Confirm with Steve Gury that finally does not work on mac and an
          # explicit catch of KeyboardInterrupt is required.
          pass
Esempio n. 5
0
    def execute(self):
        (accept_predicate,
         reject_predicate) = Target.lang_discriminator('java')
        targets = self.require_homogeneous_targets(accept_predicate,
                                                   reject_predicate)
        if targets:
            tools_classpath = self.tool_classpath('scala-repl')
            self.context.release_lock()
            with preserve_stty_settings():
                classpath = self.classpath(targets, cp=tools_classpath)

                # The scala repl requires -Dscala.usejavacp=true since Scala 2.8 when launching in the way
                # we do here (not passing -classpath as a program arg to scala.tools.nsc.MainGenericRunner).
                jvm_options = self.jvm_options
                if not any(
                        opt.startswith('-Dscala.usejavacp=')
                        for opt in jvm_options):
                    jvm_options.append('-Dscala.usejavacp=true')

                print('')  # Start REPL output on a new line.
                try:
                    # NOTE: We execute with no workunit, as capturing REPL output makes it very sluggish.
                    execute_java(classpath=classpath,
                                 main=self.get_options().main,
                                 jvm_options=jvm_options,
                                 args=self.args)
                except KeyboardInterrupt:
                    # TODO(John Sirois): Confirm with Steve Gury that finally does not work on mac and an
                    # explicit catch of KeyboardInterrupt is required.
                    pass
Esempio n. 6
0
  def execute(self, **pex_run_kwargs):
    (accept_predicate, reject_predicate) = Target.lang_discriminator('python')
    targets = self.require_homogeneous_targets(accept_predicate, reject_predicate)
    if targets:
      # We can't throw if the target isn't a python target, because perhaps we were called on a
      # JVM target, in which case we have to no-op and let scala repl do its thing.
      # TODO(benjy): Some more elegant way to coordinate how tasks claim targets.
      interpreter = self.select_interpreter_for_targets(targets)

      extra_requirements = []
      if self.get_options().ipython:
        entry_point = self.get_options().ipython_entry_point
        for req in self.get_options().ipython_requirements:
          extra_requirements.append(PythonRequirement(req))
      else:
        entry_point = 'code:interact'

      pex_info = PexInfo.default()
      pex_info.entry_point = entry_point
      with self.cached_chroot(interpreter=interpreter,
                              pex_info=pex_info,
                              targets=targets,
                              platforms=None,
                              extra_requirements=extra_requirements) as chroot:
        pex = chroot.pex()
        self.context.release_lock()
        with stty_utils.preserve_stty_settings():
          with self.context.new_workunit(name='run', labels=[WorkUnitLabel.RUN]):
            po = pex.run(blocking=False, **pex_run_kwargs)
            try:
              return po.wait()
            except KeyboardInterrupt:
              pass
Esempio n. 7
0
 def execute_for(self, targets):
     session_setup = self.setup_repl_session(targets)
     self.context.release_lock()
     with stty_utils.preserve_stty_settings():
         with self.context.new_workunit(name="repl", labels=[WorkUnitLabel.RUN]):
             print("")  # Start REPL output on a new line.
             try:
                 return self.launch_repl(session_setup)
             except KeyboardInterrupt:
                 # This is a valid way to end a REPL session in general, so just break out of execute and
                 # continue.
                 pass
Esempio n. 8
0
 def execute_for(self, targets):
   session_setup = self.setup_repl_session(targets)
   self.context.release_lock()
   with stty_utils.preserve_stty_settings():
     with self.context.new_workunit(name='repl', labels=[WorkUnitLabel.RUN]):
       print('')  # Start REPL output on a new line.
       try:
         return self.launch_repl(session_setup)
       except KeyboardInterrupt:
         # This is a valid way to end a REPL session in general, so just break out of execute and
         # continue.
         pass
Esempio n. 9
0
    def execute(self):
        (accept_predicate,
         reject_predicate) = Target.lang_discriminator('python')
        targets = self.require_homogeneous_targets(accept_predicate,
                                                   reject_predicate)
        if targets:
            # We can't throw if the target isn't a python target, because perhaps we were called on a
            # JVM target, in which case we have to no-op and let scala repl do its thing.
            # TODO(benjy): Some more elegant way to coordinate how tasks claim targets.
            interpreter = self.select_interpreter_for_targets(targets)

            extra_requirements = []
            if self.context.options.python_repl_ipython:
                entry_point = self.context.config.get(
                    'python-ipython',
                    'entry_point',
                    default='IPython:start_ipython')
                ipython_requirements = self.context.config.getlist(
                    'python-ipython',
                    'requirements',
                    default=['ipython==1.0.0'])
                for req in ipython_requirements:
                    extra_requirements.append(PythonRequirement(req))
            else:
                entry_point = 'code:interact'

            with self.temporary_pex_builder(
                    interpreter=interpreter) as builder:
                builder.set_entry_point(entry_point)
                chroot = PythonChroot(targets=targets,
                                      extra_requirements=extra_requirements,
                                      builder=builder,
                                      interpreter=interpreter,
                                      conn_timeout=self.conn_timeout)

                chroot.dump()
                builder.freeze()
                pex = PEX(builder.path(), interpreter=interpreter)
                self.context.lock.release()
                with stty_utils.preserve_stty_settings():
                    with self.context.new_workunit(name='run',
                                                   labels=[WorkUnit.RUN]):
                        po = pex.run(blocking=False)
                        try:
                            return po.wait()
                        except KeyboardInterrupt:
                            pass
Esempio n. 10
0
    def execute(self):
        (accept_predicate, reject_predicate) = Target.lang_discriminator("java")
        targets = self.require_homogeneous_targets(accept_predicate, reject_predicate)
        if targets:
            tools_classpath = self.tool_classpath(self._bootstrap_key)
            self.context.lock.release()
            with preserve_stty_settings():
                exclusives_classpath = self.get_base_classpath_for_target(targets[0])
                classpath = self.classpath(tools_classpath, confs=self.confs, exclusives_classpath=exclusives_classpath)

                print("")  # Start REPL output on a new line.
                try:
                    # NOTE: We execute with no workunit, as capturing REPL output makes it very sluggish.
                    execute_java(classpath=classpath, main=self.main, jvm_options=self.jvm_args, args=self.args)
                except KeyboardInterrupt:
                    # TODO(John Sirois): Confirm with Steve Gury that finally does not work on mac and an
                    # explicit catch of KeyboardInterrupt is required.
                    pass
Esempio n. 11
0
  def execute(self):
    (accept_predicate, reject_predicate) = Target.lang_discriminator('java')
    targets = self.require_homogeneous_targets(accept_predicate, reject_predicate)
    if targets:
      tools_classpath = self.tool_classpath('scala-repl')
      self.context.release_lock()
      with preserve_stty_settings():
        classpath = self.classpath(targets, cp=tools_classpath, confs=self.confs)

        print('')  # Start REPL output on a new line.
        try:
          # NOTE: We execute with no workunit, as capturing REPL output makes it very sluggish.
          execute_java(classpath=classpath,
                       main=self.get_options().main,
                       jvm_options=self.jvm_options,
                       args=self.args)
        except KeyboardInterrupt:
          # TODO(John Sirois): Confirm with Steve Gury that finally does not work on mac and an
          # explicit catch of KeyboardInterrupt is required.
          pass
Esempio n. 12
0
  def execute(self):
    (accept_predicate, reject_predicate) = Target.lang_discriminator('python')
    targets = self.require_homogeneous_targets(accept_predicate, reject_predicate)
    if targets:
      # We can't throw if the target isn't a python target, because perhaps we were called on a
      # JVM target, in which case we have to no-op and let scala repl do its thing.
      # TODO(benjy): Some more elegant way to coordinate how tasks claim targets.
      interpreter = self.select_interpreter_for_targets(targets)

      extra_requirements = []
      if self.get_options().ipython:
        entry_point = self.context.config.get('python-ipython', 'entry_point',
                                              default='IPython:start_ipython')
        ipython_requirements = self.context.config.getlist('python-ipython', 'requirements',
                                                           default=['ipython==1.0.0'])
        for req in ipython_requirements:
          extra_requirements.append(PythonRequirement(req))
      else:
        entry_point = 'code:interact'

      with self.temporary_pex_builder(interpreter=interpreter) as builder:
        builder.set_entry_point(entry_point)
        chroot = PythonChroot(
          targets=targets,
          extra_requirements=extra_requirements,
          builder=builder,
          interpreter=interpreter,
          conn_timeout=self.conn_timeout)

        chroot.dump()
        builder.freeze()
        pex = PEX(builder.path(), interpreter=interpreter)
        self.context.lock.release()
        with stty_utils.preserve_stty_settings():
          with self.context.new_workunit(name='run', labels=[WorkUnit.RUN]):
            po = pex.run(blocking=False)
            try:
              return po.wait()
            except KeyboardInterrupt:
              pass