Ejemplo n.º 1
0
 def test_exclude_pattern(self):
     file_list = FileList()
     self.assertFalse(file_list.exclude_pattern('*.py'))
     file_list = FileList()
     file_list.files = ['a.py', 'b.py']
     self.assertTrue(file_list.exclude_pattern('*.py'))
     file_list = FileList()
     file_list.files = ['a.py', 'a.txt']
     file_list.exclude_pattern('*.py')
     self.assertEqual(file_list.files, ['a.txt'])
Ejemplo n.º 2
0
 def test_exclude_pattern(self):
     file_list = FileList()
     self.assertFalse(file_list.exclude_pattern("*.py"))
     file_list = FileList()
     file_list.files = ["a.py", "b.py"]
     self.assertTrue(file_list.exclude_pattern("*.py"))
     file_list = FileList()
     file_list.files = ["a.py", "a.txt"]
     file_list.exclude_pattern("*.py")
     self.assertEqual(file_list.files, ["a.txt"])
Ejemplo n.º 3
0
    def test_exclude_pattern(self):
        # return False if no match
        file_list = FileList()
        self.assertFalse(file_list.exclude_pattern('*.py'))

        # return True if files match
        file_list = FileList()
        file_list.files = ['a.py', 'b.py']
        self.assertTrue(file_list.exclude_pattern('*.py'))

        # test excludes
        file_list = FileList()
        file_list.files = ['a.py', 'a.txt']
        file_list.exclude_pattern('*.py')
        self.assertEqual(file_list.files, ['a.txt'])
Ejemplo n.º 4
0
    def test_exclude_pattern(self):
        # return False if no match
        file_list = FileList()
        self.assertFalse(file_list.exclude_pattern('*.py'))

        # return True if files match
        file_list = FileList()
        file_list.files = ['a.py', 'b.py']
        self.assertTrue(file_list.exclude_pattern('*.py'))

        # test excludes
        file_list = FileList()
        file_list.files = ['a.py', 'a.txt']
        file_list.exclude_pattern('*.py')
        self.assertEqual(file_list.files, ['a.txt'])
Ejemplo n.º 5
0
 def test_remove_duplicates(self):
     file_list = FileList()
     file_list.files = ['a', 'b', 'a', 'g', 'c', 'g']
     # files must be sorted beforehand (sdist does it)
     file_list.sort()
     file_list.remove_duplicates()
     self.assertEqual(file_list.files, ['a', 'b', 'c', 'g'])
Ejemplo n.º 6
0
 def test_remove_duplicates(self):
     file_list = FileList()
     file_list.files = ['a', 'b', 'a', 'g', 'c', 'g']
     # files must be sorted beforehand (sdist does it)
     file_list.sort()
     file_list.remove_duplicates()
     self.assertEqual(file_list.files, ['a', 'b', 'c', 'g'])
Ejemplo n.º 7
0
 def test_remove_duplicates(self):
     file_list = FileList()
     file_list.files = ['a',
      'b',
      'a',
      'g',
      'c',
      'g']
     file_list.sort()
     file_list.remove_duplicates()
     self.assertEqual(file_list.files, ['a',
      'b',
      'c',
      'g'])
Ejemplo n.º 8
0
    def copy_transformed_tree(self, install_specs, dst_root=None, src_root=None, substitutions={}):
        """
        Copy parts of a source tree to a destination tree with a
        different tree structure and/or names.

        The basic idea: given a set of source files, copy them to a
        destination directory, let's call this operation an
        install_spec. A sequence of install_spec's allows one to build
        up the destrination tree in any structure desired.

        Each install_spec consists of 3 components
        (manifest_template, dst_xforms, dst_dir):

        The manifest_template is a sequence where each item is identical
        to a line in the MANIFEST.in template described in distutils. This
        gives you ability to easily specify a set of source files in a
        compact abstract manner (with recursion, exclusion, etc.) The
        manifest_template yields a sequence of source paths.

        dst_xforms is a sequence of regular expression substitutions
        applied to the each source path to yield a rewritten destination
        path. Each transform is expressed as a two-valued sequence
        (pattern, replacement)

        dst_dir is a destination directory where the destinations paths
        are written to. dst_dir is always relative to the dst_root.

        All input may be parametrized via variable substitutions
        supplied by a substitution dict. Any use of $name will cause
        name to be looked up first in the substitution dict and then
        if its not found there in the enviorment. If found it will be
        replaced with it's value.

        The pseudo code algorithm for processing an install_spec is:

        substitute all variables in manifest template
        src_list = evaluate manifest template
        for each src_path in src_list:
            dst_path = src_path
            for each xform in dst_xform:
                apply xform to dst_path
            copy src_root+src_path to dst_root+dest_dir+dest_path

        This process is repeated for each install spec. The src_root and
        dst_root are also subject to variable substitution.


        Examples:

        Copy all text files in build/doc to doc:

            copy_transformed_tree([[["include build/doc *.txt"], None, 'doc']])

        Copy all html files found under build to doc/html and change the extension from
        .html to .htm

            copy_transformed_tree([[["include build *.html"], [('\.html$','.htm')], 'doc']])

    """

        if src_root is not None: src_root = subst_vars(src_root, substitutions)
        if dst_root is not None: dst_root = subst_vars(dst_root, substitutions)

        filelist = FileList()
        if src_root is None:
            filelist.findall()
        else:
            filelist.findall(src_root)

        for manifest_template, dst_xforms, dst_dir in install_specs:
            if dst_dir is not None: dst_dir = subst_vars(dst_dir, substitutions)

            filelist.files = [] # reinitialize to empty

            for line in manifest_template:
                filelist.process_template_line(subst_vars(line, substitutions))

            for src_path in filelist.files:
                dst_path = src_path
                if dst_xforms:
                    for dst_xform in dst_xforms:
                        dst_path = re.sub(dst_xform[0], dst_xform[1], dst_path)
                if dst_dir is not None:
                    dst_path = change_root(dst_dir, dst_path)
                if dst_root is None:
                    full_dst_path = dst_path
                else:
                    full_dst_path = change_root(dst_root, dst_path)
                full_dst_dir = os.path.dirname(full_dst_path)
                self.mkpath(full_dst_dir)
                self.copy_file(src_path, full_dst_path)
Ejemplo n.º 9
0
    def test_process_template(self):
        l = make_local_path
        # invalid lines
        file_list = FileList()
        for action in ('include', 'exclude', 'global-include',
                       'global-exclude', 'recursive-include',
                       'recursive-exclude', 'graft', 'prune', 'blarg'):
            self.assertRaises(DistutilsTemplateError,
                              file_list.process_template_line, action)

        # include
        file_list = FileList()
        file_list.set_allfiles(['a.py', 'b.txt', l('d/c.py')])

        file_list.process_template_line('include *.py')
        self.assertEqual(file_list.files, ['a.py'])
        self.assertNoWarnings()

        file_list.process_template_line('include *.rb')
        self.assertEqual(file_list.files, ['a.py'])
        self.assertWarnings()

        # exclude
        file_list = FileList()
        file_list.files = ['a.py', 'b.txt', l('d/c.py')]

        file_list.process_template_line('exclude *.py')
        self.assertEqual(file_list.files, ['b.txt', l('d/c.py')])
        self.assertNoWarnings()

        file_list.process_template_line('exclude *.rb')
        self.assertEqual(file_list.files, ['b.txt', l('d/c.py')])
        self.assertWarnings()

        # global-include
        file_list = FileList()
        file_list.set_allfiles(['a.py', 'b.txt', l('d/c.py')])

        file_list.process_template_line('global-include *.py')
        self.assertEqual(file_list.files, ['a.py', l('d/c.py')])
        self.assertNoWarnings()

        file_list.process_template_line('global-include *.rb')
        self.assertEqual(file_list.files, ['a.py', l('d/c.py')])
        self.assertWarnings()

        # global-exclude
        file_list = FileList()
        file_list.files = ['a.py', 'b.txt', l('d/c.py')]

        file_list.process_template_line('global-exclude *.py')
        self.assertEqual(file_list.files, ['b.txt'])
        self.assertNoWarnings()

        file_list.process_template_line('global-exclude *.rb')
        self.assertEqual(file_list.files, ['b.txt'])
        self.assertWarnings()

        # recursive-include
        file_list = FileList()
        file_list.set_allfiles(
            ['a.py', l('d/b.py'),
             l('d/c.txt'), l('d/d/e.py')])

        file_list.process_template_line('recursive-include d *.py')
        self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
        self.assertNoWarnings()

        file_list.process_template_line('recursive-include e *.py')
        self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
        self.assertWarnings()

        # recursive-exclude
        file_list = FileList()
        file_list.files = ['a.py', l('d/b.py'), l('d/c.txt'), l('d/d/e.py')]

        file_list.process_template_line('recursive-exclude d *.py')
        self.assertEqual(file_list.files, ['a.py', l('d/c.txt')])
        self.assertNoWarnings()

        file_list.process_template_line('recursive-exclude e *.py')
        self.assertEqual(file_list.files, ['a.py', l('d/c.txt')])
        self.assertWarnings()

        # graft
        file_list = FileList()
        file_list.set_allfiles(
            ['a.py', l('d/b.py'),
             l('d/d/e.py'), l('f/f.py')])

        file_list.process_template_line('graft d')
        self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
        self.assertNoWarnings()

        file_list.process_template_line('graft e')
        self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
        self.assertWarnings()

        # prune
        file_list = FileList()
        file_list.files = ['a.py', l('d/b.py'), l('d/d/e.py'), l('f/f.py')]

        file_list.process_template_line('prune d')
        self.assertEqual(file_list.files, ['a.py', l('f/f.py')])
        self.assertNoWarnings()

        file_list.process_template_line('prune e')
        self.assertEqual(file_list.files, ['a.py', l('f/f.py')])
        self.assertWarnings()
Ejemplo n.º 10
0
    def test_process_template(self):
        l = make_local_path
        # invalid lines
        file_list = FileList()
        for action in ('include', 'exclude', 'global-include',
                       'global-exclude', 'recursive-include',
                       'recursive-exclude', 'graft', 'prune', 'blarg'):
            self.assertRaises(DistutilsTemplateError,
                              file_list.process_template_line, action)

        # include
        file_list = FileList()
        file_list.set_allfiles(['a.py', 'b.txt', l('d/c.py')])

        file_list.process_template_line('include *.py')
        self.assertEqual(file_list.files, ['a.py'])
        self.assertNoWarnings()

        file_list.process_template_line('include *.rb')
        self.assertEqual(file_list.files, ['a.py'])
        self.assertWarnings()

        # exclude
        file_list = FileList()
        file_list.files = ['a.py', 'b.txt', l('d/c.py')]

        file_list.process_template_line('exclude *.py')
        self.assertEqual(file_list.files, ['b.txt', l('d/c.py')])
        self.assertNoWarnings()

        file_list.process_template_line('exclude *.rb')
        self.assertEqual(file_list.files, ['b.txt', l('d/c.py')])
        self.assertWarnings()

        # global-include
        file_list = FileList()
        file_list.set_allfiles(['a.py', 'b.txt', l('d/c.py')])

        file_list.process_template_line('global-include *.py')
        self.assertEqual(file_list.files, ['a.py', l('d/c.py')])
        self.assertNoWarnings()

        file_list.process_template_line('global-include *.rb')
        self.assertEqual(file_list.files, ['a.py', l('d/c.py')])
        self.assertWarnings()

        # global-exclude
        file_list = FileList()
        file_list.files = ['a.py', 'b.txt', l('d/c.py')]

        file_list.process_template_line('global-exclude *.py')
        self.assertEqual(file_list.files, ['b.txt'])
        self.assertNoWarnings()

        file_list.process_template_line('global-exclude *.rb')
        self.assertEqual(file_list.files, ['b.txt'])
        self.assertWarnings()

        # recursive-include
        file_list = FileList()
        file_list.set_allfiles(['a.py', l('d/b.py'), l('d/c.txt'),
                                l('d/d/e.py')])

        file_list.process_template_line('recursive-include d *.py')
        self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
        self.assertNoWarnings()

        file_list.process_template_line('recursive-include e *.py')
        self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
        self.assertWarnings()

        # recursive-exclude
        file_list = FileList()
        file_list.files = ['a.py', l('d/b.py'), l('d/c.txt'), l('d/d/e.py')]

        file_list.process_template_line('recursive-exclude d *.py')
        self.assertEqual(file_list.files, ['a.py', l('d/c.txt')])
        self.assertNoWarnings()

        file_list.process_template_line('recursive-exclude e *.py')
        self.assertEqual(file_list.files, ['a.py', l('d/c.txt')])
        self.assertWarnings()

        # graft
        file_list = FileList()
        file_list.set_allfiles(['a.py', l('d/b.py'), l('d/d/e.py'),
                                l('f/f.py')])

        file_list.process_template_line('graft d')
        self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
        self.assertNoWarnings()

        file_list.process_template_line('graft e')
        self.assertEqual(file_list.files, [l('d/b.py'), l('d/d/e.py')])
        self.assertWarnings()

        # prune
        file_list = FileList()
        file_list.files = ['a.py', l('d/b.py'), l('d/d/e.py'), l('f/f.py')]

        file_list.process_template_line('prune d')
        self.assertEqual(file_list.files, ['a.py', l('f/f.py')])
        self.assertNoWarnings()

        file_list.process_template_line('prune e')
        self.assertEqual(file_list.files, ['a.py', l('f/f.py')])
        self.assertWarnings()
    def copy_transformed_tree(self, install_specs, dst_root=None, src_root=None, substitutions={}):
        """
        Copy parts of a source tree to a destination tree with a
        different tree structure and/or names.

        The basic idea: given a set of source files, copy them to a
        destination directory, let's call this operation an
        install_spec. A sequence of install_spec's allows one to build
        up the destrination tree in any structure desired.

        Each install_spec consists of 3 components
        (manifest_template, dst_xforms, dst_dir):

        The manifest_template is a sequence where each item is identical
        to a line in the MANIFEST.in template described in distutils. This
        gives you ability to easily specify a set of source files in a
        compact abstract manner (with recursion, exclusion, etc.) The
        manifest_template yields a sequence of source paths.

        dst_xforms is a sequence of regular expression substitutions
        applied to the each source path to yield a rewritten destination
        path. Each transform is expressed as a two-valued sequence
        (pattern, replacement)

        dst_dir is a destination directory where the destinations paths
        are written to. dst_dir is always relative to the dst_root.

        All input may be parametrized via variable substitutions
        supplied by a substitution dict. Any use of $name will cause
        name to be looked up first in the substitution dict and then
        if its not found there in the enviorment. If found it will be
        replaced with it's value.

        The pseudo code algorithm for processing an install_spec is:

        substitute all variables in manifest template
        src_list = evaluate manifest template
        for each src_path in src_list:
            dst_path = src_path
            for each xform in dst_xform:
                apply xform to dst_path
            copy src_root+src_path to dst_root+dest_dir+dest_path

        This process is repeated for each install spec. The src_root and
        dst_root are also subject to variable substitution.


        Examples:

        Copy all text files in build/doc to doc:

            copy_transformed_tree([[["include build/doc *.txt"], None, 'doc']])

        Copy all html files found under build to doc/html and change the extension from
        .html to .htm

            copy_transformed_tree([[["include build *.html"], [('\.html$','.htm')], 'doc']])

    """

        if src_root is not None: src_root = subst_vars(src_root, substitutions)
        if dst_root is not None: dst_root = subst_vars(dst_root, substitutions)

        filelist = FileList()
        if src_root is None:
            filelist.findall()
        else:
            filelist.findall(src_root)

        for manifest_template, dst_xforms, dst_dir in install_specs:
            if dst_dir is not None: dst_dir = subst_vars(dst_dir, substitutions)

            filelist.files = [] # reinitialize to empty

            for line in manifest_template:
                filelist.process_template_line(subst_vars(line, substitutions))

            for src_path in filelist.files:
                dst_path = src_path
                if dst_xforms:
                    for dst_xform in dst_xforms:
                        dst_path = re.sub(dst_xform[0], dst_xform[1], dst_path)
                if dst_dir is not None:
                    dst_path = change_root(dst_dir, dst_path)
                if dst_root is None:
                    full_dst_path = dst_path
                else:
                    full_dst_path = change_root(dst_root, dst_path)
                full_dst_dir = os.path.dirname(full_dst_path)
                self.mkpath(full_dst_dir)
                self.copy_file(src_path, full_dst_path)
Ejemplo n.º 12
0
    def test_process_template(self):
        l = make_local_path
        file_list = FileList()
        for action in (
            "include",
            "exclude",
            "global-include",
            "global-exclude",
            "recursive-include",
            "recursive-exclude",
            "graft",
            "prune",
            "blarg",
        ):
            self.assertRaises(DistutilsTemplateError, file_list.process_template_line, action)

        file_list = FileList()
        file_list.set_allfiles(["a.py", "b.txt", l("d/c.py")])
        file_list.process_template_line("include *.py")
        self.assertEqual(file_list.files, ["a.py"])
        self.assertNoWarnings()
        file_list.process_template_line("include *.rb")
        self.assertEqual(file_list.files, ["a.py"])
        self.assertWarnings()
        file_list = FileList()
        file_list.files = ["a.py", "b.txt", l("d/c.py")]
        file_list.process_template_line("exclude *.py")
        self.assertEqual(file_list.files, ["b.txt", l("d/c.py")])
        self.assertNoWarnings()
        file_list.process_template_line("exclude *.rb")
        self.assertEqual(file_list.files, ["b.txt", l("d/c.py")])
        self.assertWarnings()
        file_list = FileList()
        file_list.set_allfiles(["a.py", "b.txt", l("d/c.py")])
        file_list.process_template_line("global-include *.py")
        self.assertEqual(file_list.files, ["a.py", l("d/c.py")])
        self.assertNoWarnings()
        file_list.process_template_line("global-include *.rb")
        self.assertEqual(file_list.files, ["a.py", l("d/c.py")])
        self.assertWarnings()
        file_list = FileList()
        file_list.files = ["a.py", "b.txt", l("d/c.py")]
        file_list.process_template_line("global-exclude *.py")
        self.assertEqual(file_list.files, ["b.txt"])
        self.assertNoWarnings()
        file_list.process_template_line("global-exclude *.rb")
        self.assertEqual(file_list.files, ["b.txt"])
        self.assertWarnings()
        file_list = FileList()
        file_list.set_allfiles(["a.py", l("d/b.py"), l("d/c.txt"), l("d/d/e.py")])
        file_list.process_template_line("recursive-include d *.py")
        self.assertEqual(file_list.files, [l("d/b.py"), l("d/d/e.py")])
        self.assertNoWarnings()
        file_list.process_template_line("recursive-include e *.py")
        self.assertEqual(file_list.files, [l("d/b.py"), l("d/d/e.py")])
        self.assertWarnings()
        file_list = FileList()
        file_list.files = ["a.py", l("d/b.py"), l("d/c.txt"), l("d/d/e.py")]
        file_list.process_template_line("recursive-exclude d *.py")
        self.assertEqual(file_list.files, ["a.py", l("d/c.txt")])
        self.assertNoWarnings()
        file_list.process_template_line("recursive-exclude e *.py")
        self.assertEqual(file_list.files, ["a.py", l("d/c.txt")])
        self.assertWarnings()
        file_list = FileList()
        file_list.set_allfiles(["a.py", l("d/b.py"), l("d/d/e.py"), l("f/f.py")])
        file_list.process_template_line("graft d")
        self.assertEqual(file_list.files, [l("d/b.py"), l("d/d/e.py")])
        self.assertNoWarnings()
        file_list.process_template_line("graft e")
        self.assertEqual(file_list.files, [l("d/b.py"), l("d/d/e.py")])
        self.assertWarnings()
        file_list = FileList()
        file_list.files = ["a.py", l("d/b.py"), l("d/d/e.py"), l("f/f.py")]
        file_list.process_template_line("prune d")
        self.assertEqual(file_list.files, ["a.py", l("f/f.py")])
        self.assertNoWarnings()
        file_list.process_template_line("prune e")
        self.assertEqual(file_list.files, ["a.py", l("f/f.py")])
        self.assertWarnings()
Ejemplo n.º 13
0
 def test_remove_duplicates(self):
     file_list = FileList()
     file_list.files = ["a", "b", "a", "g", "c", "g"]
     file_list.sort()
     file_list.remove_duplicates()
     self.assertEqual(file_list.files, ["a", "b", "c", "g"])