示例#1
0
文件: build.py 项目: ejconlon/pants
    def __init__(self, run_tracker, root_dir, parser, argv):
        Command.__init__(self, run_tracker, root_dir, parser, argv)

        if not self.args:
            self.error("A spec argument is required")

        self.config = Config.load()

        interpreters = self.options.interpreters or [b'']
        self.interpreter_cache = PythonInterpreterCache(self.config,
                                                        logger=self.debug)
        self.interpreter_cache.setup(filters=interpreters)
        interpreters = self.interpreter_cache.select_interpreter(
            list(self.interpreter_cache.matches(interpreters)))
        if len(interpreters) != 1:
            self.error('Unable to detect suitable interpreter.')
        else:
            self.debug('Selected %s' % interpreters[0])
        self.interpreter = interpreters[0]

        try:
            specs_end = self.args.index('--')
            if len(self.args) > specs_end:
                self.build_args = self.args[specs_end + 1:len(self.args) + 1]
            else:
                self.build_args = []
        except ValueError:
            specs_end = 1
            self.build_args = self.args[1:] if len(self.args) > 1 else []

        self.targets = OrderedSet()
        spec_parser = SpecParser(root_dir, self.build_file_parser)
        self.top_level_addresses = set()

        for spec in self.args[0:specs_end]:
            try:
                addresses = spec_parser.parse_addresses(spec)
            except:
                self.error("Problem parsing spec %s: %s" %
                           (spec, traceback.format_exc()))

            for address in addresses:
                self.top_level_addresses.add(address)
                try:
                    self.build_file_parser.inject_address_closure_into_build_graph(
                        address, self.build_graph)
                    target = self.build_graph.get_target(address)
                except:
                    self.error("Problem parsing BUILD target %s: %s" %
                               (address, traceback.format_exc()))

                if not target:
                    self.error("Target %s does not exist" % address)

                transitive_targets = self.build_graph.transitive_subgraph_of_addresses(
                    [target.address])
                for transitive_target in transitive_targets:
                    self.targets.add(transitive_target)

        self.targets = [target for target in self.targets if target.is_python]
示例#2
0
文件: build.py 项目: ejconlon/pants
  def __init__(self, run_tracker, root_dir, parser, argv):
    Command.__init__(self, run_tracker, root_dir, parser, argv)

    if not self.args:
      self.error("A spec argument is required")

    self.config = Config.load()

    interpreters = self.options.interpreters or [b'']
    self.interpreter_cache = PythonInterpreterCache(self.config, logger=self.debug)
    self.interpreter_cache.setup(filters=interpreters)
    interpreters = self.interpreter_cache.select_interpreter(
        list(self.interpreter_cache.matches(interpreters)))
    if len(interpreters) != 1:
      self.error('Unable to detect suitable interpreter.')
    else:
      self.debug('Selected %s' % interpreters[0])
    self.interpreter = interpreters[0]

    try:
      specs_end = self.args.index('--')
      if len(self.args) > specs_end:
        self.build_args = self.args[specs_end+1:len(self.args)+1]
      else:
        self.build_args = []
    except ValueError:
      specs_end = 1
      self.build_args = self.args[1:] if len(self.args) > 1 else []

    self.targets = OrderedSet()
    spec_parser = SpecParser(root_dir, self.build_file_parser)
    self.top_level_addresses = set()

    for spec in self.args[0:specs_end]:
      try:
        addresses = spec_parser.parse_addresses(spec)
      except:
        self.error("Problem parsing spec %s: %s" % (spec, traceback.format_exc()))

      for address in addresses:
        self.top_level_addresses.add(address)
        try:
          self.build_file_parser.inject_address_closure_into_build_graph(address, self.build_graph)
          target = self.build_graph.get_target(address)
        except:
          self.error("Problem parsing BUILD target %s: %s" % (address, traceback.format_exc()))

        if not target:
          self.error("Target %s does not exist" % address)

        transitive_targets = self.build_graph.transitive_subgraph_of_addresses([target.address])
        for transitive_target in transitive_targets:
          self.targets.add(transitive_target)

    self.targets = [target for target in self.targets if target.is_python]
示例#3
0
  def __init__(self, run_tracker, root_dir, parser, argv):
    Command.__init__(self, run_tracker, root_dir, parser, argv)

    if not self.args:
      self.error("A spec argument is required")

    self._config = Config.load()
    self._root = root_dir

    address = Address.parse(root_dir, self.args[0])
    self.target = Target.get(address)
    if self.target is None:
      self.error('%s is not a valid target!' % self.args[0])

    if not self.target.provides:
      self.error('Target must provide an artifact.')
示例#4
0
  def __init__(self, run_tracker, root_dir, parser, argv):
    Command.__init__(self, run_tracker, root_dir, parser, argv)

    if not self.args:
      self.error("A spec argument is required")

    self._config = Config.load()
    self._root = root_dir

    self.build_file_parser.inject_spec_closure_into_build_graph(self.args[0], self.build_graph)
    self.target = self.build_graph.get_target_from_spec(self.args[0])

    if self.target is None:
      self.error('%s is not a valid target!' % self.args[0])

    if not self.target.provides:
      self.error('Target must provide an artifact.')
示例#5
0
文件: build.py 项目: kn/pants
  def __init__(self, run_tracker, root_dir, parser, argv):
    Command.__init__(self, run_tracker, root_dir, parser, argv)

    if not self.args:
      self.error("A spec argument is required")

    self.config = Config.load()

    interpreters = self.options.interpreters or [b'']
    self.interpreter_cache = PythonInterpreterCache(self.config, logger=self.debug)
    self.interpreter_cache.setup(filters=interpreters)
    interpreters = self.interpreter_cache.select_interpreter(
        list(self.interpreter_cache.matches(interpreters)))
    if len(interpreters) != 1:
      self.error('Unable to detect suitable interpreter.')
    else:
      self.debug('Selected %s' % interpreters[0])
    self.interpreter = interpreters[0]

    try:
      specs_end = self.args.index('--')
      if len(self.args) > specs_end:
        self.build_args = self.args[specs_end+1:len(self.args)+1]
      else:
        self.build_args = []
    except ValueError:
      specs_end = 1
      self.build_args = self.args[1:] if len(self.args) > 1 else []

    self.targets = OrderedSet()
    for spec in self.args[0:specs_end]:
      try:
        address = Address.parse(root_dir, spec)
      except:
        self.error("Problem parsing spec %s: %s" % (spec, traceback.format_exc()))

      try:
        target = Target.get(address)
      except:
        self.error("Problem parsing BUILD target %s: %s" % (address, traceback.format_exc()))

      if not target:
        self.error("Target %s does not exist" % address)
      self.targets.update(tgt for tgt in target.resolve() if tgt.is_concrete)
示例#6
0
文件: goal.py 项目: ejconlon/pants
 def __init__(self, run_tracker, root_dir, parser, args):
   self.targets = []
   self.config = None
   Command.__init__(self, run_tracker, root_dir, parser, args)
示例#7
0
文件: py.py 项目: govindkabra/pants
  def __init__(self, run_tracker, root_dir, parser, argv):
    Command.__init__(self, run_tracker, root_dir, parser, argv)

    self.target = None
    self.extra_targets = []
    self.config = Config.load()
    self.interpreter_cache = PythonInterpreterCache(self.config, logger=self.debug)
    self.interpreter_cache.setup()
    interpreters = self.interpreter_cache.select_interpreter(
        list(self.interpreter_cache.matches([self.options.interpreter]
            if self.options.interpreter else [b''])))
    if len(interpreters) != 1:
      self.error('Unable to detect suitable interpreter.')
    self.interpreter = interpreters[0]

    for req in self.options.extra_requirements:
      with ParseContext.temp():
        self.extra_targets.append(PythonRequirement(req, use_2to3=True))

    # We parse each arg in the context of the cli usage:
    #   ./pants command (options) [spec] (build args)
    #   ./pants command (options) [spec]... -- (build args)
    # Our command token and our options are parsed out so we see args of the form:
    #   [spec] (build args)
    #   [spec]... -- (build args)
    binaries = []
    for k in range(len(self.args)):
      arg = self.args.pop(0)
      if arg == '--':
        break

      def not_a_target(debug_msg):
        self.debug('Not a target, assuming option: %s.' % e)
        # We failed to parse the arg as a target or else it was in valid address format but did not
        # correspond to a real target.  Assume this is the 1st of the build args and terminate
        # processing args for target addresses.
        self.args.insert(0, arg)

      target = None
      try:
        address = Address.parse(root_dir, arg)
        target = Target.get(address)
        if target is None:
          not_a_target(debug_msg='Unrecognized target')
          break
      except Exception as e:
        not_a_target(debug_msg=e)
        break

      for resolved in filter(lambda t: t.is_concrete, target.resolve()):
        if isinstance(resolved, PythonBinary):
          binaries.append(resolved)
        else:
          self.extra_targets.append(resolved)

    if len(binaries) == 0:
      # treat as a chroot
      pass
    elif len(binaries) == 1:
      # We found a binary and are done, the rest of the args get passed to it
      self.target = binaries[0]
    else:
      self.error('Can only process 1 binary target, %s contains %d:\n\t%s' % (
        arg, len(binaries), '\n\t'.join(str(binary.address) for binary in binaries)
      ))

    if self.target is None:
      if not self.extra_targets:
        self.error('No valid target specified!')
      self.target = self.extra_targets.pop(0)
示例#8
0
文件: py.py 项目: Docworld/pants
  def __init__(self,
               run_tracker,
               root_dir,
               parser,
               argv,
               build_file_parser,
               build_graph):
    Command.__init__(self,
                     run_tracker,
                     root_dir,
                     parser,
                     argv,
                     build_file_parser,
                     build_graph)

    self.binary = None
    self.targets = []
    self.extra_requirements = []
    self.config = Config.load()

    interpreters = self.options.interpreters or [b'']
    self.interpreter_cache = PythonInterpreterCache(self.config, logger=self.debug)
    self.interpreter_cache.setup(filters=interpreters)
    interpreters = self.interpreter_cache.select_interpreter(
        list(self.interpreter_cache.matches(interpreters)))
    if len(interpreters) != 1:
      self.error('Unable to detect suitable interpreter.')
    self.interpreter = interpreters[0]

    for req in self.options.extra_requirements:
      self.extra_requirements.append(PythonRequirement(req, use_2to3=True))

    # We parse each arg in the context of the cli usage:
    #   ./pants command (options) [spec] (build args)
    #   ./pants command (options) [spec]... -- (build args)
    # Our command token and our options are parsed out so we see args of the form:
    #   [spec] (build args)
    #   [spec]... -- (build args)
    for k in range(len(self.args)):
      arg = self.args.pop(0)
      if arg == '--':
        break

      def not_a_target(debug_msg):
        self.debug('Not a target, assuming option: %s.' % debug_msg)
        # We failed to parse the arg as a target or else it was in valid address format but did not
        # correspond to a real target.  Assume this is the 1st of the build args and terminate
        # processing args for target addresses.
        self.args.insert(0, arg)

      try:
        print(root_dir, arg)
        self.build_file_parser.inject_spec_closure_into_build_graph(arg, self.build_graph)
        spec_path, target_name = parse_spec(arg)
        build_file = BuildFile(root_dir, spec_path)
        address = BuildFileAddress(build_file, target_name)
        target = self.build_graph.get_target(address)
        if target is None:
          not_a_target(debug_msg='Unrecognized target')
          break
      except Exception as e:
        not_a_target(debug_msg=e)
        break

      if isinstance(target, PythonBinary):
        if self.binary:
          self.error('Can only process 1 binary target. Found %s and %s.' % (self.binary, target))
        else:
          self.binary = target
      self.targets.append(target)

    if not self.targets:
      self.error('No valid targets specified!')
示例#9
0
文件: goal.py 项目: ejconlon/pants
 def __init__(self, run_tracker, root_dir, parser, args):
     self.targets = []
     self.config = None
     Command.__init__(self, run_tracker, root_dir, parser, args)
示例#10
0
文件: help.py 项目: govindkabra/pants
  def __init__(self, run_tracker, root_dir, parser, argv):
    Command.__init__(self, run_tracker, root_dir, parser, argv)

    if len(self.args) > 1:
      self.error("The help command accepts at most 1 argument.")
    self.subcommand = self.args[0]
示例#11
0
文件: py.py 项目: dbieber/pants
    def __init__(self, run_tracker, root_dir, parser, argv, build_file_parser,
                 build_graph):
        Command.__init__(self, run_tracker, root_dir, parser, argv,
                         build_file_parser, build_graph)

        self.binary = None
        self.targets = []
        self.extra_requirements = []
        self.config = Config.load()

        interpreters = self.options.interpreters or [b'']
        self.interpreter_cache = PythonInterpreterCache(self.config,
                                                        logger=self.debug)
        self.interpreter_cache.setup(filters=interpreters)
        interpreters = self.interpreter_cache.select_interpreter(
            list(self.interpreter_cache.matches(interpreters)))
        if len(interpreters) != 1:
            self.error('Unable to detect suitable interpreter.')
        self.interpreter = interpreters[0]

        for req in self.options.extra_requirements:
            self.extra_requirements.append(
                PythonRequirement(req, use_2to3=True))

        # We parse each arg in the context of the cli usage:
        #   ./pants command (options) [spec] (build args)
        #   ./pants command (options) [spec]... -- (build args)
        # Our command token and our options are parsed out so we see args of the form:
        #   [spec] (build args)
        #   [spec]... -- (build args)
        for k in range(len(self.args)):
            arg = self.args.pop(0)
            if arg == '--':
                break

            def not_a_target(debug_msg):
                self.debug('Not a target, assuming option: %s.' % debug_msg)
                # We failed to parse the arg as a target or else it was in valid address format but did not
                # correspond to a real target.  Assume this is the 1st of the build args and terminate
                # processing args for target addresses.
                self.args.insert(0, arg)

            try:
                print(root_dir, arg)
                self.build_file_parser.inject_spec_closure_into_build_graph(
                    arg, self.build_graph)
                spec_path, target_name = parse_spec(arg)
                build_file = BuildFile(root_dir, spec_path)
                address = BuildFileAddress(build_file, target_name)
                target = self.build_graph.get_target(address)
                if target is None:
                    not_a_target(debug_msg='Unrecognized target')
                    break
            except Exception as e:
                not_a_target(debug_msg=e)
                break

            if isinstance(target, PythonBinary):
                if self.binary:
                    self.error(
                        'Can only process 1 binary target. Found %s and %s.' %
                        (self.binary, target))
                else:
                    self.binary = target
            self.targets.append(target)

        if not self.targets:
            self.error('No valid targets specified!')