From 5cd8392bd3f1f37219d1ff37f89546d9d6e898eb Mon Sep 17 00:00:00 2001 From: cpburnz <2126043+cpburnz@users.noreply.github.com> Date: Fri, 9 Dec 2022 23:39:38 -0500 Subject: [PATCH] Add limited feature for #65 --- CHANGES.rst | 4 +++- pathspec/util.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 4b6f38d..2fa2c26 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,16 +3,18 @@ Change History ============== -0.10.3 (TBD) +0.10.3 (TDB) ------------ Improvements: +- `Issue #65`_: Checking directories via match_file() does not work on Path objects. - `Issue #66`_/`Pull #67`_: Package not marked as py.typed. - `Issue #68`_: Exports are considered private. - `Issue #70`_/`Pull #71`_: 'Self' string literal type is Unknown in pyright. +.. _`Issue #65`: https://github.com/cpburnz/python-pathspec/issues/65 .. _`Issue #66`: https://github.com/cpburnz/python-pathspec/issues/66 .. _`Pull #67`: https://github.com/cpburnz/python-pathspec/pull/67 .. _`Issue #68`: https://github.com/cpburnz/python-pathspec/issues/68 diff --git a/pathspec/util.py b/pathspec/util.py index 38cc9e2..359058e 100644 --- a/pathspec/util.py +++ b/pathspec/util.py @@ -4,6 +4,7 @@ import os import os.path +import pathlib import posixpath import stat import warnings @@ -48,6 +49,24 @@ """ +def append_dir_sep(path: pathlib.Path) -> str: + """ + Appends the path separator to the path if the path is a directory. + This can be used to aid in distinguishing between directories and + files on the file-system by relying on the presence of a trailing path + separator. + + *path* (:class:`pathlib.path`) is the path to use. + + Returns the path (:class:`str`). + """ + str_path = str(path) + if path.is_dir(): + str_path += os.sep + + return str_path + + def detailed_match_files( patterns: Iterable[Pattern], files: Iterable[str],