Example #1
0
    def test_setup_using_eggs(self):
        def link_egg(repo_root, requirement):
            existing_dist_location = self._interpreter.get_location(
                requirement)
            if existing_dist_location is not None:
                existing_dist = Package.from_href(existing_dist_location)
                requirement = '{}=={}'.format(existing_dist.name,
                                              existing_dist.raw_version)

            distributions = resolve([requirement],
                                    interpreter=self._interpreter,
                                    precedence=(EggPackage, SourcePackage))
            self.assertEqual(1, len(distributions))
            dist_location = distributions[0].location

            self.assertRegexpMatches(dist_location, r'\.egg$')
            os.symlink(
                dist_location,
                os.path.join(repo_root, os.path.basename(dist_location)))

            return Package.from_href(dist_location).raw_version

        with temporary_dir() as root:
            egg_dir = os.path.join(root, 'eggs')
            os.makedirs(egg_dir)
            setuptools_version = link_egg(egg_dir, 'setuptools')
            wheel_version = link_egg(egg_dir, 'wheel')

            interpreter_requirement = self._interpreter.identity.requirement
            python_setup = create_subsystem(
                PythonSetup,
                interpreter_cache_dir=None,
                pants_workdir=os.path.join(root, 'workdir'),
                interpreter_requirement=interpreter_requirement,
                setuptools_version=setuptools_version,
                wheel_version=wheel_version)
            python_repos = create_subsystem(PythonRepos,
                                            indexes=[],
                                            repos=[egg_dir])
            cache = PythonInterpreterCache(python_setup, python_repos)

            interpereters = cache.setup(
                paths=[os.path.dirname(self._interpreter.binary)],
                filters=[str(interpreter_requirement)])
            self.assertGreater(len(interpereters), 0)

            def assert_egg_extra(interpreter, name, version):
                location = interpreter.get_location('{}=={}'.format(
                    name, version))
                self.assertIsNotNone(location)
                self.assertIsInstance(Package.from_href(location), EggPackage)

            for interpreter in interpereters:
                assert_egg_extra(interpreter, 'setuptools', setuptools_version)
                assert_egg_extra(interpreter, 'wheel', wheel_version)
Example #2
0
  def dumped_chroot(self, targets):
    python_repos = create_subsystem(PythonRepos)

    with subsystem_instance(IvySubsystem) as ivy_subsystem:
      ivy_bootstrapper = Bootstrapper(ivy_subsystem=ivy_subsystem)

      with subsystem_instance(ThriftBinary.Factory) as thrift_binary_factory:
        interpreter_cache = PythonInterpreterCache(self.python_setup, python_repos)
        interpreter_cache.setup()
        interpreters = list(interpreter_cache.matched_interpreters([
          self.python_setup.interpreter_requirement]))
        self.assertGreater(len(interpreters), 0)
        interpreter = interpreters[0]

        with temporary_dir() as chroot:
          pex_builder = PEXBuilder(path=chroot, interpreter=interpreter)

          python_chroot = PythonChroot(python_setup=self.python_setup,
                                       python_repos=python_repos,
                                       ivy_bootstrapper=ivy_bootstrapper,
                                       thrift_binary_factory=thrift_binary_factory.create,
                                       interpreter=interpreter,
                                       builder=pex_builder,
                                       targets=targets,
                                       platforms=['current'])
          try:
            python_chroot.dump()
            yield pex_builder, python_chroot
          finally:
            python_chroot.delete()
Example #3
0
  def test_all_roots(self):
    self.create_dir('contrib/go/examples/3rdparty/go')
    self.create_dir('contrib/go/examples/src/go')
    self.create_dir('src/java')
    self.create_dir('src/python')
    self.create_dir('src/example/java')
    self.create_dir('src/example/python')
    self.create_dir('my/project/src/java')
    self.create_dir('not/a/srcroot/java')

    options = {
      'source_root_patterns': ['src/*', 'src/example/*'],
      # Test that our 'go_remote' hack works.
      # TODO: This will be redundant once we have proper "3rdparty"/"remote" support.
      'source_roots': { 'contrib/go/examples/3rdparty/go': ['go_remote'] }
    }
    options.update(self.options[''])  # We need inherited values for pants_workdir etc.

    source_roots = create_subsystem(SourceRootConfig, **options).get_source_roots()
    self.assertEquals({SourceRoot('contrib/go/examples/3rdparty/go', ('go_remote',)),
                       SourceRoot('contrib/go/examples/src/go', ('go',)),
                       SourceRoot('src/java', ('java',)),
                       SourceRoot('src/python', ('python',)),
                       SourceRoot('src/example/java', ('java',)),
                       SourceRoot('src/example/python', ('python',)),
                       SourceRoot('my/project/src/java', ('java',))},
                      set(source_roots.all_roots()))
Example #4
0
    def dumped_chroot(self, targets):
        python_repos = create_subsystem(PythonRepos)

        with subsystem_instance(IvySubsystem) as ivy_subsystem:
            ivy_bootstrapper = Bootstrapper(ivy_subsystem=ivy_subsystem)

            with subsystem_instance(
                    ThriftBinary.Factory) as thrift_binary_factory:
                interpreter_cache = PythonInterpreterCache(
                    self.python_setup, python_repos)
                interpreter_cache.setup()
                interpreters = list(
                    interpreter_cache.matches(
                        [self.python_setup.interpreter_requirement]))
                self.assertGreater(len(interpreters), 0)
                interpreter = interpreters[0]

                with temporary_dir() as chroot:
                    pex_builder = PEXBuilder(path=chroot,
                                             interpreter=interpreter)

                    python_chroot = PythonChroot(
                        python_setup=self.python_setup,
                        python_repos=python_repos,
                        ivy_bootstrapper=ivy_bootstrapper,
                        thrift_binary_factory=thrift_binary_factory.create,
                        interpreter=interpreter,
                        builder=pex_builder,
                        targets=targets,
                        platforms=['current'])
                    try:
                        python_chroot.dump()
                        yield pex_builder, python_chroot
                    finally:
                        python_chroot.delete()
 def setUp(self):
     super(PantsDaemonLauncherTest, self).setUp()
     self.launcher = create_subsystem(PantsDaemonLauncher,
                                      pants_workdir='/pants_workdir',
                                      level='info')
     self.mock_pantsd = mock.create_autospec(PantsDaemon, spec_set=True)
     self.launcher._pantsd = self.mock_pantsd
 def setUp(self):
   super(PantsDaemonLauncherTest, self).setUp()
   self.launcher = create_subsystem(PantsDaemonLauncher,
                                    pants_workdir='/pants_workdir',
                                    level='info')
   self.mock_pantsd = mock.create_autospec(PantsDaemon, spec_set=True)
   self.launcher.pantsd = self.mock_pantsd
Example #7
0
    def test_collapse_source_root(self):
        source_roots = create_subsystem(SourceRootConfig,
                                        source_roots={
                                            '/src/java': [],
                                            '/tests/java': [],
                                            '/some/other': []
                                        },
                                        unmatched='fail').get_source_roots()
        source_set_list = []
        self.assertEquals([],
                          Project._collapse_by_source_root(
                              source_roots, source_set_list))

        source_sets = [
            SourceSet('/repo-root', 'src/java', 'org/pantsbuild/app', False),
            SourceSet('/repo-root', 'tests/java', 'org/pantsbuild/app', True),
            SourceSet('/repo-root', 'some/other', 'path', False),
        ]

        results = Project._collapse_by_source_root(source_roots, source_sets)

        self.assertEquals(SourceSet('/repo-root', 'src/java', '', False),
                          results[0])
        self.assertFalse(results[0].is_test)
        self.assertEquals(SourceSet('/repo-root', 'tests/java', '', True),
                          results[1])
        self.assertTrue(results[1].is_test)
        # If there is no registered source root, the SourceSet should be returned unmodified
        self.assertEquals(source_sets[2], results[2])
        self.assertFalse(results[2].is_test)
Example #8
0
  def test_setup_using_eggs(self):
    def link_egg(repo_root, requirement):
      existing_dist_location = self._interpreter.get_location(requirement)
      if existing_dist_location is not None:
        existing_dist = Package.from_href(existing_dist_location)
        requirement = '{}=={}'.format(existing_dist.name, existing_dist.raw_version)

      distributions = resolve([requirement],
                              interpreter=self._interpreter,
                              precedence=(EggPackage, SourcePackage))
      self.assertEqual(1, len(distributions))
      dist_location = distributions[0].location

      self.assertRegexpMatches(dist_location, r'\.egg$')
      os.symlink(dist_location, os.path.join(repo_root, os.path.basename(dist_location)))

      return Package.from_href(dist_location).raw_version

    with temporary_dir() as root:
      egg_dir = os.path.join(root, 'eggs')
      os.makedirs(egg_dir)
      setuptools_version = link_egg(egg_dir, 'setuptools')
      wheel_version = link_egg(egg_dir, 'wheel')

      interpreter_requirement = self._interpreter.identity.requirement
      python_setup = create_subsystem(PythonSetup,
                                      interpreter_cache_dir=None,
                                      pants_workdir=os.path.join(root, 'workdir'),
                                      interpreter_requirement=interpreter_requirement,
                                      setuptools_version=setuptools_version,
                                      wheel_version=wheel_version)
      python_repos = create_subsystem(PythonRepos, indexes=[], repos=[egg_dir])
      cache = PythonInterpreterCache(python_setup, python_repos)

      interpereters = cache.setup(paths=[os.path.dirname(self._interpreter.binary)],
                                  filters=[str(interpreter_requirement)])
      self.assertGreater(len(interpereters), 0)

      def assert_egg_extra(interpreter, name, version):
        location = interpreter.get_location('{}=={}'.format(name, version))
        self.assertIsNotNone(location)
        self.assertIsInstance(Package.from_href(location), EggPackage)

      for interpreter in interpereters:
        assert_egg_extra(interpreter, 'setuptools', setuptools_version)
        assert_egg_extra(interpreter, 'wheel', wheel_version)
Example #9
0
  def test_all_roots(self):
    self.create_dir('contrib/go/examples/3rdparty/go')
    self.create_dir('contrib/go/examples/src/go/src')
    self.create_dir('src/java')
    self.create_dir('src/python')
    self.create_dir('src/example/java')
    self.create_dir('src/example/python')
    self.create_dir('my/project/src/java')
    self.create_dir('fixed/root/jvm')
    self.create_dir('not/a/srcroot/java')

    options = {
      'build_file_rev': None,
      'pants_ignore': [],

      'source_root_patterns': ['src/*', 'src/example/*'],
      'source_roots': {
        # Fixed roots should trump patterns which would detect contrib/go/examples/src/go here.
        'contrib/go/examples/src/go/src': ['go'],

        # Test that our 'go_remote' hack works.
        # TODO: This will be redundant once we have proper "3rdparty"/"remote" support.
        'contrib/go/examples/3rdparty/go': ['go_remote'],

        # Dir does not exist, should not be listed as a root.
        'java': ['java']}
    }
    options.update(self.options[''])  # We need inherited values for pants_workdir etc.

    source_roots = create_subsystem(SourceRootConfig, **options).get_source_roots()
    # Ensure that we see any manually added roots.
    source_roots.add_source_root('fixed/root/jvm', ('java', 'scala'))
    source_roots.all_roots()

    self.assertEquals({SourceRoot('contrib/go/examples/3rdparty/go', ('go_remote',)),
                       SourceRoot('contrib/go/examples/src/go/src', ('go',)),
                       SourceRoot('src/java', ('java',)),
                       SourceRoot('src/python', ('python',)),
                       SourceRoot('src/example/java', ('java',)),
                       SourceRoot('src/example/python', ('python',)),
                       SourceRoot('my/project/src/java', ('java',)),
                       SourceRoot('fixed/root/jvm', ('java','scala'))},
                      set(source_roots.all_roots()))
Example #10
0
  def test_collapse_source_root(self):
    source_roots = create_subsystem(SourceRootConfig, source_roots={
      '/src/java': [],
      '/tests/java': [],
      '/some/other': []
    }, unmatched='fail').get_source_roots()
    source_set_list = []
    self.assertEquals([], Project._collapse_by_source_root(source_roots, source_set_list))

    source_sets = [
      SourceSet('/repo-root', 'src/java', 'org/pantsbuild/app', False),
      SourceSet('/repo-root', 'tests/java', 'org/pantsbuild/app', True),
      SourceSet('/repo-root', 'some/other', 'path', False),
    ]

    results = Project._collapse_by_source_root(source_roots, source_sets)

    self.assertEquals(SourceSet('/repo-root', 'src/java', '', False), results[0])
    self.assertFalse(results[0].is_test)
    self.assertEquals(SourceSet('/repo-root', 'tests/java', '', True), results[1])
    self.assertTrue(results[1].is_test)
    # If there is no registered source root, the SourceSet should be returned unmodified
    self.assertEquals(source_sets[2], results[2])
    self.assertFalse(results[2].is_test)
 def create_strategy(self, option_values):
   thrift_defaults = create_subsystem(ThriftDefaults, **option_values)
   return JavaThriftLibraryFingerprintStrategy(thrift_defaults)
Example #12
0
 def create_strategy(self, option_values):
     thrift_defaults = create_subsystem(ThriftDefaults, **option_values)
     return JavaThriftLibraryFingerprintStrategy(thrift_defaults)
Example #13
0
 def setUp(self):
     BaseTest.setUp(self)
     self.watchman_launcher = create_subsystem(
         WatchmanLauncher, pants_workdir='/pants_workdir', level='info')