def test_run(self):
        pkg_dir, dist = self.create_dist()
        cmd = build_clib(dist)

        foo_c = os.path.join(pkg_dir, 'foo.c')
        self.write_file(foo_c, 'int main(void) { return 1;}\n')
        cmd.libraries = [('foo', {'sources': [foo_c]})]

        build_temp = os.path.join(pkg_dir, 'build')
        os.mkdir(build_temp)
        cmd.build_temp = build_temp
        cmd.build_clib = build_temp

        # before we run the command, we want to make sure
        # all commands are present on the system
        # by creating a compiler and checking its executables
        from distutils2.compiler import new_compiler, customize_compiler

        compiler = new_compiler()
        customize_compiler(compiler)
        for ccmd in compiler.executables.values():
            if ccmd is None:
                continue
            if find_executable(ccmd[0]) is None:
                raise unittest.SkipTest("can't test")

        # this should work
        cmd.run()

        # let's check the result
        self.assertIn('libfoo.a', os.listdir(build_temp))
    def test_run(self):
        pkg_dir, dist = self.create_dist()
        cmd = build_clib(dist)

        foo_c = os.path.join(pkg_dir, 'foo.c')
        self.write_file(foo_c, 'int main(void) { return 1;}\n')
        cmd.libraries = [('foo', {'sources': [foo_c]})]

        build_temp = os.path.join(pkg_dir, 'build')
        os.mkdir(build_temp)
        cmd.build_temp = build_temp
        cmd.build_clib = build_temp

        # before we run the command, we want to make sure
        # all commands are present on the system
        # by creating a compiler and checking its executables
        from distutils2.compiler import new_compiler, customize_compiler

        compiler = new_compiler()
        customize_compiler(compiler)
        for ccmd in compiler.executables.values():
            if ccmd is None:
                continue
            if find_executable(ccmd[0]) is None:
                raise unittest.SkipTest("can't test")

        # this should work
        cmd.run()

        # let's check the result
        self.assertIn('libfoo.a', os.listdir(build_temp))
Exemple #3
0
    def run(self):
        from distutils2.compiler import new_compiler

        if not self.extensions:
            return

        # If we were asked to build any C/C++ libraries, make sure that the
        # directory where we put them is in the library search path for
        # linking extensions.
        if self.distribution.has_c_libraries():
            build_clib = self.get_finalized_command('build_clib')
            self.libraries.extend(build_clib.get_library_names() or [])
            self.library_dirs.append(build_clib.build_clib)

        # Setup the CCompiler object that we'll use to do all the
        # compiling and linking
        self.compiler_obj = new_compiler(compiler=self.compiler,
                                         dry_run=self.dry_run,
                                         force=self.force)

        customize_compiler(self.compiler_obj)
        # If we are cross-compiling, init the compiler now (if we are not
        # cross-compiling, init would not hurt, but people may rely on
        # late initialization of compiler even if they shouldn't...)
        if os.name == 'nt' and self.plat_name != get_platform():
            self.compiler_obj.initialize(self.plat_name)

        # And make sure that any compile/link-related options (which might
        # come from the command line or from the setup script) are set in
        # that CCompiler object -- that way, they automatically apply to
        # all compiling and linking done here.
        if self.include_dirs is not None:
            self.compiler_obj.set_include_dirs(self.include_dirs)
        if self.define is not None:
            # 'define' option is a list of (name,value) tuples
            for name, value in self.define:
                self.compiler_obj.define_macro(name, value)
        if self.undef is not None:
            for macro in self.undef:
                self.compiler_obj.undefine_macro(macro)
        if self.libraries is not None:
            self.compiler_obj.set_libraries(self.libraries)
        if self.library_dirs is not None:
            self.compiler_obj.set_library_dirs(self.library_dirs)
        if self.rpath is not None:
            self.compiler_obj.set_runtime_library_dirs(self.rpath)
        if self.link_objects is not None:
            self.compiler_obj.set_link_objects(self.link_objects)

        # Now actually compile and link everything.
        self.build_extensions()
    def run(self):
        from distutils2.compiler import new_compiler

        if not self.extensions:
            return

        # If we were asked to build any C/C++ libraries, make sure that the
        # directory where we put them is in the library search path for
        # linking extensions.
        if self.distribution.has_c_libraries():
            build_clib = self.get_finalized_command('build_clib')
            self.libraries.extend(build_clib.get_library_names() or [])
            self.library_dirs.append(build_clib.build_clib)

        # Setup the CCompiler object that we'll use to do all the
        # compiling and linking
        self.compiler_obj = new_compiler(compiler=self.compiler,
                                         dry_run=self.dry_run,
                                         force=self.force)

        customize_compiler(self.compiler_obj)
        # If we are cross-compiling, init the compiler now (if we are not
        # cross-compiling, init would not hurt, but people may rely on
        # late initialization of compiler even if they shouldn't...)
        if os.name == 'nt' and self.plat_name != get_platform():
            self.compiler_obj.initialize(self.plat_name)

        # And make sure that any compile/link-related options (which might
        # come from the command line or from the setup script) are set in
        # that CCompiler object -- that way, they automatically apply to
        # all compiling and linking done here.
        if self.include_dirs is not None:
            self.compiler_obj.set_include_dirs(self.include_dirs)
        if self.define is not None:
            # 'define' option is a list of (name,value) tuples
            for name, value in self.define:
                self.compiler_obj.define_macro(name, value)
        if self.undef is not None:
            for macro in self.undef:
                self.compiler_obj.undefine_macro(macro)
        if self.libraries is not None:
            self.compiler_obj.set_libraries(self.libraries)
        if self.library_dirs is not None:
            self.compiler_obj.set_library_dirs(self.library_dirs)
        if self.rpath is not None:
            self.compiler_obj.set_runtime_library_dirs(self.rpath)
        if self.link_objects is not None:
            self.compiler_obj.set_link_objects(self.link_objects)

        # Now actually compile and link everything.
        self.build_extensions()
Exemple #5
0
 def _check_compiler(self):
     """Check that 'self.compiler' really is a CCompiler object;
     if not, make it one.
     """
     # We do this late, and only on-demand, because this is an expensive
     # import.
     from distutils2.compiler.ccompiler import CCompiler
     from distutils2.compiler import new_compiler
     if not isinstance(self.compiler, CCompiler):
         self.compiler = new_compiler(compiler=self.compiler,
                                      dry_run=self.dry_run, force=True)
         customize_compiler(self.compiler)
         if self.include_dirs:
             self.compiler.set_include_dirs(self.include_dirs)
         if self.libraries:
             self.compiler.set_libraries(self.libraries)
         if self.library_dirs:
             self.compiler.set_library_dirs(self.library_dirs)
Exemple #6
0
    def _check_compiler(self):
        """Check that 'self.compiler' really is a CCompiler object;
        if not, make it one.
        """
        # We do this late, and only on-demand, because this is an expensive
        # import.
        from distutils2.compiler.ccompiler import CCompiler
        from distutils2.compiler import new_compiler

        if not isinstance(self.compiler, CCompiler):
            self.compiler = new_compiler(compiler=self.compiler, dry_run=self.dry_run, force=True)
            customize_compiler(self.compiler)
            if self.include_dirs:
                self.compiler.set_include_dirs(self.include_dirs)
            if self.libraries:
                self.compiler.set_libraries(self.libraries)
            if self.library_dirs:
                self.compiler.set_library_dirs(self.library_dirs)
Exemple #7
0
    def run(self):
        if not self.libraries:
            return

        # Yech -- this is cut 'n pasted from build_ext.py!
        self.compiler = new_compiler(compiler=self.compiler,
                                     dry_run=self.dry_run,
                                     force=self.force)
        customize_compiler(self.compiler)

        if self.include_dirs is not None:
            self.compiler.set_include_dirs(self.include_dirs)
        if self.define is not None:
            # 'define' option is a list of (name,value) tuples
            for name, value in self.define:
                self.compiler.define_macro(name, value)
        if self.undef is not None:
            for macro in self.undef:
                self.compiler.undefine_macro(macro)

        self.build_libraries(self.libraries)
Exemple #8
0
    def test_config(self):
        self.write_setup()
        self.write_file('README', 'yeah')
        os.mkdir('bm')
        self.write_file(('bm', 'b1.gif'), '')
        self.write_file(('bm', 'b2.gif'), '')
        os.mkdir('Cfg')
        self.write_file(('Cfg', 'data.CFG'), '')
        self.write_file('init_script', '')

        # try to load the metadata now
        dist = self.get_dist()

        # check what was done
        self.assertEqual(dist.metadata['Author'], 'Carl Meyer')
        self.assertEqual(dist.metadata['Author-Email'], '*****@*****.**')

        # the hook adds .dev1
        self.assertEqual(dist.metadata['Version'], '0.6.4.dev1')

        wanted = [
            'Development Status :: 4 - Beta',
            'Environment :: Console (Text Based)',
            "Environment :: X11 Applications :: GTK; python_version < '3'",
            'License :: OSI Approved :: MIT License',
            'Programming Language :: Python',
            'Programming Language :: Python :: 2',
            'Programming Language :: Python :: 3'
        ]
        self.assertEqual(dist.metadata['Classifier'], wanted)

        wanted = ['distutils2', 'sample project']
        self.assertEqual(dist.metadata['Keywords'], wanted)

        self.assertEqual(dist.metadata['Requires-Python'], '>=2.4, <3.2')

        wanted = [
            'PetShoppe', 'MichaelPalin (> 1.1)',
            "pywin32; sys.platform == 'win32'",
            "pysqlite2; python_version < '2.5'",
            "inotify (0.0.1); sys.platform == 'linux2'"
        ]

        self.assertEqual(dist.metadata['Requires-Dist'], wanted)
        urls = [('Main repository',
                 'http://bitbucket.org/carljm/sample-distutils2-project'),
                ('Fork in progress',
                 'http://bitbucket.org/Merwok/sample-distutils2-project')]
        self.assertEqual(dist.metadata['Project-Url'], urls)

        self.assertEqual(dist.packages, ['one', 'two', 'three'])
        self.assertEqual(dist.py_modules, ['haven'])
        self.assertEqual(
            dist.package_data,
            {'cheese': ['data/templates/*', 'doc/*', 'doc/images/*.png']})
        self.assertEqual(
            dist.data_files, {
                'bm/b1.gif': '{icon}/b1.gif',
                'bm/b2.gif': '{icon}/b2.gif',
                'Cfg/data.CFG': '{config}/baBar/data.CFG',
                'init_script': '{script}/JunGle/init_script'
            })

        self.assertEqual(dist.package_dir, 'src')

        # Make sure we get the foo command loaded.  We use a string comparison
        # instead of assertIsInstance because the class is not the same when
        # this test is run directly: foo is distutils2.tests.test_config.Foo
        # because get_command_class uses the full name, but a bare "Foo" in
        # this file would be __main__.Foo when run as "python test_config.py".
        # The name FooBarBazTest should be unique enough to prevent
        # collisions.
        self.assertEqual(
            dist.get_command_obj('foo').__class__.__name__, 'FooBarBazTest')

        # did the README got loaded ?
        self.assertEqual(dist.metadata['description'], 'yeah')

        # do we have the D Compiler enabled ?
        self.assertIn('d', _COMPILERS)
        d = new_compiler(compiler='d')
        self.assertEqual(d.description, 'D Compiler')

        # check error reporting for invalid package_data value
        self.write_file('setup.cfg', SETUP_CFG_PKGDATA_BUGGY_1)
        self.assertRaises(PackagingOptionError, self.get_dist)

        self.write_file('setup.cfg', SETUP_CFG_PKGDATA_BUGGY_2)
        self.assertRaises(PackagingOptionError, self.get_dist)
Exemple #9
0
    def test_config(self):
        self.write_setup()
        self.write_file('README', 'yeah')
        os.mkdir('bm')
        self.write_file(('bm', 'b1.gif'), '')
        self.write_file(('bm', 'b2.gif'), '')
        os.mkdir('Cfg')
        self.write_file(('Cfg', 'data.CFG'), '')
        self.write_file('init_script', '')

        # try to load the metadata now
        dist = self.get_dist()

        # check what was done
        self.assertEqual(dist.metadata['Author'], 'Carl Meyer')
        self.assertEqual(dist.metadata['Author-Email'], '*****@*****.**')

        # the hook adds .dev1
        self.assertEqual(dist.metadata['Version'], '0.6.4.dev1')

        wanted = [
            'Development Status :: 4 - Beta',
            'Environment :: Console (Text Based)',
            "Environment :: X11 Applications :: GTK; python_version < '3'",
            'License :: OSI Approved :: MIT License',
            'Programming Language :: Python',
            'Programming Language :: Python :: 2',
            'Programming Language :: Python :: 3']
        self.assertEqual(dist.metadata['Classifier'], wanted)

        wanted = ['distutils2', 'sample project']
        self.assertEqual(dist.metadata['Keywords'], wanted)

        self.assertEqual(dist.metadata['Requires-Python'], '>=2.4, <3.2')

        wanted = ['PetShoppe',
                  'MichaelPalin (> 1.1)',
                  "pywin32; sys.platform == 'win32'",
                  "pysqlite2; python_version < '2.5'",
                  "inotify (0.0.1); sys.platform == 'linux2'"]

        self.assertEqual(dist.metadata['Requires-Dist'], wanted)
        urls = [('Main repository',
                 'http://bitbucket.org/carljm/sample-distutils2-project'),
                ('Fork in progress',
                 'http://bitbucket.org/Merwok/sample-distutils2-project')]
        self.assertEqual(dist.metadata['Project-Url'], urls)

        self.assertEqual(dist.packages, ['one', 'two', 'three'])
        self.assertEqual(dist.py_modules, ['haven'])
        self.assertEqual(dist.package_data,
                         {'cheese': ['data/templates/*', 'doc/*',
                                     'doc/images/*.png']})
        self.assertEqual(dist.data_files,
            {'bm/b1.gif': '{icon}/b1.gif',
             'bm/b2.gif': '{icon}/b2.gif',
             'Cfg/data.CFG': '{config}/baBar/data.CFG',
             'init_script': '{script}/JunGle/init_script'})

        self.assertEqual(dist.package_dir, 'src')

        # Make sure we get the foo command loaded.  We use a string comparison
        # instead of assertIsInstance because the class is not the same when
        # this test is run directly: foo is distutils2.tests.test_config.Foo
        # because get_command_class uses the full name, but a bare "Foo" in
        # this file would be __main__.Foo when run as "python test_config.py".
        # The name FooBarBazTest should be unique enough to prevent
        # collisions.
        self.assertEqual(dist.get_command_obj('foo').__class__.__name__,
                         'FooBarBazTest')

        # did the README got loaded ?
        self.assertEqual(dist.metadata['description'], 'yeah')

        # do we have the D Compiler enabled ?
        self.assertIn('d', _COMPILERS)
        d = new_compiler(compiler='d')
        self.assertEqual(d.description, 'D Compiler')

        # check error reporting for invalid package_data value
        self.write_file('setup.cfg', SETUP_CFG_PKGDATA_BUGGY_1)
        self.assertRaises(PackagingOptionError, self.get_dist)

        self.write_file('setup.cfg', SETUP_CFG_PKGDATA_BUGGY_2)
        self.assertRaises(PackagingOptionError, self.get_dist)