Exemplo n.º 1
0
  def test_locate(self):
    with pytest.raises(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))
Exemplo n.º 2
0
    def test_locate(self):
        with pytest.raises(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))
Exemplo n.º 3
0
 def __init__(self, name,
              sources = None,
              resources = None,
              dependencies = None,
              module = "",
              module_root = "src/python"):
   """
     name = Name of library
     sources = Python source files
     resources = non-Python resources, e.g. templates, keys, other data (it is
       recommended that your application uses the pkgutil package to access these
       resources in a .zip-module friendly way.)
     dependencies = other PythonLibraries, Eggs or internal Pants targets
     module = everything beneath module_root is relative to this module name, None if root namespace
     module_root = see above
   """
   context = ParseContext.locate()
   self._module = module
   PythonTarget.__init__(
     self,
     module_root,
     name,
     sources,
     resources,
     dependencies,
     False)
Exemplo n.º 4
0
  def __init__(self, spec):
    # 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)

    self.address = parse_address()

    Target.__init__(self, self.address.target_name, False)
Exemplo n.º 5
0
  def __init__(self, spec):
    # 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)

    self.address = parse_address()
    # 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.
    Target.__init__(self, self.address.target_name, False, reinit_check=False)
Exemplo n.º 6
0
    def __init__(self, spec):
        # 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)

        self.address = parse_address()

        Target.__init__(self, self.address.target_name, False)
Exemplo n.º 7
0
    def __init__(self, spec):
        # 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)

        self.address = parse_address()

        # 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.
        Target.__init__(self, self.address.target_name, reinit_check=False)
Exemplo n.º 8
0
 def __init__(self,
              name,
              sources=None,
              resources=None,
              dependencies=None,
              module="",
              module_root="src/python"):
     """
   name = Name of library
   sources = Python source files
   resources = non-Python resources, e.g. templates, keys, other data (it is
     recommended that your application uses the pkgutil package to access these
     resources in a .zip-module friendly way.)
   dependencies = other PythonLibraries, Eggs or internal Pants targets
   module = everything beneath module_root is relative to this module name, None if root namespace
   module_root = see above
 """
     context = ParseContext.locate()
     self._module = module
     PythonTarget.__init__(self, module_root, name, sources, resources,
                           dependencies, False)
Exemplo n.º 9
0
  def test_on_context_exit(self):
    with temporary_dir() as root_dir:
      parse_context = ParseContext(create_buildfile(root_dir, 'a'))
      with pytest.raises(ContextError):
        parse_context.on_context_exit(lambda: 37)

    with temporary_dir() as root_dir:
      buildfile = create_buildfile(root_dir, 'a',
'''import os
from twitter.pants.base import ParseContext
def leave_a_trail(file, contents=''):
  with open(file, 'w') as b:
    b.write(contents)
b_file = os.path.join(os.path.dirname(__file__), 'b')
ParseContext.locate().on_context_exit(leave_a_trail, b_file, contents='42')
assert not os.path.exists(b_file), 'Expected context exit action to be delayed.'
'''.strip())
      b_file = os.path.join(root_dir, 'a', 'b')
      self.assertFalse(os.path.exists(b_file))
      ParseContext(buildfile).parse()
      with open(b_file, 'r') as b:
        self.assertEquals('42', b.read())
Exemplo n.º 10
0
    def test_on_context_exit(self):
        with temporary_dir() as root_dir:
            parse_context = ParseContext(create_buildfile(root_dir, 'a'))
            with pytest.raises(ContextError):
                parse_context.on_context_exit(lambda: 37)

        with temporary_dir() as root_dir:
            buildfile = create_buildfile(
                root_dir, 'a', '''import os
from twitter.pants.base import ParseContext
def leave_a_trail(file, contents=''):
  with open(file, 'w') as b:
    b.write(contents)
b_file = os.path.join(os.path.dirname(__file__), 'b')
ParseContext.locate().on_context_exit(leave_a_trail, b_file, contents='42')
assert not os.path.exists(b_file), 'Expected context exit action to be delayed.'
'''.strip())
            b_file = os.path.join(root_dir, 'a', 'b')
            self.assertFalse(os.path.exists(b_file))
            ParseContext(buildfile).parse()
            with open(b_file, 'r') as b:
                self.assertEquals('42', b.read())
Exemplo n.º 11
0
 def test_in_a():
   self.assertEquals(a_context, ParseContext.locate())
   return b_context.do_in_context(lambda: ParseContext.locate())
Exemplo n.º 12
0
 def test_in_a():
     self.assertEquals(a_context, ParseContext.locate())
     return b_context.do_in_context(lambda: ParseContext.locate())