Skip to content

Commit

Permalink
Merge pull request #70 from Ouranosinc/remove-ignores
Browse files Browse the repository at this point in the history
  • Loading branch information
fmigneault authored Oct 12, 2024
2 parents bb3977f + 63bab54 commit 41ebea4
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
allow-failure: [false]
test-case: [test-only] # add other test variations to run for every python/os/failure combinations
# tests with single run
Expand Down
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ Changes
`Unreleased <https://github.com/Ouranosinc/cowbird/tree/master>`_ (latest)
------------------------------------------------------------------------------------

* Nothing yet.
* Drop Python 3.8 support.
* Pin ``watchdog>=5`` to employ typing fixes.
* Pin ``requests>=2.32.3`` to fix security vulnerability.
* Pin ``setuptools>=70.0.0`` to fix security vulnerability.

`2.4.0 <https://github.com/Ouranosinc/cowbird/tree/2.4.0>`_ (2024-07-09)
------------------------------------------------------------------------------------
Expand Down
35 changes: 18 additions & 17 deletions cowbird/monitoring/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from watchdog.observers.api import BaseObserver

from cowbird.monitoring.fsmonitor import FSMonitor
from cowbird.utils import get_logger
from cowbird.utils import bytes2str, get_logger

LOGGER = get_logger(__name__)

Expand Down Expand Up @@ -153,11 +153,11 @@ def start(self) -> None:
LOGGER.error(msg)
raise MonitorException(msg)
self.__event_observer = Observer()
self.__event_observer.schedule(self, # type: ignore[no-untyped-call]
self.__event_observer.schedule(self,
self.__src_path,
recursive=self.__recursive)
try:
self.__event_observer.start() # type: ignore[no-untyped-call]
self.__event_observer.start()
except OSError:
LOGGER.warning("Cannot monitor the following file or directory [%s]: No such file or directory",
self.__src_path)
Expand All @@ -166,46 +166,47 @@ def stop(self) -> None:
"""
Stop the monitoring so that events stop to be fired.
"""
self.__event_observer.stop() # type: ignore[no-untyped-call]
self.__event_observer.stop()
self.__event_observer.join()
self.__event_observer = None

def on_moved(self, event: Union[DirMovedEvent, FileMovedEvent]) -> None: # type: ignore[override]
def on_moved(self, event: Union[DirMovedEvent, FileMovedEvent]) -> None:
"""
Called when a file or a directory is moved or renamed.
:param event: Event representing file/directory movement.
"""
self.__callback.on_deleted(event.src_path)
event_dest_path = bytes2str(event.dest_path)
event_src_path = bytes2str(event.src_path)
self_src_path = bytes2str(self.__src_path)
self.__callback.on_deleted(event_src_path)
# If moved outside of __src_path don't send a create event
if event.dest_path.startswith(self.__src_path):
if event_dest_path.startswith(self_src_path):
# If move under subdirectory and recursive is False don't send a
# create event neither
if self.__recursive or \
os.path.dirname(event.dest_path) == \
os.path.dirname(self.__src_path):
self.__callback.on_created(event.dest_path)
if self.__recursive or os.path.dirname(event_dest_path) == os.path.dirname(self_src_path):
self.__callback.on_created(event_dest_path)

def on_created(self, event: Union[DirCreatedEvent, FileCreatedEvent]) -> None: # type: ignore[override]
def on_created(self, event: Union[DirCreatedEvent, FileCreatedEvent]) -> None:
"""
Called when a file or directory is created.
:param event: Event representing file/directory creation.
"""
self.__callback.on_created(event.src_path)
self.__callback.on_created(bytes2str(event.src_path))

def on_deleted(self, event: Union[DirDeletedEvent, FileDeletedEvent]) -> None: # type: ignore[override]
def on_deleted(self, event: Union[DirDeletedEvent, FileDeletedEvent]) -> None:
"""
Called when a file or directory is deleted.
:param event: Event representing file/directory deletion.
"""
self.__callback.on_deleted(event.src_path)
self.__callback.on_deleted(bytes2str(event.src_path))

def on_modified(self, event: Union[DirModifiedEvent, FileModifiedEvent]) -> None: # type: ignore[override]
def on_modified(self, event: Union[DirModifiedEvent, FileModifiedEvent]) -> None:
"""
Called when a file or directory is modified.
:param event: Event representing file/directory modification.
"""
self.__callback.on_modified(event.src_path)
self.__callback.on_modified(bytes2str(event.src_path))
9 changes: 9 additions & 0 deletions cowbird/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ def bool2str(value: Any) -> str:
return "true" if str(value).lower() in truthy else "false"


def bytes2str(string: Union[str, bytes]) -> str:
"""
Ensures a string is represented in UTF-8.
"""
if isinstance(string, bytes):
return string.decode("utf-8")
return string


def islambda(func: Any) -> bool:
"""
Evaluate if argument is a callable :class:`lambda` expression.
Expand Down
2 changes: 1 addition & 1 deletion requirements-sys.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

packaging
pip>=22.0
setuptools>=65.5.1
setuptools>=70.0.0
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ pyramid_mako>=1.0.2
pyramid_celery @ git+https://github.com/crim-ca/pyramid_celery.git@5.0.0a
python-dotenv
pyyaml>=5.1
requests
requests>=2.32.3
requests_file
schema
simplejson
threddsclient==0.4.6
typing_extensions
urllib3>=2.2.2
watchdog>=4
watchdog>=5
webob
zipp>=3.19.1 # not directly required, pinned by Snyk to avoid a vulnerability
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ def _extra_requirements(base_requirements: Iterable[str], other_requirements: It
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
python_requires=">=3.8, <4",
python_requires=">=3.9, <4",

# -- Package structure -------------------------------------------------
packages=[__meta__.__package__],
Expand Down

0 comments on commit 41ebea4

Please sign in to comment.