Example #1
0
    def test_4_normalizing_pathlib_path(self):
        """
		Tests passing pathlib.Path as argument.
		"""
        from pathlib import Path
        first_spec = normalize_file(Path('a.txt'))
        second_spec = normalize_file('a.txt')
        self.assertEqual(first_spec, second_spec)
Example #2
0
File: ignore.py Project: lcbasu/dvc
    def matches(self, dirname, basename, is_dir=False):
        # NOTE: `relpath` is too slow, so we have to assume that both
        # `dirname` and `self.dirname` are relative or absolute together.
        if dirname == self.dirname:
            path = basename
        elif dirname.startswith(self.prefix):
            rel = dirname[len(self.prefix) :]
            # NOTE: `os.path.join` is ~x5.5 slower
            path = f"{rel}{os.sep}{basename}"
        else:
            return False

        if not System.is_unix():
            path = normalize_file(path)
        return self.ignore(path, is_dir)
Example #3
0
File: ignore.py Project: jhhuh/dvc
    def _get_normalize_path(self, dirname, basename):
        # NOTE: `relpath` is too slow, so we have to assume that both
        # `dirname` and `self.dirname` are relative or absolute together.
        if dirname == self.dirname:
            path = basename
        elif dirname.startswith(self.prefix):
            rel = dirname[len(self.prefix):]
            # NOTE: `os.path.join` is ~x5.5 slower
            path = f"{rel}{self.sep}{basename}"
        else:
            return False

        if os.name == "nt":
            path = normalize_file(path)
        return path
Example #4
0
    def match_file(self, filepath):
        """Match file against match patterns.

        NOTE: only match patterns are considered, not the `linked_files` argument of
        this class.

        # Arguments:
            filepath (str): the path to match.

        # Returns:
            Boolean, whether the path is a match or not.
        """
        if self._path_spec is None:
            return True
        return match_file(self._path_spec.patterns, normalize_file(filepath))
Example #5
0
def change_rule(rule, rel):
    rule = rule.strip()
    if _is_comment(rule):
        return rule
    not_ignore, rule = _not_ignore(rule)
    match_all, rule = _match_all_level(rule)
    rule = _remove_slash(rule)
    if not match_all:
        rule = f"/{rule}"
    else:
        rule = f"/**/{rule}"
    if not_ignore:
        rule = f"!/{rel}{rule}"
    else:
        rule = f"/{rel}{rule}"
    rule = normalize_file(rule)
    return rule