コード例 #1
0
 def test_walk_addressables(self):
   self.assertEqual(sorted([(self.addr('//:root'), Configuration(name='root')),
                            (self.addr('a/b:b'), self.a_b_target),
                            (self.addr('a/d:d'), Target(name='d')),
                            (self.addr('a/d/e:e'), Target(name='e')),
                            (self.addr('a/d/e:e-prime'), Configuration(name='e-prime'))]),
                    sorted(self.address_mapper.walk_addressables()))
コード例 #2
0
ファイル: test_mapper.py プロジェクト: cheister/pants
 def test_walk_addressables_rel_path(self):
     self.assertEqual(
         {
             self.addr('a/d:d'): Target(name='d'),
             self.addr('a/d/e:e'): Target(name='e'),
             self.addr('a/d/e:e-prime'): Struct(name='e-prime')
         }, self.resolve_multi(DescendantAddresses('a/d')))
コード例 #3
0
    def do_test_codegen_simple(self, graph):
        def address(name):
            return Address(spec_path='examples/graph_test', target_name=name)

        resolved_java1 = graph.resolve(address('java1'))

        nonstrict = ApacheThriftConfiguration(address=address('nonstrict'),
                                              version='0.9.2',
                                              strict=False,
                                              lang='java')
        public = Struct(address=address('public'),
                        url='https://oss.sonatype.org/#stagingRepositories')
        thrift1 = Target(address=address('thrift1'))
        thrift2 = Target(address=address('thrift2'), dependencies=[thrift1])
        expected_java1 = Target(
            address=address('java1'),
            configurations=[
                ApacheThriftConfiguration(version='0.9.2',
                                          strict=True,
                                          lang='java'), nonstrict,
                PublishConfiguration(
                    default_repo=public,
                    repos={
                        'jake':
                        Struct(url='https://dl.bintray.com/pantsbuild/maven'),
                        'jane':
                        public
                    })
            ],
            dependencies=[thrift2])

        self.assertEqual(expected_java1, resolved_java1)
コード例 #4
0
ファイル: test_mapper.py プロジェクト: cheister/pants
 def test_walk_addressables(self):
     self.assertEqual(
         {
             self.addr('//:root'): Struct(name='root'),
             self.addr('a/b:b'): self.a_b_target,
             self.addr('a/d:d'): Target(name='d'),
             self.addr('a/d/e:e'): Target(name='e'),
             self.addr('a/d/e:e-prime'): Struct(name='e-prime')
         }, self.resolve_multi(DescendantAddresses('')))
コード例 #5
0
ファイル: test_mapper.py プロジェクト: youprofit/pants
 def test_resolve(self):
     resolved = self.address_mapper.resolve(Address.parse('a/b'))
     self.assertEqual(
         Target(name='b',
                dependencies=['//d:e'],
                configurations=['//a', Configuration(embedded='yes')]),
         resolved)
コード例 #6
0
ファイル: test_mapper.py プロジェクト: youprofit/pants
    def test_invalidate_build_file_added(self):
        address_family = self.address_mapper.family('a/b')

        a_b_target = Target(
            name='b',
            dependencies=['//d:e'],
            configurations=['//a', Configuration(embedded='yes')])
        self.assertEqual({Address.parse('a/b'): a_b_target},
                         address_family.addressables)

        with open(os.path.join(self.build_root, 'a/b/sibling.BUILD.json'),
                  'w') as fp:
            fp.write('{"typename": "configuration", "name": "c"}')

        still_valid = self.address_mapper.family('a/b')
        self.assertIs(address_family, still_valid)

        self.address_mapper.invalidate_build_file('a/b/sibling.BUILD.json')
        newly_formed = self.address_mapper.family('a/b')
        self.assertIsNot(address_family, newly_formed)
        self.assertEqual(
            {
                Address.parse('a/b'): a_b_target,
                Address.parse('a/b:c'): Configuration(name='c')
            }, newly_formed.addressables)
コード例 #7
0
  def setUp(self):
    self.work_dir = safe_mkdtemp()
    self.addCleanup(safe_rmtree, self.work_dir)
    self.build_root = os.path.join(self.work_dir, 'build_root')
    shutil.copytree(os.path.join(os.path.dirname(__file__), 'examples/mapper_test'),
                    self.build_root)

    parser = partial(parse_json, symbol_table={'configuration': Configuration, 'target': Target})
    self.address_mapper = AddressMapper(build_root=self.build_root,
                                        build_pattern=r'.+\.BUILD.json$',
                                        parser=parser)

    self.a_b_target = Target(name='b',
                             dependencies=['//d:e'],
                             configurations=['//a', Configuration(embedded='yes')])
コード例 #8
0
ファイル: test_mapper.py プロジェクト: youprofit/pants
    def test_invalidation_relative(self):
        resolved = self.address_mapper.resolve(Address.parse('a/b'))
        a_b_target = Target(
            name='b',
            dependencies=['//d:e'],
            configurations=['//a', Configuration(embedded='yes')])
        self.assertEqual(a_b_target, resolved)

        build_file = os.path.join(self.build_root, 'a/b/b.BUILD.json')
        os.unlink(build_file)
        self.assertIs(resolved,
                      self.address_mapper.resolve(Address.parse('a/b')))

        self.address_mapper.invalidate_build_file('a/b/b.BUILD.json')
        with self.assertRaises(ResolveError):
            self.address_mapper.resolve(Address.parse('a/b'))
コード例 #9
0
ファイル: test_mapper.py プロジェクト: will-horning/pants
    def setUp(self):
        self.work_dir = safe_mkdtemp()
        self.addCleanup(safe_rmtree, self.work_dir)
        self.build_root = os.path.join(self.work_dir, 'build_root')
        shutil.copytree(
            os.path.join(os.path.dirname(__file__), 'examples/mapper_test'),
            self.build_root)

        self.address_mapper = AddressMapper(build_root=self.build_root,
                                            symbol_table_cls=TargetTable,
                                            parser_cls=JsonParser,
                                            build_pattern=r'.+\.BUILD.json$')

        self.a_b_target = Target(
            name='b',
            dependencies=['//d:e'],
            configurations=['//a', Struct(embedded='yes')])
コード例 #10
0
    def plan(self, scheduler, product_type, subject, configuration=None):
        thrift_sources = list(
            subject.sources.iter_paths(base_path=subject.address.spec_path,
                                       ext='.thrift'))
        if not thrift_sources:
            raise self.Error('No thrift sources for {!r} from {!r}.'.format(
                product_type, subject))

        config = self._extract_thrift_config(product_type,
                                             subject,
                                             configuration=configuration)
        subject = Subject(subject, alternate=Target(dependencies=config.deps))
        inputs = self.plan_parameters(scheduler, product_type, subject, config)
        return Plan(func_or_task_type=self.gen_func,
                    subjects=(subject, ),
                    sources=thrift_sources,
                    **inputs)
コード例 #11
0
ファイル: test_mapper.py プロジェクト: youprofit/pants
    def test_invalidation_un_normalized(self):
        resolved = self.address_mapper.resolve(Address.parse('a/b'))
        a_b_target = Target(
            name='b',
            dependencies=['//d:e'],
            configurations=['//a', Configuration(embedded='yes')])
        self.assertEqual(a_b_target, resolved)

        os.unlink(os.path.join(self.build_root, 'a/b/b.BUILD.json'))
        self.assertIs(resolved,
                      self.address_mapper.resolve(Address.parse('a/b')))

        un_normalized_build_root = os.path.join(self.work_dir,
                                                'build_root_linked')
        os.symlink(self.build_root, un_normalized_build_root)
        un_normalized_build_file = os.path.join(un_normalized_build_root,
                                                'a/b/b.BUILD.json')
        self.address_mapper.invalidate_build_file(un_normalized_build_file)
        with self.assertRaises(ResolveError):
            self.address_mapper.resolve(Address.parse('a/b'))
コード例 #12
0
    def plan(self, scheduler, product_type, subject, configuration=None):
        if not isinstance(subject, Target):
            return None

        thrift_sources = list(
            subject.sources.iter_paths(base_path=subject.address.spec_path,
                                       ext='.thrift'))
        if not thrift_sources:
            return None

        config = self.extract_thrift_config(product_type,
                                            subject,
                                            configuration=configuration)
        if config is None:
            return None

        subject = Subject(subject, alternate=Target(dependencies=config.deps))
        inputs = self.plan_parameters(scheduler, product_type, subject, config)
        return Plan(func_or_task_type=self.gen_func,
                    subjects=(subject, ),
                    sources=thrift_sources,
                    **inputs)
コード例 #13
0
ファイル: test_mapper.py プロジェクト: cheister/pants
    def setUp(self):
        self.work_dir = safe_mkdtemp()
        self.addCleanup(safe_rmtree, self.work_dir)
        self.build_root = os.path.join(self.work_dir, 'build_root')
        shutil.copytree(
            os.path.join(os.path.dirname(__file__), 'examples/mapper_test'),
            self.build_root)

        self._goal = 'list'
        symbol_table_cls = TargetTable
        self.address_mapper = AddressMapper(symbol_table_cls=symbol_table_cls,
                                            parser_cls=JsonParser,
                                            build_pattern=r'.+\.BUILD.json$')
        tasks = (create_fs_tasks(self.build_root) +
                 create_graph_tasks(self.address_mapper, symbol_table_cls))
        self.scheduler = LocalScheduler({self._goal: UnhydratedStruct},
                                        symbol_table_cls, tasks)

        self.a_b = Address.parse('a/b')
        self.a_b_target = Target(
            name='b',
            dependencies=['//d:e'],
            configurations=['//a', Struct(embedded='yes')])
コード例 #14
0
    def do_test_codegen_simple(self, graph):
        def address(name):
            return Address(spec_path='examples/graph_test', target_name=name)

        def resolver(addr):
            return Resolver(graph, addr)

        java1_address = address('java1')
        resolved_java1 = graph.resolve(java1_address)

        nonstrict_address = address('nonstrict')
        public_address = address('public')
        thrift2_address = address('thrift2')
        expected_java1 = Target(
            address=java1_address,
            sources={},
            configurations=[
                ApacheThriftConfiguration(
                    version='0.9.2',
                    strict=True,
                    lang='java',
                    dependencies=[resolver(thrift2_address)]),
                resolver(nonstrict_address),
                PublishConfiguration(
                    default_repo=resolver(public_address),
                    repos={
                        'jake':
                        Struct(url='https://dl.bintray.com/pantsbuild/maven'),
                        'jane':
                        resolver(public_address)
                    })
            ])

        self.assertEqual(expected_java1, resolved_java1)

        expected_nonstrict = ApacheThriftConfiguration(
            address=nonstrict_address,
            version='0.9.2',
            strict=False,
            lang='java')
        resolved_nonstrict = graph.resolve(nonstrict_address)
        self.assertEqual(expected_nonstrict, resolved_nonstrict)
        self.assertEqual(expected_nonstrict, expected_java1.configurations[1])
        self.assertIs(expected_java1.configurations[1], resolved_nonstrict)

        expected_public = Struct(
            address=public_address,
            url='https://oss.sonatype.org/#stagingRepositories')
        resolved_public = graph.resolve(public_address)
        self.assertEqual(expected_public, resolved_public)
        self.assertEqual(expected_public,
                         expected_java1.configurations[2].default_repo)
        self.assertEqual(expected_public,
                         expected_java1.configurations[2].repos['jane'])
        self.assertIs(expected_java1.configurations[2].default_repo,
                      resolved_public)
        self.assertIs(expected_java1.configurations[2].repos['jane'],
                      resolved_public)

        thrift1_address = address('thrift1')
        expected_thrift2 = Target(address=thrift2_address,
                                  dependencies=[resolver(thrift1_address)])
        resolved_thrift2 = graph.resolve(thrift2_address)
        self.assertEqual(expected_thrift2, resolved_thrift2)
        resolved_thrift_config = [
            config for config in resolved_java1.configurations
            if isinstance(config, ApacheThriftConfiguration)
        ]
        self.assertEqual(expected_thrift2,
                         resolved_thrift_config[0].dependencies[0])
        self.assertIs(resolved_thrift_config[0].dependencies[0],
                      resolved_thrift2)

        expected_thrift1 = Target(address=thrift1_address)
        resolved_thrift1 = graph.resolve(thrift1_address)
        self.assertEqual(expected_thrift1, resolved_thrift1)
        self.assertEqual(expected_thrift1, resolved_thrift2.dependencies[0])
        self.assertIs(resolved_thrift2.dependencies[0], resolved_thrift1)
コード例 #15
0
ファイル: test_mapper.py プロジェクト: hardiku/pants
 def test_walk_addressables_path_excludes(self):
     self.assertEqual([(self.addr('//:root'), Struct(name='root')),
                       (self.addr('a/d:d'), Target(name='d'))],
                      list(
                          self.address_mapper.walk_addressables(
                              path_excludes=['a/b', 'a/d/e'])))
コード例 #16
0
ファイル: test_mapper.py プロジェクト: hardiku/pants
 def test_walk_addressables_rel_path(self):
     self.assertEqual(
         sorted([(self.addr('a/d:d'), Target(name='d')),
                 (self.addr('a/d/e:e'), Target(name='e')),
                 (self.addr('a/d/e:e-prime'), Struct(name='e-prime'))]),
         sorted(self.address_mapper.walk_addressables(rel_path='a/d')))
コード例 #17
0
    def do_test_codegen_simple(self, scheduler):
        def address(name):
            return Address(spec_path='examples/graph_test', target_name=name)

        java1_address = address('java1')
        resolved_java1 = self.resolve(scheduler, java1_address)

        nonstrict_address = address('nonstrict')
        expected_nonstrict = ApacheThriftConfiguration(
            address=nonstrict_address,
            version='0.9.2',
            strict=False,
            lang='java')

        public_address = address('public')
        expected_public = Struct(
            address=public_address,
            url='https://oss.sonatype.org/#stagingRepositories')

        thrift2_address = address('thrift2')
        expected_java1 = Target(
            address=java1_address,
            sources={},
            configurations=[
                PublishConfiguration(
                    default_repo=expected_public,
                    repos={
                        'jake':
                        Struct(url='https://dl.bintray.com/pantsbuild/maven'),
                        'jane':
                        expected_public
                    }),
                expected_nonstrict,
                ApacheThriftConfiguration(
                    version='0.9.2',
                    strict=True,
                    lang='java',
                    dependencies=[address(thrift2_address)]),
            ])

        self.assertEqual(expected_java1, resolved_java1)

        resolved_nonstrict = self.resolve(scheduler, nonstrict_address)
        self.assertEqual(expected_nonstrict, resolved_nonstrict)
        self.assertEqual(expected_nonstrict, expected_java1.configurations[1])
        self.assertIs(resolved_java1.configurations[1], resolved_nonstrict)

        resolved_public = self.resolve(scheduler, public_address)
        self.assertEqual(expected_public, resolved_public)
        self.assertEqual(expected_public,
                         expected_java1.configurations[0].default_repo)
        self.assertEqual(expected_public,
                         expected_java1.configurations[0].repos['jane'])
        self.assertIs(resolved_java1.configurations[0].default_repo,
                      resolved_public)
        self.assertIs(resolved_java1.configurations[0].repos['jane'],
                      resolved_public)

        # NB: `dependencies` lists must be explicitly requested by tasks, so we expect an Address.
        thrift1_address = address('thrift1')
        expected_thrift2 = Target(address=thrift2_address,
                                  dependencies=[thrift1_address])
        resolved_thrift2 = self.resolve(scheduler, thrift2_address)
        self.assertEqual(expected_thrift2, resolved_thrift2)

        expected_thrift1 = Target(address=thrift1_address)
        resolved_thrift1 = self.resolve(scheduler, thrift1_address)
        self.assertEqual(expected_thrift1, resolved_thrift1)
コード例 #18
0
ファイル: test_mapper.py プロジェクト: cheister/pants
 def test_walk_addressables_path_excludes(self):
     self.assertEqual(
         {
             self.addr('//:root'): Struct(name='root'),
             self.addr('a/d:d'): Target(name='d')
         }, self.resolve_multi(DescendantAddresses('')))