예제 #1
0
    def test_locate(self):
        with pytest.raises(ParseContext.ContextError):
            ParseContext.locate()

        with temporary_dir() as root_dir:
            a_context = ParseContext(create_buildfile(root_dir, 'a'))
            b_context = ParseContext(create_buildfile(root_dir, 'b'))

            def test_in_a():
                self.assertEquals(a_context, ParseContext.locate())
                return b_context.do_in_context(lambda: ParseContext.locate())

            self.assertEquals(b_context, a_context.do_in_context(test_in_a))
예제 #2
0
  def test_locate(self):
    with pytest.raises(ParseContext.ContextError):
      ParseContext.locate()

    with temporary_dir() as root_dir:
      a_context = ParseContext(create_buildfile(root_dir, 'a'))
      b_context = ParseContext(create_buildfile(root_dir, 'b'))

      def test_in_a():
        self.assertEquals(a_context, ParseContext.locate())
        return b_context.do_in_context(lambda: ParseContext.locate())

      self.assertEquals(b_context, a_context.do_in_context(test_in_a))
예제 #3
0
    def __init__(self, spec, exclusives=None):
        """
    :param string spec: target address. E.g.,
      src/main/java/com/twitter/common/util/BUILD:util
    """
        # it's critical the spec is parsed 1st, the results are needed elsewhere in constructor flow
        parse_context = ParseContext.locate()

        def parse_address():
            if spec.startswith(':'):
                # the :[target] could be in a sibling BUILD - so parse using the canonical address
                pathish = "%s:%s" % (parse_context.buildfile.canonical_relpath,
                                     spec[1:])
                return Address.parse(parse_context.buildfile.root_dir, pathish,
                                     False)
            else:
                return Address.parse(parse_context.buildfile.root_dir, spec,
                                     False)

        try:
            self.address = parse_address()
        except IOError as e:
            self.address = parse_context.buildfile.relpath
            raise TargetDefinitionException(
                self, '%s%s' % (self._DEFINITION_ERROR_MSG, e))

        # We must disable the re-init check, because our funky __getattr__ breaks it.
        # We're not involved in any multiple inheritance, so it's OK to disable it here.
        super(Pants, self).__init__(self.address.target_name,
                                    reinit_check=False,
                                    exclusives=exclusives)
예제 #4
0
    def __init__(self, spec, exclusives=None):
        """
    :param string spec: target address. E.g., `src/java/com/twitter/common/util/BUILD\:util`
    """
        # it's critical the spec is parsed 1st, the results are needed elsewhere in constructor flow
        parse_context = ParseContext.locate()

        def parse_address():
            if spec.startswith(':'):
                # the :[target] could be in a sibling BUILD - so parse using the canonical address
                pathish = "%s:%s" % (parse_context.buildfile.canonical_relpath,
                                     spec[1:])
                return Address.parse(parse_context.buildfile.root_dir, pathish,
                                     False)
            else:
                return Address.parse(parse_context.buildfile.root_dir, spec,
                                     False)

        try:
            self.address = parse_address()
        except IOError as e:
            self.address = parse_context.buildfile.relpath
            raise TargetDefinitionException(
                self, '%s%s' % (self._DEFINITION_ERROR_MSG, e))

        # We must disable the re-init check, because our funky __getattr__ breaks it.
        # We're not involved in any multiple inheritance, so it's OK to disable it here.
        super(Pants, self).__init__(
            self.address.target_name,
            reinit_check=False,
            exclusives=exclusives)
예제 #5
0
 def __init__(self, target, msg):
   address = getattr(target, 'address', None)
   if address is None:
     try:
       location = ParseContext.locate().current_buildfile
     except ParseContext.ContextError:
       location = 'unknown location'
     address = 'unknown target of type %s in %s' % (target.__class__.__name__, location)
   super(Exception, self).__init__('Error with %s: %s' % (address, msg))
예제 #6
0
 def __init__(self, target, msg):
     address = getattr(target, 'address', None)
     if address is None:
         try:
             location = ParseContext.locate().current_buildfile
         except ParseContext.ContextError:
             location = 'unknown location'
         address = 'unknown target of type %s in %s' % (
             target.__class__.__name__, location)
     super(Exception, self).__init__('Error with %s: %s' % (address, msg))
예제 #7
0
    def __init__(self, name, reinit_check=True, exclusives=None):
        """
    :param string name: The target name.
    """
        # See "get_all_exclusives" below for an explanation of the exclusives parameter.
        # This check prevents double-initialization in multiple-inheritance situations.
        # TODO(John Sirois): fix target inheritance - use super() to linearize or use alternatives to
        # multiple inheritance.
        if not reinit_check or not hasattr(self, '_initialized'):
            if not isinstance(name, Compatibility.string):
                self.address = '%s:%s' % (
                    ParseContext.locate().current_buildfile, str(name))
                raise TargetDefinitionException(
                    self, "Invalid target name: %s" % name)
            self.name = name
            self.description = None

            self.address = self._locate()

            # TODO(John Sirois): Transition all references to self.identifier to eliminate id builtin
            # ambiguity
            self.id = self._create_id()

            self._register()

            self.labels = set()

            self._initialized = True

            self.declared_exclusives = collections.defaultdict(set)
            if exclusives is not None:
                for k in exclusives:
                    self.declared_exclusives[k].add(exclusives[k])
            self.exclusives = None

            # For synthetic codegen targets this will be the original target from which
            # the target was synthesized.
            self._derived_from = self
예제 #8
0
  def __init__(self, name, reinit_check=True, exclusives=None):
    """
    :param string name: The target name.
    """
    # See "get_all_exclusives" below for an explanation of the exclusives parameter.
    # This check prevents double-initialization in multiple-inheritance situations.
    # TODO(John Sirois): fix target inheritance - use super() to linearize or use alternatives to
    # multiple inheritance.
    if not reinit_check or not hasattr(self, '_initialized'):
      if not isinstance(name, Compatibility.string):
        self.address = '%s:%s' % (ParseContext.locate().current_buildfile, str(name))
        raise TargetDefinitionException(self, "Invalid target name: %s" % name)
      self.name = name
      self.description = None

      self.address = self._locate()

      # TODO(John Sirois): Transition all references to self.identifier to eliminate id builtin
      # ambiguity
      self.id = self._create_id()

      self._register()

      self.labels = set()

      self._initialized = True

      self.declared_exclusives = collections.defaultdict(set)
      if exclusives is not None:
        for k in exclusives:
          self.declared_exclusives[k].add(exclusives[k])
      self.exclusives = None

      # For synthetic codegen targets this will be the original target from which
      # the target was synthesized.
      self._derived_from = self
예제 #9
0
 def test_in_a():
   self.assertEquals(a_context, ParseContext.locate())
   return b_context.do_in_context(lambda: ParseContext.locate())
예제 #10
0
 def _locate(self):
   parse_context = ParseContext.locate()
   return Address(parse_context.current_buildfile, self.name)
예제 #11
0
 def _post_construct(self, func, *args, **kwargs):
   """Registers a command to invoke after this target's BUILD file is parsed."""
   ParseContext.locate().on_context_exit(func, *args, **kwargs)
예제 #12
0
파일: target.py 프로젝트: wickman/commons
 def locate(self):
     parse_context = ParseContext.locate()
     return Address(parse_context.buildfile, self.name)
예제 #13
0
파일: target.py 프로젝트: wickman/commons
    def _post_construct(self, func, *args, **kwargs):
        """Registers a command to invoke after this target's BUILD file is parsed."""

        ParseContext.locate().on_context_exit(func, *args, **kwargs)
예제 #14
0
파일: target.py 프로젝트: SeungEun/commons
 def locate(self):
   parse_context = ParseContext.locate()
   return Address(parse_context.buildfile, self.name, self.is_meta)
예제 #15
0
 def test_in_a():
     self.assertEquals(a_context, ParseContext.locate())
     return b_context.do_in_context(lambda: ParseContext.locate())