-
-
Notifications
You must be signed in to change notification settings - Fork 690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move to use pathlib instead of os.path and pathtools #556
Comments
We should also check pathlib2, which is a more recently updated version of the same. |
Watchdog uses only three things from
Here's how the latter two look like done with from pathlib import PureWindowsPath, PurePosixPath
def _match_path(path, included_patterns, excluded_patterns):
common_patterns = included_patterns & excluded_patterns
if common_patterns:
raise ValueError(f'conflicting patterns `{common_patterns}` included and excluded')
return (any(path.match(p) for p in included_patterns) and
not any(path.match(p) for p in excluded_patterns))
def filter_paths(paths, included_patterns = None, excluded_patterns = None, case_sensitive = True):
included = ["*"] if included_patterns is None else included_patterns
excluded = [] if excluded_patterns is None else excluded_patterns
for path in paths:
p = PurePosixPath(path) if case_sensitive else PureWindowsPath(path)
if _match_path(p, set(included), set(excluded), case_sensitive):
yield p
def match_any_paths(paths, included_patterns = None, excluded_patterns = None, case_sensitive = True):
included = ["*"] if included_patterns is None else included_patterns
excluded = [] if excluded_patterns is None else excluded_patterns
for path in paths:
p = PurePosixPath(path) if case_sensitive else PureWindowsPath(path)
if _match_path(p, set(included), set(excluded), case_sensitive):
yield p As for the
After that, there would only be two cases of |
Here's my first attempt at switching to pathlib: bstaletic@35feb63 If there's actual interest, I can make a pull request. |
Nice! Go ahead for a PR, we just dropped the Python 2.7 support so your changes will work directly. Think to "backport" docstrings and doctests from the original |
…bot tagged dependencies. Pathtools does not work with Python 3.12 ( gorakhargosh/pathtools#13 ) and qtinterfaceframework says: - Use ``pathlib`` from the standard library, instead of pathtools (`microsoft#556 <https://github.com/gorakhargosh/watchdog/pull/556>`_)
…bot tagged dependencies. Pathtools does not work with Python 3.12 ( gorakhargosh/pathtools#13 ) and qtinterfaceframework says: - Use ``pathlib`` from the standard library, instead of pathtools (`microsoft#556 <https://github.com/gorakhargosh/watchdog/pull/556>`_)
This issue created for discuss about moving to use pathlib.
I have a next questions about this:
Also, I want to know, maybe any potential problems for moving to pathlib? What youre think about this?
The text was updated successfully, but these errors were encountered: