Skip to content
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

[core] Run ruff, apply several fixes #1033

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cirrus.yml
Expand Up @@ -16,6 +16,6 @@ task:
- python3.8 -m pip install -U pip
- python3.8 -m pip install -r requirements-tests.txt
lint_script:
- python3.8 -m flake8 docs src tests tools
- python3.8 -m ruff src
tests_script:
- python3.8 -bb -m pytest tests
21 changes: 5 additions & 16 deletions .github/workflows/tests.yml
Expand Up @@ -5,8 +5,6 @@ on:
branches:
- master
pull_request:
branches:
- '**'

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name != 'pull_request' && github.sha || '' }}
Expand All @@ -21,12 +19,12 @@ jobs:
fail-fast: false
matrix:
tox:
- name: Types
environment: types
timeout: 15
- name: Test
environment: py
timeout: 15
- name: mypy
environment: mypy
timeout: 15
os:
- name: Linux
matrix: linux
Expand All @@ -50,17 +48,8 @@ jobs:
- "pypy-3.9"
include:
- tox:
name: Flake8
environment: flake8
timeout: 5
python: "3.11"
os:
name: Linux
emoji: 🐧
runs-on: [ubuntu-latest]
- tox:
name: isort
environment: isort-ci
name: Linter
environment: lint
timeout: 5
python: "3.11"
os:
Expand Down
5 changes: 0 additions & 5 deletions .isort.cfg

This file was deleted.

1 change: 1 addition & 0 deletions changelog.rst
Expand Up @@ -8,6 +8,7 @@ Changelog

2024-xx-xx • `full history <https://github.com/gorakhargosh/watchdog/compare/v4.0.0...HEAD>`__

- [core] Run ``ruff``, apply several fixes (`#1033 <https://github.com/gorakhargosh/watchdog/pull/1033>`__)
- [inotify] Fix missing ``event_filter`` for the full emitter (`#1032 <https://github.com/gorakhargosh/watchdog/pull/1032>`__)
- Thanks to our beloved contributors: @mraspaud

Expand Down
74 changes: 69 additions & 5 deletions pyproject.toml
@@ -1,7 +1,71 @@
[tool.black]
target-version = ["py38"]
[tool.mypy]
# Ensure we know what we do
warn_redundant_casts = true
warn_unused_ignores = true
warn_unused_configs = true

# Imports management
ignore_missing_imports = true
follow_imports = "skip"

# Ensure full coverage
disallow_untyped_defs = true
disallow_incomplete_defs = true
disallow_untyped_calls = true

# Restrict dynamic typing (a little)
# e.g. `x: List[Any]` or x: List`
# disallow_any_generics = true

strict_equality = true

[tool.pytest]
addopts = """
--showlocals
-v
--cov=watchdog
--cov-report=term-missing
"""

[tool.ruff]
line-length = 120
safe = true
indent-width = 4
target-version = "py38"

[tool.ruff.lint]
extend-select = ["ALL"]
ignore = [
"ARG",
"ANN", # TODO: remove
"ANN002",
"ANN003",
"ANN401",
"B006",
"B023", # TODO: remove
"B028",
"BLE001",
"C90",
"COM",
"D",
"EM",
"ERA",
"FBT",
"FIX",
"ISC001",
"N", # Requires a major version number bump
"PERF203", # TODO: remove
"PL",
"PTH", # TODO: remove?
"S",
"TD",
"TRY003",
"UP", # TODO: when minimum python version will be 3.10
]
fixable = ["ALL"]

[tool.isort]
profile = "black"
[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
docstring-code-format = true
3 changes: 1 addition & 2 deletions requirements-tests.txt
@@ -1,10 +1,9 @@
eventlet
flake8
flaky
isort
pytest
pytest-cov
pytest-timeout
ruff
sphinx
mypy
types-PyYAML
15 changes: 0 additions & 15 deletions setup.cfg
Expand Up @@ -10,21 +10,6 @@ source-dir = docs/source
build-dir = docs/build
all_files = 1

[flake8]
ignore =
# E203 whitespace before ':', but E203 is not PEP 8 compliant
E203
# W503 line break before binary operator, but W503 is not PEP 8 compliant
W503
max-line-length = 120

[upload_sphinx]
# Requires sphinx-pypi-upload to work.
upload-dir = docs/build/html

[tool:pytest]
addopts =
--showlocals
-v
--cov=watchdog
--cov-report=term-missing
46 changes: 14 additions & 32 deletions src/watchdog/events.py 100755 → 100644
Expand Up @@ -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: yesudeep@google.com (Yesudeep Mangalapilly)
:author: contact@tiger-222.fr (Mickaël Schoentgen)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -295,9 +289,7 @@ def on_opened(self, event: FileSystemEvent) -> None:


class PatternMatchingEventHandler(FileSystemEventHandler):
"""
Matches given patterns with file paths associated with occurring events.
"""
"""Matches given patterns with file paths associated with occurring events."""

def __init__(
self,
Expand All @@ -315,32 +307,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.
"""
Expand Down Expand Up @@ -373,9 +361,7 @@ def dispatch(self, event: FileSystemEvent) -> None:


class RegexMatchingEventHandler(FileSystemEventHandler):
"""
Matches given regexes with file paths associated with occurring events.
"""
"""Matches given regexes with file paths associated with occurring events."""

def __init__(
self,
Expand Down Expand Up @@ -403,32 +389,28 @@ def __init__(

@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.
"""
Expand Down