def test_binary_target_injected_into_reduced_dependencies(self): foo_bin_dep = self.create_python_library(relpath='foo/dep', name='dep') foo_bin = self.create_python_binary( relpath='foo/bin', name='bin', entry_point='foo.bin:foo', dependencies=[ 'foo/dep', ] ) foo = self.create_python_library( relpath='foo', name='foo', provides=dedent(""" setup_py( name='foo', version='0.0.0' ).with_binaries( foo_binary='foo/bin' ) """) ) self.assertEqual(self.dependency_calculator.reduced_dependencies(foo), OrderedSet([foo_bin, foo_bin_dep])) entry_points = dict(SetupPy.iter_entry_points(foo)) self.assertEqual(entry_points, {'foo_binary': 'foo.bin:foo'}) with self.run_execute(foo, recursive=False) as created: self.assertEqual([foo], created.keys()) with self.run_execute(foo, recursive=True) as created: self.assertEqual([foo], created.keys())
def test_binary_target_injected_into_reduced_dependencies(self): foo_bin_dep = self.create_python_library(relpath='foo/dep', name='dep') foo_bin = self.create_python_binary(relpath='foo/bin', name='bin', entry_point='foo.bin:foo', dependencies=[ 'foo/dep', ]) foo = self.create_python_library(relpath='foo', name='foo', provides=dedent(""" setup_py( name='foo', version='0.0.0' ).with_binaries( foo_binary='foo/bin' ) """)) self.assertEqual(self.dependency_calculator.reduced_dependencies(foo), OrderedSet([foo_bin, foo_bin_dep])) entry_points = dict(SetupPy.iter_entry_points(foo)) self.assertEqual(entry_points, {'foo_binary': 'foo.bin:foo'}) with self.run_execute(foo, recursive=False) as created: self.assertEqual([foo], created.keys()) with self.run_execute(foo, recursive=True) as created: self.assertEqual([foo], created.keys())
def setUp(self): super(TestSetupPy, self).setUp() distdir = os.path.join(self.build_root, 'dist') self.set_options(pants_distdir=distdir) init_subsystem(Target.Arguments) self.dependency_calculator = SetupPy.DependencyCalculator( self.build_graph)
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(['foo'], [], {}) assert_single_chroot(['foo'], ['foo'], {}) # assert resources work assert_single_chroot(['foo'], [], {'foo': ['blork.dat']}) resources = { 'foo': [ 'f0', os.path.join('bar', 'baz', 'f1'), os.path.join('bar', 'baz', 'f2'), ] } assert_single_chroot(['foo'], [], resources) # assert that nearest-submodule is honored with yield_chroot(['foo', 'foo.bar'], [], resources) as chroot: _, _, r = SetupPy.find_packages(chroot) assert r == { 'foo': {'f0'}, 'foo.bar': {os.path.join('baz', 'f1'), os.path.join('baz', 'f2')} } # assert that nearest submodule splits on module prefixes with yield_chroot( ['foo', 'foo.bar'], [], {'foo.bar1': ['f0']}) as chroot: _, _, r = SetupPy.find_packages(chroot) assert r == {'foo': {'bar1/f0'}}
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(['foo'], [], {}) assert_single_chroot(['foo'], ['foo'], {}) # assert resources work assert_single_chroot(['foo'], [], {'foo': ['blork.dat']}) resources = { 'foo': [ 'f0', os.path.join('bar', 'baz', 'f1'), os.path.join('bar', 'baz', 'f2'), ] } assert_single_chroot(['foo'], [], resources) # assert that nearest-submodule is honored with yield_chroot(['foo', 'foo.bar'], [], resources) as chroot: _, _, r = SetupPy.find_packages(chroot) assert r == { 'foo': {'f0'}, 'foo.bar': {os.path.join('baz', 'f1'), os.path.join('baz', 'f2')} } # assert that nearest submodule splits on module prefixes with yield_chroot(['foo', 'foo.bar'], [], {'foo.bar1': ['f0']}) as chroot: _, _, r = SetupPy.find_packages(chroot) assert r == {'foo': {'bar1/f0'}}
def test_nearest_subpackage(): # degenerate assert SetupPy.nearest_subpackage('foo', []) == 'foo' assert SetupPy.nearest_subpackage('foo', ['foo']) == 'foo' assert SetupPy.nearest_subpackage('foo', ['bar']) == 'foo' # common prefix assert 'foo' == SetupPy.nearest_subpackage('foo.bar', ['foo']) assert 'foo.bar' == SetupPy.nearest_subpackage('foo.bar', ['foo', 'foo.bar']) assert 'foo.bar' == SetupPy.nearest_subpackage('foo.bar.topo', ['foo', 'foo.bar']) assert 'foo' == SetupPy.nearest_subpackage('foo.barization', ['foo', 'foo.bar'])
def test_nearest_subpackage(): # degenerate assert SetupPy.nearest_subpackage('foo', []) == 'foo' assert SetupPy.nearest_subpackage('foo', ['foo']) == 'foo' assert SetupPy.nearest_subpackage('foo', ['bar']) == 'foo' # common prefix assert 'foo' == SetupPy.nearest_subpackage('foo.bar', ['foo']) assert 'foo.bar' == SetupPy.nearest_subpackage( 'foo.bar', ['foo', 'foo.bar']) assert 'foo.bar' == SetupPy.nearest_subpackage( 'foo.bar.topo', ['foo', 'foo.bar']) assert 'foo' == SetupPy.nearest_subpackage( 'foo.barization', ['foo', 'foo.bar'])
def test_binary_target_injected_into_reduced_dependencies_with_provider(self): bar_bin_dep = self.create_python_library( relpath='bar/dep', name='dep', provides=dedent(""" setup_py( name='bar_bin_dep', version='0.0.0' ) """) ) bar_bin = self.create_python_binary( relpath='bar/bin', name='bin', entry_point='bar.bin:bar', dependencies=[ 'bar/dep' ], ) bar = self.create_python_library( relpath='bar', name='bar', provides=dedent(""" setup_py( name='bar', version='0.0.0' ).with_binaries( bar_binary='bar/bin' ) """) ) self.assertEqual(self.dependency_calculator.reduced_dependencies(bar), OrderedSet([bar_bin, bar_bin_dep])) self.assert_requirements(bar, {'bar_bin_dep==0.0.0'}) entry_points = dict(SetupPy.iter_entry_points(bar)) self.assertEqual(entry_points, {'bar_binary': 'bar.bin:bar'}) with self.run_execute(bar, recursive=False) as created: self.assertEqual([bar], created.keys()) with self.run_execute(bar, recursive=True) as created: self.assertEqual({bar_bin_dep, bar}, set(created.keys()))
def test_binary_target_injected_into_reduced_dependencies_with_provider( self): bar_bin_dep = self.create_python_library(relpath='bar/dep', name='dep', provides=dedent(""" setup_py( name='bar_bin_dep', version='0.0.0' ) """)) bar_bin = self.create_python_binary( relpath='bar/bin', name='bin', entry_point='bar.bin:bar', dependencies=['bar/dep'], ) bar = self.create_python_library(relpath='bar', name='bar', provides=dedent(""" setup_py( name='bar', version='0.0.0' ).with_binaries( bar_binary='bar/bin' ) """)) self.assertEqual(self.dependency_calculator.reduced_dependencies(bar), OrderedSet([bar_bin, bar_bin_dep])) self.assert_requirements(bar, {'bar_bin_dep==0.0.0'}) entry_points = dict(SetupPy.iter_entry_points(bar)) self.assertEqual(entry_points, {'bar_binary': 'bar.bin:bar'}) with self.run_execute(bar, recursive=False) as created: self.assertEqual([bar], created.keys()) with self.run_execute(bar, recursive=True) as created: self.assertEqual({bar_bin_dep, bar}, set(created.keys()))
def assert_requirements(self, target, expected): reduced_dependencies = self.dependency_calculator.reduced_dependencies( target) self.assertEqual(SetupPy.install_requires(reduced_dependencies), expected)
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())
def has_ns(stmt): with temporary_file() as fp: fp.write(stmt) fp.flush() return SetupPy.declares_namespace_package(fp.name)
def setUp(self): super(TestSetupPy, self).setUp() self.dependency_calculator = SetupPy.DependencyCalculator( self.build_graph)
def assert_requirements(self, target, expected): reduced_dependencies = self.dependency_calculator.reduced_dependencies(target) self.assertEqual(SetupPy.install_requires(reduced_dependencies), expected)