コード例 #1
0
def BuildExtension(sources, output_dir, extension_name):
  from distutils import log
  from distutils.core import Distribution, Extension
  import os
  import tempfile

  build_dir = tempfile.mkdtemp()
  # Source file paths must be relative to current path.
  cwd = os.getcwd()
  src_files = [os.path.relpath(filename, cwd) for filename in sources]

  ext = Extension(extension_name, src_files)

  if os.name == 'nt':
    _FixDistutilsMsvcCompiler()
    # VS 2010 does not generate manifest, see http://bugs.python.org/issue4431
    ext.extra_link_args = ['/MANIFEST']

  dist = Distribution({
    'ext_modules': [ext]
  })
  dist.script_args = ['build_ext', '--build-temp', build_dir,
                      '--build-lib', output_dir]
  dist.parse_command_line()
  log.set_threshold(log.DEBUG)
  dist.run_commands()
  dist.script_args = ['clean', '--build-temp', build_dir, '--all']
  dist.parse_command_line()
  log.set_threshold(log.DEBUG)
  dist.run_commands()
コード例 #2
0
    def test_empty_package_dir(self):
        cwd = os.getcwd()
        sources = self.mkdtemp()
        open(os.path.join(sources, '__init__.py'), 'w').close()
        testdir = os.path.join(sources, 'doc')
        os.mkdir(testdir)
        open(os.path.join(testdir, 'testfile'), 'w').close()
        os.chdir(sources)
        old_stdout = sys.stdout
        sys.stdout = StringIO.StringIO()
        try:
            dist = Distribution({'packages': ['pkg'],
             'package_dir': {'pkg': ''},
             'package_data': {'pkg': ['doc/*']}})
            dist.script_name = os.path.join(sources, 'setup.py')
            dist.script_args = ['build']
            dist.parse_command_line()
            try:
                dist.run_commands()
            except DistutilsFileError:
                self.fail("failed package_data test when package_dir is ''")

        finally:
            os.chdir(cwd)
            sys.stdout = old_stdout
コード例 #3
0
    def test_empty_package_dir (self):
        # See SF 1668596/1720897.
        cwd = os.getcwd()

        # create the distribution files.
        sources = self.mkdtemp()
        open(os.path.join(sources, "__init__.py"), "w").close()

        testdir = os.path.join(sources, "doc")
        os.mkdir(testdir)
        open(os.path.join(testdir, "testfile"), "w").close()

        os.chdir(sources)
        old_stdout = sys.stdout
        sys.stdout = StringIO.StringIO()

        try:
            dist = Distribution({"packages": ["pkg"],
                                 "package_dir": {"pkg": ""},
                                 "package_data": {"pkg": ["doc/*"]}})
            # script_name need not exist, it just need to be initialized
            dist.script_name = os.path.join(sources, "setup.py")
            dist.script_args = ["build"]
            dist.parse_command_line()

            try:
                dist.run_commands()
            except DistutilsFileError:
                self.fail("failed package_data test when package_dir is ''")
        finally:
            # Restore state.
            os.chdir(cwd)
            sys.stdout = old_stdout
コード例 #4
0
    def test_dir_in_package_data(self):
        """
        A directory in package_data should not be added to the filelist.
        """
        # See bug 19286
        sources = self.mkdtemp()
        pkg_dir = os.path.join(sources, "pkg")

        os.mkdir(pkg_dir)
        open(os.path.join(pkg_dir, "__init__.py"), "w").close()

        docdir = os.path.join(pkg_dir, "doc")
        os.mkdir(docdir)
        open(os.path.join(docdir, "testfile"), "w").close()

        # create the directory that could be incorrectly detected as a file
        os.mkdir(os.path.join(docdir, 'otherdir'))

        os.chdir(sources)
        dist = Distribution({"packages": ["pkg"],
                             "package_data": {"pkg": ["doc/*"]}})
        # script_name need not exist, it just need to be initialized
        dist.script_name = os.path.join(sources, "setup.py")
        dist.script_args = ["build"]
        dist.parse_command_line()

        try:
            dist.run_commands()
        except DistutilsFileError:
            self.fail("failed package_data when data dir includes a dir")
コード例 #5
0
 def test_dir_in_package_data(self):
     """
     A directory in package_data should not be added to the filelist.
     """
     sources = self.mkdtemp()
     pkg_dir = os.path.join(sources, 'pkg')
     os.mkdir(pkg_dir)
     open(os.path.join(pkg_dir, '__init__.py'), 'w').close()
     docdir = os.path.join(pkg_dir, 'doc')
     os.mkdir(docdir)
     open(os.path.join(docdir, 'testfile'), 'w').close()
     os.mkdir(os.path.join(docdir, 'otherdir'))
     os.chdir(sources)
     dist = Distribution({
         'packages': ['pkg'],
         'package_data': {
             'pkg': ['doc/*']
         }
     })
     dist.script_name = os.path.join(sources, 'setup.py')
     dist.script_args = ['build']
     dist.parse_command_line()
     try:
         dist.run_commands()
     except DistutilsFileError:
         self.fail('failed package_data when data dir includes a dir')
コード例 #6
0
    def test_empty_package_dir(self):
        cwd = os.getcwd()
        sources = self.mkdtemp()
        open(os.path.join(sources, '__init__.py'), 'w').close()
        testdir = os.path.join(sources, 'doc')
        os.mkdir(testdir)
        open(os.path.join(testdir, 'testfile'), 'w').close()
        os.chdir(sources)
        old_stdout = sys.stdout
        sys.stdout = StringIO.StringIO()
        try:
            dist = Distribution({
                'packages': ['pkg'],
                'package_dir': {
                    'pkg': ''
                },
                'package_data': {
                    'pkg': ['doc/*']
                }
            })
            dist.script_name = os.path.join(sources, 'setup.py')
            dist.script_args = ['build']
            dist.parse_command_line()
            try:
                dist.run_commands()
            except DistutilsFileError:
                self.fail("failed package_data test when package_dir is ''")

        finally:
            os.chdir(cwd)
            sys.stdout = old_stdout
コード例 #7
0
    def test_empty_package_dir(self):
        # See bugs #1668596/#1720897
        sources = self.mkdtemp()
        open(os.path.join(sources, "__init__.py"), "w").close()

        testdir = os.path.join(sources, "doc")
        os.mkdir(testdir)
        open(os.path.join(testdir, "testfile"), "w").close()

        os.chdir(sources)
        dist = Distribution({
            "packages": ["pkg"],
            "package_dir": {
                "pkg": ""
            },
            "package_data": {
                "pkg": ["doc/*"]
            }
        })
        # script_name need not exist, it just need to be initialized
        dist.script_name = os.path.join(sources, "setup.py")
        dist.script_args = ["build"]
        dist.parse_command_line()

        try:
            dist.run_commands()
        except DistutilsFileError:
            self.fail("failed package_data test when package_dir is ''")
コード例 #8
0
    def test_dir_in_package_data(self):
        """
        A directory in package_data should not be added to the filelist.
        """
        # See bug 19286
        sources = self.mkdtemp()
        pkg_dir = os.path.join(sources, "pkg")

        os.mkdir(pkg_dir)
        open(os.path.join(pkg_dir, "__init__.py"), "w").close()

        docdir = os.path.join(pkg_dir, "doc")
        os.mkdir(docdir)
        open(os.path.join(docdir, "testfile"), "w").close()

        # create the directory that could be incorrectly detected as a file
        os.mkdir(os.path.join(docdir, 'otherdir'))

        os.chdir(sources)
        dist = Distribution({
            "packages": ["pkg"],
            "package_data": {
                "pkg": ["doc/*"]
            }
        })
        # script_name need not exist, it just need to be initialized
        dist.script_name = os.path.join(sources, "setup.py")
        dist.script_args = ["build"]
        dist.parse_command_line()

        try:
            dist.run_commands()
        except DistutilsFileError:
            self.fail("failed package_data when data dir includes a dir")
コード例 #9
0
 def test_dir_in_package_data(self):
     """
     A directory in package_data should not be added to the filelist.
     """
     sources = self.mkdtemp()
     pkg_dir = os.path.join(sources, 'pkg')
     os.mkdir(pkg_dir)
     open(os.path.join(pkg_dir, '__init__.py'), 'w').close()
     docdir = os.path.join(pkg_dir, 'doc')
     os.mkdir(docdir)
     open(os.path.join(docdir, 'testfile'), 'w').close()
     os.mkdir(os.path.join(docdir, 'otherdir'))
     os.chdir(sources)
     dist = Distribution({'packages': ['pkg'],
      'package_data': {'pkg': ['doc/*']}})
     dist.script_name = os.path.join(sources, 'setup.py')
     dist.script_args = ['build']
     dist.parse_command_line()
     try:
         dist.run_commands()
     except DistutilsFileError:
         self.fail('failed package_data when data dir includes a dir')
コード例 #10
0
ファイル: test_build_py.py プロジェクト: 0jpq0/kbengine
    def test_empty_package_dir(self):
        # See bugs #1668596/#1720897
        sources = self.mkdtemp()
        open(os.path.join(sources, "__init__.py"), "w").close()

        testdir = os.path.join(sources, "doc")
        os.mkdir(testdir)
        open(os.path.join(testdir, "testfile"), "w").close()

        os.chdir(sources)
        dist = Distribution({"packages": ["pkg"],
                             "package_dir": {"pkg": ""},
                             "package_data": {"pkg": ["doc/*"]}})
        # script_name need not exist, it just need to be initialized
        dist.script_name = os.path.join(sources, "setup.py")
        dist.script_args = ["build"]
        dist.parse_command_line()

        try:
            dist.run_commands()
        except DistutilsFileError:
            self.fail("failed package_data test when package_dir is ''")
コード例 #11
0
def print_box(msg):
    lines = msg.split('\n')
    size = max(len(l) + 1 for l in lines)
    print('-' * (size + 2))
    for l in lines:
        print('|{}{}|'.format(l, ' ' * (size - len(l))))
    print('-' * (size + 2))


if __name__ == '__main__':
    # Parse the command line and check the arguments
    # before we proceed with building deps and setup
    dist = Distribution()
    dist.script_name = sys.argv[0]
    dist.script_args = sys.argv[1:]
    try:
        ok = dist.parse_command_line()
    except DistutilsArgError as msg:
        raise SystemExit(
            core.gen_usage(dist.script_name) + "\nerror: %s" % msg)
    if not ok:
        sys.exit()

    if RUN_BUILD_DEPS:
        build_deps()

    extensions, cmdclass, packages, entry_points = configure_extension_build()

    setup(
        name=package_name,