-
-
Notifications
You must be signed in to change notification settings - Fork 704
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Run ruff, apply several fixes (#1033)
- code simplifications here and there - introduce a proxy to guess the best `observer` class to import
- Loading branch information
Showing
29 changed files
with
347 additions
and
519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
eventlet | ||
flake8 | ||
flaky | ||
isort | ||
pytest | ||
pytest-cov | ||
pytest-timeout | ||
ruff | ||
sphinx | ||
mypy | ||
types-PyYAML |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,7 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
""" | ||
:module: watchdog.events | ||
""":module: watchdog.events | ||
:synopsis: File system events and event handlers. | ||
:author: [email protected] (Yesudeep Mangalapilly) | ||
:author: [email protected] (Mickaël Schoentgen) | ||
|
@@ -111,8 +110,7 @@ | |
|
||
@dataclass(unsafe_hash=True) | ||
class FileSystemEvent: | ||
""" | ||
Immutable type that represents a file system event that is triggered | ||
"""Immutable type that represents a file system event that is triggered | ||
when a change occurs on the monitored file system. | ||
All FileSystemEvent objects are required to be immutable and hence | ||
|
@@ -186,9 +184,7 @@ class DirDeletedEvent(FileSystemEvent): | |
|
||
|
||
class DirModifiedEvent(FileSystemEvent): | ||
""" | ||
File system event representing directory modification on the file system. | ||
""" | ||
"""File system event representing directory modification on the file system.""" | ||
|
||
event_type = EVENT_TYPE_MODIFIED | ||
is_directory = True | ||
|
@@ -208,9 +204,7 @@ class DirMovedEvent(FileSystemMovedEvent): | |
|
||
|
||
class FileSystemEventHandler: | ||
""" | ||
Base file system event handler that you can override methods from. | ||
""" | ||
"""Base file system event handler that you can override methods from.""" | ||
|
||
def dispatch(self, event: FileSystemEvent) -> None: | ||
"""Dispatches events to the appropriate methods. | ||
|
@@ -317,32 +311,28 @@ def __init__( | |
|
||
@property | ||
def patterns(self): | ||
""" | ||
(Read-only) | ||
"""(Read-only) | ||
Patterns to allow matching event paths. | ||
""" | ||
return self._patterns | ||
|
||
@property | ||
def ignore_patterns(self): | ||
""" | ||
(Read-only) | ||
"""(Read-only) | ||
Patterns to ignore matching event paths. | ||
""" | ||
return self._ignore_patterns | ||
|
||
@property | ||
def ignore_directories(self): | ||
""" | ||
(Read-only) | ||
"""(Read-only) | ||
``True`` if directories should be ignored; ``False`` otherwise. | ||
""" | ||
return self._ignore_directories | ||
|
||
@property | ||
def case_sensitive(self): | ||
""" | ||
(Read-only) | ||
"""(Read-only) | ||
``True`` if path names should be matched sensitive to case; ``False`` | ||
otherwise. | ||
""" | ||
|
@@ -399,39 +389,35 @@ def __init__( | |
self._regexes = [re.compile(r) for r in regexes] | ||
self._ignore_regexes = [re.compile(r) for r in ignore_regexes] | ||
else: | ||
self._regexes = [re.compile(r, re.I) for r in regexes] | ||
self._ignore_regexes = [re.compile(r, re.I) for r in ignore_regexes] | ||
self._regexes = [re.compile(r, re.IGNORECASE) for r in regexes] | ||
self._ignore_regexes = [re.compile(r, re.IGNORECASE) for r in ignore_regexes] | ||
self._ignore_directories = ignore_directories | ||
self._case_sensitive = case_sensitive | ||
|
||
@property | ||
def regexes(self): | ||
""" | ||
(Read-only) | ||
"""(Read-only) | ||
Regexes to allow matching event paths. | ||
""" | ||
return self._regexes | ||
|
||
@property | ||
def ignore_regexes(self): | ||
""" | ||
(Read-only) | ||
"""(Read-only) | ||
Regexes to ignore matching event paths. | ||
""" | ||
return self._ignore_regexes | ||
|
||
@property | ||
def ignore_directories(self): | ||
""" | ||
(Read-only) | ||
"""(Read-only) | ||
``True`` if directories should be ignored; ``False`` otherwise. | ||
""" | ||
return self._ignore_directories | ||
|
||
@property | ||
def case_sensitive(self): | ||
""" | ||
(Read-only) | ||
"""(Read-only) | ||
``True`` if path names should be matched sensitive to case; ``False`` | ||
otherwise. | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,7 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
""" | ||
:module: watchdog.observers | ||
""":module: watchdog.observers | ||
:synopsis: Observer that picks a native implementation if available. | ||
:author: [email protected] (Yesudeep Mangalapilly) | ||
:author: [email protected] (Mickaël Schoentgen) | ||
|
@@ -52,46 +51,52 @@ | |
|
||
from __future__ import annotations | ||
|
||
import contextlib | ||
import warnings | ||
from typing import TYPE_CHECKING | ||
|
||
from watchdog.utils import UnsupportedLibc, platform | ||
|
||
from .api import BaseObserverSubclassCallable | ||
|
||
Observer: BaseObserverSubclassCallable | ||
if TYPE_CHECKING: | ||
from watchdog.observers.api import BaseObserverSubclassCallable | ||
|
||
|
||
if platform.is_linux(): | ||
try: | ||
from .inotify import InotifyObserver as Observer | ||
except UnsupportedLibc: | ||
from .polling import PollingObserver as Observer | ||
def _get_observer_cls() -> BaseObserverSubclassCallable: | ||
if platform.is_linux(): | ||
with contextlib.suppress(UnsupportedLibc): | ||
from watchdog.observers.inotify import InotifyObserver | ||
|
||
elif platform.is_darwin(): | ||
try: | ||
from .fsevents import FSEventsObserver as Observer | ||
except Exception: | ||
return InotifyObserver | ||
elif platform.is_darwin(): | ||
try: | ||
from .kqueue import KqueueObserver as Observer | ||
|
||
warnings.warn("Failed to import fsevents. Fall back to kqueue") | ||
from watchdog.observers.fsevents import FSEventsObserver | ||
except Exception: | ||
try: | ||
from watchdog.observers.kqueue import KqueueObserver | ||
except Exception: | ||
warnings.warn("Failed to import fsevents and kqueue. Fall back to polling.") | ||
else: | ||
warnings.warn("Failed to import fsevents. Fall back to kqueue") | ||
return KqueueObserver | ||
else: | ||
return FSEventsObserver | ||
elif platform.is_windows(): | ||
try: | ||
from watchdog.observers.read_directory_changes import WindowsApiObserver | ||
except Exception: | ||
from .polling import PollingObserver as Observer | ||
warnings.warn("Failed to import `read_directory_changes`. Fall back to polling.") | ||
else: | ||
return WindowsApiObserver | ||
elif platform.is_bsd(): | ||
from watchdog.observers.kqueue import KqueueObserver | ||
|
||
warnings.warn("Failed to import fsevents and kqueue. Fall back to polling.") | ||
return KqueueObserver | ||
|
||
elif platform.is_bsd(): | ||
from .kqueue import KqueueObserver as Observer | ||
from watchdog.observers.polling import PollingObserver | ||
|
||
elif platform.is_windows(): | ||
try: | ||
from .read_directory_changes import WindowsApiObserver as Observer | ||
except Exception: | ||
from .polling import PollingObserver as Observer | ||
return PollingObserver | ||
|
||
warnings.warn("Failed to import read_directory_changes. Fall back to polling.") | ||
|
||
else: | ||
from .polling import PollingObserver as Observer | ||
Observer = _get_observer_cls() | ||
|
||
__all__ = ["Observer"] |
Oops, something went wrong.