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")
예제 #2
0
 def test_quiet(self):
     tmp_dir = self.mkdtemp()
     pkg_dir = os.path.join(tmp_dir, 'foo')
     os.mkdir(pkg_dir)
     self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
     self.write_file((pkg_dir, 'foo.py'), '#')
     self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
     self.write_file((pkg_dir, 'README'), '')
     dist = Distribution({'name': 'foo',
      'version': '0.1',
      'py_modules': ['foo'],
      'url': 'xxx',
      'author': 'xxx',
      'author_email': 'xxx'})
     dist.script_name = 'setup.py'
     os.chdir(pkg_dir)
     sys.argv = ['setup.py']
     cmd = bdist_rpm(dist)
     cmd.fix_python = True
     cmd.quiet = 1
     cmd.ensure_finalized()
     cmd.run()
     dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
     self.assertIn('foo-0.1-1.noarch.rpm', dist_created)
     self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'), dist.dist_files)
     self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files)
    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 ''")
예제 #4
0
    def test_home_installation_scheme(self):
        # This ensure two things:
        # - that --home generates the desired set of directory names
        # - test --home is supported on all platforms
        builddir = self.mkdtemp()
        destination = os.path.join(builddir, "installation")

        dist = Distribution({"name": "foopkg"})
        # script_name need not exist, it just need to be initialized
        dist.script_name = os.path.join(builddir, "setup.py")
        dist.command_obj["build"] = support.DummyCommand(
            build_base=builddir,
            build_lib=os.path.join(builddir, "lib"),
        )

        cmd = install(dist)
        cmd.home = destination
        cmd.ensure_finalized()

        self.assertEqual(cmd.install_base, destination)
        self.assertEqual(cmd.install_platbase, destination)

        def check_path(got, expected):
            got = os.path.normpath(got)
            expected = os.path.normpath(expected)
            self.assertEqual(got, expected)

        libdir = os.path.join(destination, "lib", "python")
        check_path(cmd.install_lib, libdir)
        check_path(cmd.install_platlib, libdir)
        check_path(cmd.install_purelib, libdir)
        check_path(cmd.install_headers,
                   os.path.join(destination, "include", "python", "foopkg"))
        check_path(cmd.install_scripts, os.path.join(destination, "bin"))
        check_path(cmd.install_data, destination)
예제 #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_home_installation_scheme(self):
        # This ensure two things:
        # - that --home generates the desired set of directory names
        # - test --home is supported on all platforms
        builddir = self.mkdtemp()
        destination = os.path.join(builddir, "installation")

        dist = Distribution({"name": "foopkg"})
        # script_name need not exist, it just need to be initialized
        dist.script_name = os.path.join(builddir, "setup.py")
        dist.command_obj["build"] = support.DummyCommand(build_base=builddir, build_lib=os.path.join(builddir, "lib"))

        cmd = install(dist)
        cmd.home = destination
        cmd.ensure_finalized()

        self.assertEqual(cmd.install_base, destination)
        self.assertEqual(cmd.install_platbase, destination)

        def check_path(got, expected):
            got = os.path.normpath(got)
            expected = os.path.normpath(expected)
            self.assertEqual(got, expected)

        libdir = os.path.join(destination, "lib", "python")
        check_path(cmd.install_lib, libdir)
        check_path(cmd.install_platlib, libdir)
        check_path(cmd.install_purelib, libdir)
        check_path(cmd.install_headers, os.path.join(destination, "include", "python", "foopkg"))
        check_path(cmd.install_scripts, os.path.join(destination, "bin"))
        check_path(cmd.install_data, destination)
예제 #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_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
예제 #10
0
    def test_no_optimize_flag(self):
        # let's create a package that breaks bdist_rpm
        tmp_dir = self.mkdtemp()
        os.environ['HOME'] = tmp_dir   # to confine dir '.rpmdb' creation
        pkg_dir = os.path.join(tmp_dir, 'foo')
        os.mkdir(pkg_dir)
        self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
        self.write_file((pkg_dir, 'foo.py'), '#')
        self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
        self.write_file((pkg_dir, 'README'), '')

        dist = Distribution({'name': 'foo', 'version': '0.1',
                             'py_modules': ['foo'],
                             'url': 'xxx', 'author': 'xxx',
                             'author_email': 'xxx'})
        dist.script_name = 'setup.py'
        os.chdir(pkg_dir)

        sys.argv = ['setup.py']
        cmd = bdist_rpm(dist)
        cmd.fix_python = True

        cmd.quiet = 1
        cmd.ensure_finalized()
        cmd.run()

        dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
        self.assertIn('foo-0.1-1.noarch.rpm', dist_created)

        # bug #2945: upload ignores bdist_rpm files
        self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'), dist.dist_files)
        self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files)

        os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm'))
예제 #11
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
예제 #12
0
 def test_quiet(self):
     tmp_dir = self.mkdtemp()
     os.environ['HOME'] = tmp_dir
     pkg_dir = os.path.join(tmp_dir, 'foo')
     os.mkdir(pkg_dir)
     self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
     self.write_file((pkg_dir, 'foo.py'), '#')
     self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
     self.write_file((pkg_dir, 'README'), '')
     dist = Distribution({
         'name': 'foo',
         'version': '0.1',
         'py_modules': ['foo'],
         'url': 'xxx',
         'author': 'xxx',
         'author_email': 'xxx'
     })
     dist.script_name = 'setup.py'
     os.chdir(pkg_dir)
     sys.argv = ['setup.py']
     cmd = bdist_rpm(dist)
     cmd.fix_python = True
     cmd.quiet = 1
     cmd.ensure_finalized()
     cmd.run()
     dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
     self.assertIn('foo-0.1-1.noarch.rpm', dist_created)
     self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'),
                   dist.dist_files)
     self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'),
                   dist.dist_files)
예제 #13
0
    def test_home_installation_scheme(self):
        builddir = self.mkdtemp()
        destination = os.path.join(builddir, 'installation')
        dist = Distribution({'name': 'foopkg'})
        dist.script_name = os.path.join(builddir, 'setup.py')
        dist.command_obj['build'] = support.DummyCommand(
            build_base=builddir, build_lib=os.path.join(builddir, 'lib'))
        cmd = install(dist)
        cmd.home = destination
        cmd.ensure_finalized()
        self.assertEqual(cmd.install_base, destination)
        self.assertEqual(cmd.install_platbase, destination)

        def check_path(got, expected):
            got = os.path.normpath(got)
            expected = os.path.normpath(expected)
            self.assertEqual(got, expected)

        libdir = os.path.join(destination, 'lib', 'python')
        check_path(cmd.install_lib, libdir)
        check_path(cmd.install_platlib, libdir)
        check_path(cmd.install_purelib, libdir)
        check_path(cmd.install_headers,
                   os.path.join(destination, 'include', 'python', 'foopkg'))
        check_path(cmd.install_scripts, os.path.join(destination, 'bin'))
        check_path(cmd.install_data, destination)
예제 #14
0
 def test_simple_built(self):
     tmp_dir = self.mkdtemp()
     pkg_dir = os.path.join(tmp_dir, 'foo')
     os.mkdir(pkg_dir)
     self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
     self.write_file((pkg_dir, 'foo.py'), '#')
     self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
     self.write_file((pkg_dir, 'README'), '')
     dist = Distribution({'name': 'foo', 'version': '0.1', 'py_modules':
         ['foo'], 'url': 'xxx', 'author': 'xxx', 'author_email': 'xxx'})
     dist.script_name = 'setup.py'
     os.chdir(pkg_dir)
     sys.argv = ['setup.py']
     cmd = bdist_dumb(dist)
     cmd.format = 'zip'
     cmd.ensure_finalized()
     cmd.run()
     dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
     base = '%s.%s.zip' % (dist.get_fullname(), cmd.plat_name)
     self.assertEqual(dist_created, [base])
     fp = zipfile.ZipFile(os.path.join('dist', base))
     try:
         contents = fp.namelist()
     finally:
         fp.close()
     contents = sorted(os.path.basename(fn) for fn in contents)
     wanted = ['foo-0.1-py%s.%s.egg-info' % sys.version_info[:2], 'foo.py']
     if not sys.dont_write_bytecode:
         wanted.append('foo.%s.pyc' % sys.implementation.cache_tag)
     self.assertEqual(contents, sorted(wanted))
예제 #15
0
    def test_no_optimize_flag(self):
        # let's create a package that breaks bdist_rpm
        tmp_dir = self.mkdtemp()
        os.environ['HOME'] = tmp_dir   # to confine dir '.rpmdb' creation
        pkg_dir = os.path.join(tmp_dir, 'foo')
        os.mkdir(pkg_dir)
        self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
        self.write_file((pkg_dir, 'foo.py'), '#')
        self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
        self.write_file((pkg_dir, 'README'), '')

        dist = Distribution({'name': 'foo', 'version': '0.1',
                             'py_modules': ['foo'],
                             'url': 'xxx', 'author': 'xxx',
                             'author_email': 'xxx'})
        dist.script_name = 'setup.py'
        os.chdir(pkg_dir)

        sys.argv = ['setup.py']
        cmd = bdist_rpm(dist)
        cmd.fix_python = True

        cmd.quiet = 1
        cmd.ensure_finalized()
        cmd.run()

        dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
        self.assertIn('foo-0.1-1.noarch.rpm', dist_created)

        # bug #2945: upload ignores bdist_rpm files
        self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'), dist.dist_files)
        self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files)

        os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm'))
예제 #16
0
 def test_get_sdist_filelist(self, sample_pkg):
     # we can get an sdist filelist
     dist = Distribution(SETUP_ATTRS)
     dist.script_name = "setup.py"
     cmd = sdist_check(dist)
     cmd.ensure_finalized()
     file_list = cmd._get_sdist_filelist()
     assert "sample_test/__init__.py" in file_list.files
     assert "setup.py" in file_list.files
예제 #17
0
 def test_check_bad_filenames_filename(self, sample_pkg, capsys):
     # we do not get any output if there are no bad filenames.
     dist = Distribution(SETUP_ATTRS)
     dist.script_name = "setup.py"
     sample_pkg.join("MANIFEST.in").write("graft sample_test\n")
     cmd = sdist_check(dist)
     cmd.ensure_finalized()
     cmd.check_bad_filenames()
     out, err = capsys.readouterr()
     assert err == ""
예제 #18
0
 def get_cmd(self, metadata=None):
     """Returns a cmd"""
     if metadata is None:
         metadata = {"name": "fake", "version": "1.0", "url": "xxx", "author": "xxx", "author_email": "xxx"}
     dist = Distribution(metadata)
     dist.script_name = "setup.py"
     dist.packages = ["somecode"]
     dist.include_package_data = True
     cmd = sdist(dist)
     cmd.dist_dir = "dist"
     return dist, cmd
예제 #19
0
    def test_simple_built(self):

        # let's create a simple package
        tmp_dir = self.mkdtemp()
        pkg_dir = os.path.join(tmp_dir, 'foo')
        os.mkdir(pkg_dir)
        self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
        self.write_file((pkg_dir, 'foo.py'), '#')
        self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
        self.write_file((pkg_dir, 'README'), '')

        dist = Distribution({
            'name': 'foo',
            'version': '0.1',
            'py_modules': ['foo'],
            'url': 'xxx',
            'author': 'xxx',
            'author_email': 'xxx'
        })
        dist.script_name = 'setup.py'
        os.chdir(pkg_dir)

        sys.argv = ['setup.py']
        cmd = bdist_dumb(dist)

        # so the output is the same no matter
        # what is the platform
        cmd.format = 'zip'

        cmd.ensure_finalized()
        cmd.run()

        # see what we have
        dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
        base = "%s.%s.zip" % (dist.get_fullname(), cmd.plat_name)
        if os.name == 'os2':
            base = base.replace(':', '-')

        self.assertEqual(dist_created, [base])

        # now let's check what we have in the zip file
        fp = zipfile.ZipFile(os.path.join('dist', base))
        try:
            contents = fp.namelist()
        finally:
            fp.close()

        contents = sorted(os.path.basename(fn) for fn in contents)
        wanted = [
            'foo-0.1-py%s.%s.egg-info' % sys.version_info[:2], 'foo.py',
            'foo.pyc'
        ]
        self.assertEqual(contents, sorted(wanted))
예제 #20
0
    def test_simple_built(self):

        # let's create a simple package
        tmp_dir = self.mkdtemp()
        pkg_dir = os.path.join(tmp_dir, "foo")
        os.mkdir(pkg_dir)
        self.write_file((pkg_dir, "setup.py"), SETUP_PY)
        self.write_file((pkg_dir, "foo.py"), "#")
        self.write_file((pkg_dir, "MANIFEST.in"), "include foo.py")
        self.write_file((pkg_dir, "README"), "")

        dist = Distribution(
            {
                "name": "foo",
                "version": "0.1",
                "py_modules": ["foo"],
                "url": "xxx",
                "author": "xxx",
                "author_email": "xxx",
            }
        )
        dist.script_name = "setup.py"
        os.chdir(pkg_dir)

        sys.argv = ["setup.py"]
        cmd = bdist_dumb(dist)

        # so the output is the same no matter
        # what is the platform
        cmd.format = "zip"

        cmd.ensure_finalized()
        cmd.run()

        # see what we have
        dist_created = os.listdir(os.path.join(pkg_dir, "dist"))
        base = "%s.%s.zip" % (dist.get_fullname(), cmd.plat_name)
        if os.name == "os2":
            base = base.replace(":", "-")

        self.assertEqual(dist_created, [base])

        # now let's check what we have in the zip file
        fp = zipfile.ZipFile(os.path.join("dist", base))
        try:
            contents = fp.namelist()
        finally:
            fp.close()

        contents = sorted(os.path.basename(fn) for fn in contents)
        wanted = ["foo-0.1-py%s.%s.egg-info" % sys.version_info[:2], "foo.%s.pyc" % imp.get_tag(), "foo.py"]
        self.assertEqual(contents, sorted(wanted))
예제 #21
0
 def test_check_bad_filenames_filename_tilde(self, sample_pkg, capsys):
     # we are warned about bad filenames like *~, which are listed
     # in the default list of bad filenames.
     dist = Distribution(SETUP_ATTRS)
     dist.script_name = "setup.py"
     sample_pkg.join("MANIFEST.in").write("graft sample_test\n")
     sample_pkg.join("sample_test").join("workfile~").write("foo")
     cmd = sdist_check(dist)
     cmd.ensure_finalized()
     cmd.check_bad_filenames()
     out, err = capsys.readouterr()
     assert "warning: sdist_check" in err
     assert "sample_test/workfile~" in err
예제 #22
0
 def get_cmd(self, metadata=None):
     """Returns a cmd"""
     if metadata is None:
         metadata = {'name': 'fake', 'version': '1.0',
                     'url': 'xxx', 'author': 'xxx',
                     'author_email': 'xxx'}
     dist = Distribution(metadata)
     dist.script_name = 'setup.py'
     dist.packages = ['somecode']
     dist.include_package_data = True
     cmd = sdist(dist)
     cmd.dist_dir = 'dist'
     return dist, cmd
예제 #23
0
 def test_command_runnable(self, sample_pkg, capfd):
     # we can run() the new command
     sample_pkg.join("MANIFEST.in").write("graft sample_test\n")
     sample_pkg.join("sample_test").join("file~").write("foo")
     dist = Distribution(dict(SETUP_ATTRS))
     dist.script_name = "setup.py"
     cmd = sdist_check(dist)
     cmd.ensure_finalized()
     cmd.run()
     out, err = capfd.readouterr()
     assert (
         u'warning: sdist_check: suspicious filename found for '
         u'distribution: sample_test/file~\n\n') in err
예제 #24
0
 def get_cmd(self, metadata=None):
     """Returns a cmd"""
     if metadata is None:
         metadata = {'name': 'fake', 'version': '1.0',
                     'url': 'xxx', 'author': 'xxx',
                     'author_email': 'xxx'}
     dist = Distribution(metadata)
     dist.script_name = 'setup.py'
     dist.packages = ['somecode']
     dist.include_package_data = True
     cmd = sdist(dist)
     cmd.dist_dir = 'dist'
     return dist, cmd
    def test_package_data(self):
        sources = self.mkdtemp()
        f = open(os.path.join(sources, "__init__.py"), "w")
        try:
            f.write("# Pretend this is a package.")
        finally:
            f.close()
        f = open(os.path.join(sources, "README.txt"), "w")
        try:
            f.write("Info about this package")
        finally:
            f.close()

        destination = self.mkdtemp()

        dist = Distribution({
            "packages": ["pkg"],
            "package_dir": {
                "pkg": sources
            }
        })
        # script_name need not exist, it just need to be initialized
        dist.script_name = os.path.join(sources, "setup.py")
        dist.command_obj["build"] = support.DummyCommand(force=0,
                                                         build_lib=destination)
        dist.packages = ["pkg"]
        dist.package_data = {"pkg": ["README.txt"]}
        dist.package_dir = {"pkg": sources}

        cmd = build_py(dist)
        cmd.compile = 1
        cmd.ensure_finalized()
        self.assertEqual(cmd.package_data, dist.package_data)

        cmd.run()

        # This makes sure the list of outputs includes byte-compiled
        # files for Python modules but not for package data files
        # (there shouldn't *be* byte-code files for those!).
        self.assertEqual(len(cmd.get_outputs()), 3)
        pkgdest = os.path.join(destination, "pkg")
        files = os.listdir(pkgdest)
        pycache_dir = os.path.join(pkgdest, "__pycache__")
        self.assertIn("__init__.py", files)
        self.assertIn("README.txt", files)
        if sys.dont_write_bytecode:
            self.assertFalse(os.path.exists(pycache_dir))
        else:
            pyc_files = os.listdir(pycache_dir)
            self.assertIn("__init__.%s.pyc" % sys.implementation.cache_tag,
                          pyc_files)
예제 #26
0
    def test_no_optimize_flag(self):

        # XXX I am unable yet to make this test work without
        # spurious sdtout/stderr output under Mac OS X
        if sys.platform != 'linux2':
            return

        # http://bugs.python.org/issue1533164
        # this test will run only if the rpm command is found
        if (find_executable('rpm') is None
                or find_executable('rpmbuild') is None):
            return

        # let's create a package that brakes bdist_rpm
        tmp_dir = self.mkdtemp()
        pkg_dir = os.path.join(tmp_dir, 'foo')
        os.mkdir(pkg_dir)
        self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
        self.write_file((pkg_dir, 'foo.py'), '#')
        self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
        self.write_file((pkg_dir, 'README'), '')

        dist = Distribution({
            'name': 'foo',
            'version': '0.1',
            'py_modules': ['foo'],
            'url': 'xxx',
            'author': 'xxx',
            'author_email': 'xxx'
        })
        dist.script_name = 'setup.py'
        os.chdir(pkg_dir)

        sys.argv = ['setup.py']
        cmd = bdist_rpm(dist)
        cmd.fix_python = True

        cmd.quiet = 1
        cmd.ensure_finalized()
        cmd.run()

        dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
        self.assertTrue('foo-0.1-1.noarch.rpm' in dist_created)

        # bug #2945: upload ignores bdist_rpm files
        self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'),
                      dist.dist_files)
        self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'),
                      dist.dist_files)

        os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm'))
예제 #27
0
    def test_no_optimize_flag(self):

        # XXX I am unable yet to make this test work without
        # spurious sdtout/stderr output under Mac OS X
        if sys.platform != "linux2":
            return

        # http://bugs.python.org/issue1533164
        # this test will run only if the rpm command is found
        if find_executable("rpm") is None or find_executable("rpmbuild") is None:
            return

        # let's create a package that brakes bdist_rpm
        tmp_dir = self.mkdtemp()
        pkg_dir = os.path.join(tmp_dir, "foo")
        os.mkdir(pkg_dir)
        self.write_file((pkg_dir, "setup.py"), SETUP_PY)
        self.write_file((pkg_dir, "foo.py"), "#")
        self.write_file((pkg_dir, "MANIFEST.in"), "include foo.py")
        self.write_file((pkg_dir, "README"), "")

        dist = Distribution(
            {
                "name": "foo",
                "version": "0.1",
                "py_modules": ["foo"],
                "url": "xxx",
                "author": "xxx",
                "author_email": "xxx",
            }
        )
        dist.script_name = "setup.py"
        os.chdir(pkg_dir)

        sys.argv = ["setup.py"]
        cmd = bdist_rpm(dist)
        cmd.fix_python = True

        cmd.quiet = 1
        cmd.ensure_finalized()
        cmd.run()

        dist_created = os.listdir(os.path.join(pkg_dir, "dist"))
        self.assertTrue("foo-0.1-1.noarch.rpm" in dist_created)

        # bug #2945: upload ignores bdist_rpm files
        self.assertIn(("bdist_rpm", "any", "dist/foo-0.1-1.src.rpm"), dist.dist_files)
        self.assertIn(("bdist_rpm", "any", "dist/foo-0.1-1.noarch.rpm"), dist.dist_files)

        os.remove(os.path.join(pkg_dir, "dist", "foo-0.1-1.noarch.rpm"))
예제 #28
0
    def test_prune_file_list(self):
        # this test creates a package with some vcs dirs in it
        # and launch sdist to make sure they get pruned
        # on all systems
        self._init_tmp_pkg()

        # creating VCS directories with some files in them
        os.mkdir(join(TEMP_PKG, 'somecode', '.svn'))
        self._write(join(TEMP_PKG, 'somecode', '.svn', 'ok.py'), 'xxx')

        os.mkdir(join(TEMP_PKG, 'somecode', '.hg'))
        self._write(join(TEMP_PKG, 'somecode', '.hg',
                         'ok'), 'xxx')

        os.mkdir(join(TEMP_PKG, 'somecode', '.git'))
        self._write(join(TEMP_PKG, 'somecode', '.git',
                         'ok'), 'xxx')

        # now building a sdist
        dist = Distribution()
        dist.script_name = 'setup.py'
        dist.metadata.name = 'fake'
        dist.metadata.version = '1.0'
        dist.metadata.url = 'http://xxx'
        dist.metadata.author = dist.metadata.author_email = 'xxx'
        dist.packages = ['somecode']
        dist.include_package_data = True
        cmd = sdist(dist)
        cmd.manifest = 'MANIFEST'
        cmd.template = 'MANIFEST.in'
        cmd.dist_dir = 'dist'

        # zip is available universally
        # (tar might not be installed under win32)
        cmd.formats = ['zip']
        cmd.run()

        # now let's check what we have
        dist_folder = join(TEMP_PKG, 'dist')
        files = os.listdir(dist_folder)
        self.assertEquals(files, ['fake-1.0.zip'])

        zip_file = zipfile.ZipFile(join(dist_folder, 'fake-1.0.zip'))
        try:
            content = zip_file.namelist()
        finally:
            zip_file.close()

        # making sure everything has been pruned correctly
        self.assertEquals(len(content), 4)
예제 #29
0
    def test_prune_file_list(self):
        # this test creates a package with some vcs dirs in it
        # and launch sdist to make sure they get pruned
        # on all systems
        self._init_tmp_pkg()

        # creating VCS directories with some files in them
        os.mkdir(join(self.temp_pkg, 'somecode', '.svn'))
        self._write(join(self.temp_pkg, 'somecode', '.svn', 'ok.py'), 'xxx')

        os.mkdir(join(self.temp_pkg, 'somecode', '.hg'))
        self._write(join(self.temp_pkg, 'somecode', '.hg',
                         'ok'), 'xxx')

        os.mkdir(join(self.temp_pkg, 'somecode', '.git'))
        self._write(join(self.temp_pkg, 'somecode', '.git',
                         'ok'), 'xxx')

        # now building a sdist
        dist = Distribution()
        dist.script_name = 'setup.py'
        dist.metadata.name = 'fake'
        dist.metadata.version = '1.0'
        dist.metadata.url = 'http://xxx'
        dist.metadata.author = dist.metadata.author_email = 'xxx'
        dist.packages = ['somecode']
        dist.include_package_data = True
        cmd = sdist(dist)
        cmd.manifest = 'MANIFEST'
        cmd.template = 'MANIFEST.in'
        cmd.dist_dir = 'dist'

        # zip is available universally
        # (tar might not be installed under win32)
        cmd.formats = ['zip']
        cmd.run()

        # now let's check what we have
        dist_folder = join(self.temp_pkg, 'dist')
        files = os.listdir(dist_folder)
        self.assertEquals(files, ['fake-1.0.zip'])

        zip_file = zipfile.ZipFile(join(dist_folder, 'fake-1.0.zip'))
        try:
            content = zip_file.namelist()
        finally:
            zip_file.close()

        # making sure everything has been pruned correctly
        self.assertEquals(len(content), 4)
예제 #30
0
    def test_package_data(self):
        sources = self.mkdtemp()
        f = open(os.path.join(sources, "__init__.py"), "w")
        try:
            f.write("# Pretend this is a package.")
        finally:
            f.close()
        f = open(os.path.join(sources, "README.txt"), "w")
        try:
            f.write("Info about this package")
        finally:
            f.close()

        destination = self.mkdtemp()

        dist = Distribution({"packages": ["pkg"],
                             "package_dir": {"pkg": sources}})
        # script_name need not exist, it just need to be initialized
        dist.script_name = os.path.join(sources, "setup.py")
        dist.command_obj["build"] = support.DummyCommand(
            force=0,
            build_lib=destination)
        dist.packages = ["pkg"]
        dist.package_data = {"pkg": ["README.txt"]}
        dist.package_dir = {"pkg": sources}

        cmd = build_py(dist)
        cmd.compile = 1
        cmd.ensure_finalized()
        self.assertEqual(cmd.package_data, dist.package_data)

        cmd.run()

        # This makes sure the list of outputs includes byte-compiled
        # files for Python modules but not for package data files
        # (there shouldn't *be* byte-code files for those!).
        self.assertEqual(len(cmd.get_outputs()), 3)
        pkgdest = os.path.join(destination, "pkg")
        files = os.listdir(pkgdest)
        pycache_dir = os.path.join(pkgdest, "__pycache__")
        self.assertIn("__init__.py", files)
        self.assertIn("README.txt", files)
        if sys.dont_write_bytecode:
            self.assertFalse(os.path.exists(pycache_dir))
        else:
            pyc_files = os.listdir(pycache_dir)
            self.assertIn("__init__.%s.pyc" % sys.implementation.cache_tag,
                          pyc_files)
예제 #31
0
    def test_simple_built(self):

        # let's create a simple package
        tmp_dir = self.mkdtemp()
        pkg_dir = os.path.join(tmp_dir, 'foo')
        os.mkdir(pkg_dir)
        self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
        self.write_file((pkg_dir, 'foo.py'), '#')
        self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
        self.write_file((pkg_dir, 'README'), '')

        dist = Distribution({'name': 'foo', 'version': '0.1',
                             'py_modules': ['foo'],
                             'url': 'xxx', 'author': 'xxx',
                             'author_email': 'xxx'})
        dist.script_name = 'setup.py'
        os.chdir(pkg_dir)

        sys.argv = ['setup.py']
        cmd = bdist_dumb(dist)

        # so the output is the same no matter
        # what is the platform
        cmd.format = 'zip'

        cmd.ensure_finalized()
        cmd.run()

        # see what we have
        dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
        base = "%s.%s.zip" % (dist.get_fullname(), cmd.plat_name)
        if os.name == 'os2':
            base = base.replace(':', '-')

        self.assertEqual(dist_created, [base])

        # now let's check what we have in the zip file
        fp = zipfile.ZipFile(os.path.join('dist', base))
        try:
            contents = fp.namelist()
        finally:
            fp.close()

        contents = sorted(os.path.basename(fn) for fn in contents)
        wanted = ['foo-0.1-py%s.%s.egg-info' % sys.version_info[:2], 'foo.py']
        if not sys.dont_write_bytecode:
            wanted.append('foo.pyc')
        self.assertEqual(contents, sorted(wanted))
예제 #32
0
 def test_check_bad_filenames_overriden(self, sample_pkg, capsys):
     # if we override the default "badfiles", we are not warned
     # about these files anymore (but about others).
     dist = Distribution(SETUP_ATTRS)
     dist.script_name = "setup.py"
     sample_pkg.join("MANIFEST.in").write("graft sample_test\n")
     sample_pkg.join("sample_test").join("file.foo").write("foo")
     sample_pkg.join("sample_test").join("file~").write("foo")
     cmd = sdist_check(dist)
     cmd.badfiles = ["*.foo", ]
     cmd.ensure_finalized()
     cmd.check_bad_filenames()
     out, err = capsys.readouterr()
     assert "warning: sdist_check" in err
     assert "sample_test/file.foo" in err
     assert "sample_test/file~" not in err
예제 #33
0
    def test_make_distribution(self):

        # check if tar and gzip are installed
        if (find_executable('tar') is None or
            find_executable('gzip') is None):
            return

        self._init_tmp_pkg()

        # now building a sdist
        dist = Distribution()
        dist.script_name = 'setup.py'
        dist.metadata.name = 'fake'
        dist.metadata.version = '1.0'
        dist.metadata.url = 'http://xxx'
        dist.metadata.author = dist.metadata.author_email = 'xxx'
        dist.packages = ['somecode']
        dist.include_package_data = True
        cmd = sdist(dist)
        cmd.manifest = 'MANIFEST'
        cmd.template = 'MANIFEST.in'
        cmd.dist_dir = 'dist'

        # creating a gztar then a tar
        cmd.formats = ['gztar', 'tar']
        cmd.run()

        # making sure we have two files
        dist_folder = join(TEMP_PKG, 'dist')
        result = os.listdir(dist_folder)
        result.sort()
        self.assertEquals(result,
                          ['fake-1.0.tar', 'fake-1.0.tar.gz'] )

        os.remove(join(dist_folder, 'fake-1.0.tar'))
        os.remove(join(dist_folder, 'fake-1.0.tar.gz'))

        # now trying a tar then a gztar
        cmd.formats = ['tar', 'gztar']
        cmd.run()

        result = os.listdir(dist_folder)
        result.sort()
        self.assertEquals(result,
                ['fake-1.0.tar', 'fake-1.0.tar.gz'])
예제 #34
0
    def test_no_optimize_flag(self):

        # XXX I am unable yet to make this test work without
        # spurious sdtout/stderr output under Mac OS X
        if not sys.platform.startswith('linux'):
            return

        # http://bugs.python.org/issue1533164
        # this test will run only if the rpm command is found
        if (find_executable('rpm') is None or
            find_executable('rpmbuild') is None):
            return

        # let's create a package that brakes bdist_rpm
        tmp_dir = self.mkdtemp()
        pkg_dir = os.path.join(tmp_dir, 'foo')
        os.mkdir(pkg_dir)
        self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
        self.write_file((pkg_dir, 'foo.py'), '#')
        self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
        self.write_file((pkg_dir, 'README'), '')

        dist = Distribution({'name': 'foo', 'version': '0.1',
                             'py_modules': ['foo'],
                             'url': 'xxx', 'author': 'xxx',
                             'author_email': 'xxx'})
        dist.script_name = 'setup.py'
        os.chdir(pkg_dir)

        sys.argv = ['setup.py']
        cmd = bdist_rpm(dist)
        cmd.fix_python = True

        cmd.quiet = 1
        cmd.ensure_finalized()
        cmd.run()

        dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
        self.assertTrue('foo-0.1-1.noarch.rpm' in dist_created)

        # bug #2945: upload ignores bdist_rpm files
        self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.src.rpm'), dist.dist_files)
        self.assertIn(('bdist_rpm', 'any', 'dist/foo-0.1-1.noarch.rpm'), dist.dist_files)

        os.remove(os.path.join(pkg_dir, 'dist', 'foo-0.1-1.noarch.rpm'))
예제 #35
0
    def test_package_data(self):
        sources = self.mkdtemp()
        f = open(os.path.join(sources, "__init__.py"), "w")
        f.write("# Pretend this is a package.")
        f.close()
        f = open(os.path.join(sources, "README.txt"), "w")
        f.write("Info about this package")
        f.close()

        destination = self.mkdtemp()

        dist = Distribution({
            "packages": ["pkg"],
            "package_dir": {
                "pkg": sources
            }
        })
        # script_name need not exist, it just need to be initialized
        dist.script_name = os.path.join(sources, "setup.py")
        dist.command_obj["build"] = support.DummyCommand(force=0,
                                                         build_lib=destination)
        dist.packages = ["pkg"]
        dist.package_data = {"pkg": ["README.txt"]}
        dist.package_dir = {"pkg": sources}

        cmd = build_py(dist)
        cmd.compile = 1
        cmd.ensure_finalized()
        self.assertEqual(cmd.package_data, dist.package_data)

        cmd.run()

        # This makes sure the list of outputs includes byte-compiled
        # files for Python modules but not for package data files
        # (there shouldn't *be* byte-code files for those!).
        #
        self.assertEqual(len(cmd.get_outputs()), 3)
        pkgdest = os.path.join(destination, "pkg")
        files = os.listdir(pkgdest)
        self.assert_("__init__.py" in files)
        if sys.platform.startswith('java'):
            self.assert_("__init__$py.class" in files, files)
        else:
            self.assert_("__init__.pyc" in files)
        self.assert_("README.txt" in files)
예제 #36
0
    def test_make_distribution(self):

        # check if tar and gzip are installed
        if (find_executable('tar') is None or
            find_executable('gzip') is None):
            return

        self._init_tmp_pkg()

        # now building a sdist
        dist = Distribution()
        dist.script_name = 'setup.py'
        dist.metadata.name = 'fake'
        dist.metadata.version = '1.0'
        dist.metadata.url = 'http://xxx'
        dist.metadata.author = dist.metadata.author_email = 'xxx'
        dist.packages = ['somecode']
        dist.include_package_data = True
        cmd = sdist(dist)
        cmd.manifest = 'MANIFEST'
        cmd.template = 'MANIFEST.in'
        cmd.dist_dir = 'dist'

        # creating a gztar then a tar
        cmd.formats = ['gztar', 'tar']
        cmd.run()

        # making sure we have two files
        dist_folder = join(self.temp_pkg, 'dist')
        result = os.listdir(dist_folder)
        result.sort()
        self.assertEquals(result,
                          ['fake-1.0.tar', 'fake-1.0.tar.gz'] )

        os.remove(join(dist_folder, 'fake-1.0.tar'))
        os.remove(join(dist_folder, 'fake-1.0.tar.gz'))

        # now trying a tar then a gztar
        cmd.formats = ['tar', 'gztar']
        cmd.run()

        result = os.listdir(dist_folder)
        result.sort()
        self.assertEquals(result,
                ['fake-1.0.tar', 'fake-1.0.tar.gz'])
예제 #37
0
    def test_quiet(self):

        # XXX I am unable yet to make this test work without
        # spurious sdtout/stderr output under Mac OS X
        if sys.platform != 'linux2':
            return

        # this test will run only if the rpm commands are found
        if (find_executable('rpm') is None
                or find_executable('rpmbuild') is None):
            return

        # let's create a package
        tmp_dir = self.mkdtemp()
        pkg_dir = os.path.join(tmp_dir, 'foo')
        os.mkdir(pkg_dir)
        self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
        self.write_file((pkg_dir, 'foo.py'), '#')
        self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
        self.write_file((pkg_dir, 'README'), '')

        dist = Distribution({
            'name': 'foo',
            'version': '0.1',
            'py_modules': ['foo'],
            'url': 'xxx',
            'author': 'xxx',
            'author_email': 'xxx'
        })
        dist.script_name = 'setup.py'
        os.chdir(pkg_dir)

        sys.argv = ['setup.py']
        cmd = bdist_rpm(dist)
        cmd.fix_python = True

        # running in quiet mode
        cmd.quiet = 1
        cmd.ensure_finalized()
        cmd.run()

        dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
        self.assertTrue('foo-0.1-1.noarch.rpm' in dist_created)
예제 #38
0
    def test_package_data(self):
        sources = self.mkdtemp()
        f = open(os.path.join(sources, "__init__.py"), "w")
        f.write("# Pretend this is a package.")
        f.close()
        f = open(os.path.join(sources, "README.txt"), "w")
        f.write("Info about this package")
        f.close()

        destination = self.mkdtemp()

        dist = Distribution({"packages": ["pkg"],
                             "package_dir": {"pkg": sources}})
        # script_name need not exist, it just need to be initialized
        dist.script_name = os.path.join(sources, "setup.py")
        dist.command_obj["build"] = support.DummyCommand(
            force=0,
            build_lib=destination)
        dist.packages = ["pkg"]
        dist.package_data = {"pkg": ["README.txt"]}
        dist.package_dir = {"pkg": sources}

        cmd = build_py(dist)
        cmd.compile = 1
        cmd.ensure_finalized()
        self.assertEqual(cmd.package_data, dist.package_data)

        cmd.run()

        # This makes sure the list of outputs includes byte-compiled
        # files for Python modules but not for package data files
        # (there shouldn't *be* byte-code files for those!).
        #
        self.assertEqual(len(cmd.get_outputs()), 3)
        pkgdest = os.path.join(destination, "pkg")
        files = os.listdir(pkgdest)
        self.assert_("__init__.py" in files)
        if sys.platform.startswith('java'):
            self.assert_("__init__$py.class" in files, files)
        else:
            self.assert_("__init__.pyc" in files)
        self.assert_("README.txt" in files)
예제 #39
0
 def test_package_data(self):
     sources = self.mkdtemp()
     f = open(os.path.join(sources, '__init__.py'), 'w')
     try:
         f.write('# Pretend this is a package.')
     finally:
         f.close()
     f = open(os.path.join(sources, 'README.txt'), 'w')
     try:
         f.write('Info about this package')
     finally:
         f.close()
     destination = self.mkdtemp()
     dist = Distribution({
         'packages': ['pkg'],
         'package_dir': {
             'pkg': sources
         }
     })
     dist.script_name = os.path.join(sources, 'setup.py')
     dist.command_obj['build'] = support.DummyCommand(force=0,
                                                      build_lib=destination)
     dist.packages = ['pkg']
     dist.package_data = {'pkg': ['README.txt']}
     dist.package_dir = {'pkg': sources}
     cmd = build_py(dist)
     cmd.compile = 1
     cmd.ensure_finalized()
     self.assertEqual(cmd.package_data, dist.package_data)
     cmd.run()
     self.assertEqual(len(cmd.get_outputs()), 3)
     pkgdest = os.path.join(destination, 'pkg')
     files = os.listdir(pkgdest)
     pycache_dir = os.path.join(pkgdest, '__pycache__')
     self.assertIn('__init__.py', files)
     self.assertIn('README.txt', files)
     if sys.dont_write_bytecode:
         self.assertFalse(os.path.exists(pycache_dir))
     else:
         pyc_files = os.listdir(pycache_dir)
         self.assertIn('__init__.%s.pyc' % sys.implementation.cache_tag,
                       pyc_files)
예제 #40
0
    def test_simple_built(self):
        tmp_dir = self.mkdtemp()
        pkg_dir = os.path.join(tmp_dir, "foo")
        os.mkdir(pkg_dir)
        self.write_file((pkg_dir, "setup.py"), SETUP_PY)
        self.write_file((pkg_dir, "foo.py"), "#")
        self.write_file((pkg_dir, "MANIFEST.in"), "include foo.py")
        self.write_file((pkg_dir, "README"), "")
        dist = Distribution(
            {
                "name": "foo",
                "version": "0.1",
                "py_modules": ["foo"],
                "url": "xxx",
                "author": "xxx",
                "author_email": "xxx",
            }
        )
        dist.script_name = "setup.py"
        os.chdir(pkg_dir)
        sys.argv = ["setup.py"]
        cmd = bdist_dumb(dist)
        cmd.format = "zip"
        cmd.ensure_finalized()
        cmd.run()
        dist_created = os.listdir(os.path.join(pkg_dir, "dist"))
        base = "%s.%s.zip" % (dist.get_fullname(), cmd.plat_name)
        if os.name == "os2":
            base = base.replace(":", "-")
        self.assertEqual(dist_created, [base])
        fp = zipfile.ZipFile(os.path.join("dist", base))
        try:
            contents = fp.namelist()
        finally:
            fp.close()

        contents = sorted((os.path.basename(fn) for fn in contents))
        wanted = ["foo-0.1-py%s.%s.egg-info" % sys.version_info[:2], "foo.py"]
        if not sys.dont_write_bytecode:
            wanted.append("foo.pyc")
        self.assertEqual(contents, sorted(wanted))
예제 #41
0
    def test_simple_built(self):

        # let's create a simple package
        tmp_dir = self.mkdtemp()
        pkg_dir = os.path.join(tmp_dir, 'foo')
        os.mkdir(pkg_dir)
        self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
        self.write_file((pkg_dir, 'foo.py'), '#')
        self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
        self.write_file((pkg_dir, 'README'), '')

        dist = Distribution({
            'name': 'foo',
            'version': '0.1',
            'py_modules': ['foo'],
            'url': 'xxx',
            'author': 'xxx',
            'author_email': 'xxx'
        })
        dist.script_name = 'setup.py'
        os.chdir(pkg_dir)

        sys.argv = ['setup.py']
        cmd = bdist_dumb(dist)

        # so the output is the same no matter
        # what is the platform
        cmd.format = 'zip'

        cmd.ensure_finalized()
        cmd.run()

        # see what we have
        dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
        base = "%s.%s" % (dist.get_fullname(), cmd.plat_name)
        if os.name == 'os2':
            base = base.replace(':', '-')

        wanted = ['%s.zip' % base]
        self.assertEqual(dist_created, wanted)
예제 #42
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 ''")
예제 #43
0
    def test_no_optimize_flag(self):
        # let's create a package that brakes bdist_rpm
        tmp_dir = self.mkdtemp()
        pkg_dir = os.path.join(tmp_dir, "foo")
        os.mkdir(pkg_dir)
        self.write_file((pkg_dir, "setup.py"), SETUP_PY)
        self.write_file((pkg_dir, "foo.py"), "#")
        self.write_file((pkg_dir, "MANIFEST.in"), "include foo.py")
        self.write_file((pkg_dir, "README"), "")

        dist = Distribution(
            {
                "name": "foo",
                "version": "0.1",
                "py_modules": ["foo"],
                "url": "xxx",
                "author": "xxx",
                "author_email": "xxx",
            }
        )
        dist.script_name = "setup.py"
        os.chdir(pkg_dir)

        sys.argv = ["setup.py"]
        cmd = bdist_rpm(dist)
        cmd.fix_python = True

        cmd.quiet = 1
        cmd.ensure_finalized()
        cmd.run()

        dist_created = os.listdir(os.path.join(pkg_dir, "dist"))
        self.assertIn("foo-0.1-1.noarch.rpm", dist_created)

        # bug #2945: upload ignores bdist_rpm files
        self.assertIn(("bdist_rpm", "any", "dist/foo-0.1-1.src.rpm"), dist.dist_files)
        self.assertIn(("bdist_rpm", "any", "dist/foo-0.1-1.noarch.rpm"), dist.dist_files)

        os.remove(os.path.join(pkg_dir, "dist", "foo-0.1-1.noarch.rpm"))
예제 #44
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')
예제 #45
0
    def test_quiet(self):

        # XXX I am unable yet to make this test work without
        # spurious sdtout/stderr output under Mac OS X
        if sys.platform != 'linux2':
            return

        # this test will run only if the rpm commands are found
        if (find_executable('rpm') is None or
            find_executable('rpmbuild') is None):
            return

        # let's create a package
        tmp_dir = self.mkdtemp()
        pkg_dir = os.path.join(tmp_dir, 'foo')
        os.mkdir(pkg_dir)
        self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
        self.write_file((pkg_dir, 'foo.py'), '#')
        self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
        self.write_file((pkg_dir, 'README'), '')

        dist = Distribution({'name': 'foo', 'version': '0.1',
                             'py_modules': ['foo'],
                             'url': 'xxx', 'author': 'xxx',
                             'author_email': 'xxx'})
        dist.script_name = 'setup.py'
        os.chdir(pkg_dir)

        sys.argv = ['setup.py']
        cmd = bdist_rpm(dist)
        cmd.fix_python = True

        # running in quiet mode
        cmd.quiet = 1
        cmd.ensure_finalized()
        cmd.run()

        dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
        self.assertTrue('foo-0.1-1.noarch.rpm' in dist_created)
예제 #46
0
    def test_package_data(self):
        sources = self.mkdtemp()
        f = open(os.path.join(sources, '__init__.py'), 'w')
        try:
            f.write('# Pretend this is a package.')
        finally:
            f.close()

        f = open(os.path.join(sources, 'README.txt'), 'w')
        try:
            f.write('Info about this package')
        finally:
            f.close()

        destination = self.mkdtemp()
        dist = Distribution({'packages': ['pkg'],
         'package_dir': {'pkg': sources}})
        dist.script_name = os.path.join(sources, 'setup.py')
        dist.command_obj['build'] = support.DummyCommand(force=0, build_lib=destination)
        dist.packages = ['pkg']
        dist.package_data = {'pkg': ['README.txt']}
        dist.package_dir = {'pkg': sources}
        cmd = build_py(dist)
        cmd.compile = 1
        cmd.ensure_finalized()
        self.assertEqual(cmd.package_data, dist.package_data)
        cmd.run()
        self.assertEqual(len(cmd.get_outputs()), 3)
        pkgdest = os.path.join(destination, 'pkg')
        files = os.listdir(pkgdest)
        self.assertIn('__init__.py', files)
        self.assertIn('README.txt', files)
        if sys.dont_write_bytecode:
            self.assertNotIn('__init__.pyc', files)
        else:
            self.assertIn('__init__.pyc', files)
예제 #47
0
    def test_home_installation_scheme(self):
        builddir = self.mkdtemp()
        destination = os.path.join(builddir, 'installation')
        dist = Distribution({'name': 'foopkg'})
        dist.script_name = os.path.join(builddir, 'setup.py')
        dist.command_obj['build'] = support.DummyCommand(build_base=builddir, build_lib=os.path.join(builddir, 'lib'))
        cmd = install(dist)
        cmd.home = destination
        cmd.ensure_finalized()
        self.assertEqual(cmd.install_base, destination)
        self.assertEqual(cmd.install_platbase, destination)

        def check_path(got, expected):
            got = os.path.normpath(got)
            expected = os.path.normpath(expected)
            self.assertEqual(got, expected)

        libdir = os.path.join(destination, 'lib', 'python')
        check_path(cmd.install_lib, libdir)
        check_path(cmd.install_platlib, libdir)
        check_path(cmd.install_purelib, libdir)
        check_path(cmd.install_headers, os.path.join(destination, 'include', 'python', 'foopkg'))
        check_path(cmd.install_scripts, os.path.join(destination, 'bin'))
        check_path(cmd.install_data, destination)
예제 #48
0
    def test_simple_built(self):

        # let's create a simple package
        tmp_dir = self.mkdtemp()
        pkg_dir = os.path.join(tmp_dir, 'foo')
        os.mkdir(pkg_dir)
        self.write_file((pkg_dir, 'setup.py'), SETUP_PY)
        self.write_file((pkg_dir, 'foo.py'), '#')
        self.write_file((pkg_dir, 'MANIFEST.in'), 'include foo.py')
        self.write_file((pkg_dir, 'README'), '')

        dist = Distribution({'name': 'foo', 'version': '0.1',
                             'py_modules': ['foo'],
                             'url': 'xxx', 'author': 'xxx',
                             'author_email': 'xxx'})
        dist.script_name = 'setup.py'
        os.chdir(pkg_dir)

        sys.argv = ['setup.py']
        cmd = bdist_dumb(dist)

        # so the output is the same no matter
        # what is the platform
        cmd.format = 'zip'

        cmd.ensure_finalized()
        cmd.run()

        # see what we have
        dist_created = os.listdir(os.path.join(pkg_dir, 'dist'))
        base = "%s.%s" % (dist.get_fullname(), cmd.plat_name)
        if os.name == 'os2':
            base = base.replace(':', '-')

        wanted = ['%s.zip' % base]
        self.assertEquals(dist_created, wanted)
예제 #49
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(