Exemple #1
0
    def test_binary_target_injected_into_minified_dependencies_with_provider(
            self):
        with ParseContext.temp():
            bar = python_library(name='bar',
                                 provides=setup_py(
                                     name='bar',
                                     version='0.0.0',
                                 ).with_binaries(bar_binary=pants(':bar_bin')))

            bar_bin = python_binary(name='bar_bin',
                                    entry_point='bar.bin.bar',
                                    dependencies=[pants(':bar_bin_dep')])

            bar_bin_dep = python_library(name='bar_bin_dep',
                                         provides=setup_py(
                                             name='bar_bin_dep',
                                             version='0.0.0',
                                         ))

        assert SetupPy.minified_dependencies(bar) == OrderedSet(
            [bar_bin, bar_bin_dep])
        entry_points = dict(SetupPy.iter_entry_points(bar))
        assert entry_points == {'bar_binary': 'bar.bin.bar'}

        with self.run_execute(bar, recursive=False) as setup_py_command:
            setup_py_command.run_one.assert_called_with(bar)

        with self.run_execute(bar, recursive=True) as setup_py_command:
            setup_py_command.run_one.assert_has_calls(
                [call(bar), call(bar_bin_dep)], any_order=True)
Exemple #2
0
 def test_minified_dependencies_1(self):
   # foo -> bar -> baz
   dep_map = {'foo': ['bar'], 'bar': ['baz'], 'baz': []}
   target_map = create_dependencies(dep_map)
   assert SetupPy.minified_dependencies(target_map['foo']) == OrderedSet([target_map['bar']])
   assert SetupPy.minified_dependencies(target_map['bar']) == OrderedSet([target_map['baz']])
   assert SetupPy.minified_dependencies(target_map['baz']) == OrderedSet()
Exemple #3
0
  def test_binary_target_injected_into_minified_dependencies(self):
    with ParseContext.temp():
      foo = python_library(
        name = 'foo',
        provides = setup_py(
          name = 'foo',
          version = '0.0.0',
        ).with_binaries(
          foo_binary = pants(':foo_bin')
        )
      )

      foo_bin = python_binary(
        name = 'foo_bin',
        entry_point = 'foo.bin.foo',
        dependencies = [ pants(':foo_bin_dep') ]
      )

      foo_bin_dep = python_library(
        name = 'foo_bin_dep'
      )

    assert SetupPy.minified_dependencies(foo) == OrderedSet([foo_bin, foo_bin_dep])
    entry_points = dict(SetupPy.iter_entry_points(foo))
    assert entry_points == {'foo_binary': 'foo.bin.foo'}

    with self.run_execute(foo, recursive=False) as setup_py_command:
      setup_py_command.run_one.assert_called_with(foo)

    with self.run_execute(foo, recursive=True) as setup_py_command:
      setup_py_command.run_one.assert_called_with(foo)
Exemple #4
0
 def test_minified_dependencies_1(self):
     # foo -> bar -> baz
     dep_map = {'foo': ['bar'], 'bar': ['baz'], 'baz': []}
     target_map = create_dependencies(dep_map)
     assert SetupPy.minified_dependencies(target_map['foo']) == OrderedSet(
         [target_map['bar']])
     assert SetupPy.minified_dependencies(target_map['bar']) == OrderedSet(
         [target_map['baz']])
     assert SetupPy.minified_dependencies(target_map['baz']) == OrderedSet()
Exemple #5
0
 def test_minified_dependencies_diamond(self):
   #   bar <-- foo --> baz
   #    |               |
   #    `----> bak <----'
   dep_map = {'foo': ['bar', 'baz'], 'bar': ['bak'], 'baz': ['bak'], 'bak': []}
   target_map = create_dependencies(dep_map)
   assert SetupPy.minified_dependencies(target_map['foo']) == OrderedSet(
       [target_map['bar'], target_map['baz']])
   assert SetupPy.minified_dependencies(target_map['bar']) == OrderedSet([target_map['bak']])
   assert SetupPy.minified_dependencies(target_map['baz']) == OrderedSet([target_map['bak']])
Exemple #6
0
    def test_binary_cycle(self):
        with ParseContext.temp():
            foo = python_library(name='foo',
                                 provides=setup_py(
                                     name='foo',
                                     version='0.0.0',
                                 ).with_binaries(foo_binary=pants(':foo_bin')))

            foo_bin = python_binary(name='foo_bin',
                                    entry_point='foo.bin.foo',
                                    dependencies=[pants(':foo')])

        with pytest.raises(TargetDefinitionException):
            SetupPy.minified_dependencies(foo)
Exemple #7
0
 def test_minified_dependencies_diamond(self):
     #   bar <-- foo --> baz
     #    |               |
     #    `----> bak <----'
     dep_map = {
         'foo': ['bar', 'baz'],
         'bar': ['bak'],
         'baz': ['bak'],
         'bak': []
     }
     target_map = create_dependencies(dep_map)
     assert SetupPy.minified_dependencies(target_map['foo']) == OrderedSet(
         [target_map['bar'], target_map['baz']])
     assert SetupPy.minified_dependencies(target_map['bar']) == OrderedSet(
         [target_map['bak']])
     assert SetupPy.minified_dependencies(target_map['baz']) == OrderedSet(
         [target_map['bak']])
Exemple #8
0
def test_find_packages():
  def assert_single_chroot(packages, namespace_packages, resources):
    with yield_chroot(packages, namespace_packages, resources) as chroot:
      p, n_p, r = SetupPy.find_packages(chroot)
      assert p == set(packages + namespace_packages)
      assert n_p == set(namespace_packages)
      assert r == dict((k, set(v)) for (k, v) in resources.items())

  # assert both packages and namespace packages work
  assert_single_chroot(['twitter'], [], {})
  assert_single_chroot(['twitter'], ['twitter'], {})

  # assert resources work
  assert_single_chroot(['twitter'], [], {'twitter': ['blork.dat']})

  resources = {
    'twitter': [
      'README.rst',
      os.path.join('pants', 'templates', 'ivy.mk'),
      os.path.join('pants', 'templates', 'maven.mk'),
    ]
  }
  assert_single_chroot(['twitter'], [], resources)

  # assert that nearest-submodule is honored
  with yield_chroot(['twitter', 'twitter.pants'], [], resources) as chroot:
    _, _, r = SetupPy.find_packages(chroot)
    assert r == {
      'twitter': set(['README.rst']),
      'twitter.pants': set([
        os.path.join('templates', 'ivy.mk'),
        os.path.join('templates', 'maven.mk'),
      ])
    }

  # assert that nearest submodule splits on module prefixes
  with yield_chroot(
      ['twitter', 'twitter.util'],
      [],
      {'twitter.utilization': ['README.rst']}) as chroot:

    _, _, r = SetupPy.find_packages(chroot)
    assert r == {'twitter': set(['utilization/README.rst'])}
Exemple #9
0
def test_find_packages():
    def assert_single_chroot(packages, namespace_packages, resources):
        with yield_chroot(packages, namespace_packages, resources) as chroot:
            p, n_p, r = SetupPy.find_packages(chroot)
            assert p == set(packages + namespace_packages)
            assert n_p == set(namespace_packages)
            assert r == dict((k, set(v)) for (k, v) in resources.items())

    # assert both packages and namespace packages work
    assert_single_chroot(['twitter'], [], {})
    assert_single_chroot(['twitter'], ['twitter'], {})

    # assert resources work
    assert_single_chroot(['twitter'], [], {'twitter': ['blork.dat']})

    resources = {
        'twitter': [
            'README.rst',
            os.path.join('pants', 'templates', 'ivy.mk'),
            os.path.join('pants', 'templates', 'maven.mk'),
        ]
    }
    assert_single_chroot(['twitter'], [], resources)

    # assert that nearest-submodule is honored
    with yield_chroot(['twitter', 'twitter.pants'], [], resources) as chroot:
        _, _, r = SetupPy.find_packages(chroot)
        assert r == {
            'twitter':
            set(['README.rst']),
            'twitter.pants':
            set([
                os.path.join('templates', 'ivy.mk'),
                os.path.join('templates', 'maven.mk'),
            ])
        }

    # assert that nearest submodule splits on module prefixes
    with yield_chroot(['twitter', 'twitter.util'], [],
                      {'twitter.utilization': ['README.rst']}) as chroot:

        _, _, r = SetupPy.find_packages(chroot)
        assert r == {'twitter': set(['utilization/README.rst'])}
Exemple #10
0
  def test_binary_cycle(self):
    with ParseContext.temp():
      foo = python_library(
        name = 'foo',
        provides = setup_py(
          name = 'foo',
          version = '0.0.0',
        ).with_binaries(
          foo_binary = pants(':foo_bin')
        )
      )

      foo_bin = python_binary(
        name = 'foo_bin',
        entry_point = 'foo.bin.foo',
        dependencies = [ pants(':foo') ]
      )

    with pytest.raises(TargetDefinitionException):
      SetupPy.minified_dependencies(foo)
Exemple #11
0
  def test_binary_target_injected_into_minified_dependencies_with_provider(self):
    with ParseContext.temp():
      bar = python_library(
        name = 'bar',
        provides = setup_py(
          name = 'bar',
          version = '0.0.0',
        ).with_binaries(
          bar_binary = pants(':bar_bin')
        )
      )

      bar_bin = python_binary(
        name = 'bar_bin',
        entry_point = 'bar.bin.bar',
        dependencies = [ pants(':bar_bin_dep') ]
      )

      bar_bin_dep = python_library(
        name = 'bar_bin_dep',
        provides = setup_py(
          name = 'bar_bin_dep',
          version = '0.0.0',
        )
      )

    assert SetupPy.minified_dependencies(bar) == OrderedSet([bar_bin, bar_bin_dep])
    entry_points = dict(SetupPy.iter_entry_points(bar))
    assert entry_points == {'bar_binary': 'bar.bin.bar'}

    with self.run_execute(bar, recursive=False) as setup_py_command:
      setup_py_command.run_one.assert_called_with(bar)

    with self.run_execute(bar, recursive=True) as setup_py_command:
      setup_py_command.run_one.assert_has_calls([
          call(bar),
          call(bar_bin_dep)
      ], any_order=True)
Exemple #12
0
    def test_binary_target_injected_into_minified_dependencies(self):
        with ParseContext.temp():
            foo = python_library(name='foo',
                                 provides=setup_py(
                                     name='foo',
                                     version='0.0.0',
                                 ).with_binaries(foo_binary=pants(':foo_bin')))

            foo_bin = python_binary(name='foo_bin',
                                    entry_point='foo.bin.foo',
                                    dependencies=[pants(':foo_bin_dep')])

            foo_bin_dep = python_library(name='foo_bin_dep')

        assert SetupPy.minified_dependencies(foo) == OrderedSet(
            [foo_bin, foo_bin_dep])
        entry_points = dict(SetupPy.iter_entry_points(foo))
        assert entry_points == {'foo_binary': 'foo.bin.foo'}

        with self.run_execute(foo, recursive=False) as setup_py_command:
            setup_py_command.run_one.assert_called_with(foo)

        with self.run_execute(foo, recursive=True) as setup_py_command:
            setup_py_command.run_one.assert_called_with(foo)
Exemple #13
0
def test_nearest_subpackage():
    # degenerate
    assert SetupPy.nearest_subpackage('twitter', []) == 'twitter'
    assert SetupPy.nearest_subpackage('twitter', ['twitter']) == 'twitter'
    assert SetupPy.nearest_subpackage('twitter', ['foursquare']) == 'twitter'

    # common prefix
    assert 'twitter' == SetupPy.nearest_subpackage('twitter.util', ['twitter'])
    assert 'twitter.util' == SetupPy.nearest_subpackage(
        'twitter.util', ['twitter', 'twitter.util'])
    assert 'twitter.util' == SetupPy.nearest_subpackage(
        'twitter.util.topo', ['twitter', 'twitter.util'])
    assert 'twitter' == SetupPy.nearest_subpackage('twitter.utilization',
                                                   ['twitter', 'twitter.util'])
Exemple #14
0
def test_nearest_subpackage():
  # degenerate
  assert SetupPy.nearest_subpackage('twitter', []) == 'twitter'
  assert SetupPy.nearest_subpackage('twitter', ['twitter']) == 'twitter'
  assert SetupPy.nearest_subpackage('twitter', ['foursquare']) == 'twitter'

  # common prefix
  assert 'twitter' == SetupPy.nearest_subpackage('twitter.util', ['twitter'])
  assert 'twitter.util' == SetupPy.nearest_subpackage(
      'twitter.util', ['twitter', 'twitter.util'])
  assert 'twitter.util' == SetupPy.nearest_subpackage(
      'twitter.util.topo', ['twitter', 'twitter.util'])
  assert 'twitter' == SetupPy.nearest_subpackage(
      'twitter.utilization', ['twitter', 'twitter.util'])
Exemple #15
0
 def assert_single_chroot(packages, namespace_packages, resources):
     with yield_chroot(packages, namespace_packages, resources) as chroot:
         p, n_p, r = SetupPy.find_packages(chroot)
         assert p == set(packages + namespace_packages)
         assert n_p == set(namespace_packages)
         assert r == dict((k, set(v)) for (k, v) in resources.items())
Exemple #16
0
 def has_ns(stmt):
     with temporary_file() as fp:
         fp.write(stmt)
         fp.flush()
         return SetupPy.declares_namespace_package(fp.name)
Exemple #17
0
 def has_ns(stmt):
   with temporary_file() as fp:
     fp.write(stmt)
     fp.flush()
     return SetupPy.declares_namespace_package(fp.name)
Exemple #18
0
 def assert_single_chroot(packages, namespace_packages, resources):
   with yield_chroot(packages, namespace_packages, resources) as chroot:
     p, n_p, r = SetupPy.find_packages(chroot)
     assert p == set(packages + namespace_packages)
     assert n_p == set(namespace_packages)
     assert r == dict((k, set(v)) for (k, v) in resources.items())