Skip to content
Open
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d3ef817
Suppress known git progress logs
candleindark Oct 18, 2023
412923d
Define Git progress report matching patterns
candleindark Oct 19, 2023
638b044
Reimplement `filter()` in `SuppressKnownGitProgressLogs`
candleindark Oct 19, 2023
f5e47b8
Redefine `known_git_progress_log_types` as a set
candleindark Oct 19, 2023
5e07ecc
Eliminate unneeded group capturing in re expressions
candleindark Oct 19, 2023
5c5016e
Test `celery_app` in `make_celery.py` is instantiated correctly
candleindark Oct 19, 2023
e7b4e5a
Rename `SuppressKnownGitProgressLogs` to `SuppressKnownGitProgressRep…
candleindark Oct 19, 2023
1731edb
Rename `known_git_progress_log_types` to `known_git_progress_report_t…
candleindark Oct 19, 2023
fbea870
Modify comments
candleindark Oct 19, 2023
4461a37
RF:
candleindark Oct 19, 2023
45808f9
Merge with suggested change on return base on if op name is known
candleindark Oct 19, 2023
63736c6
Add additional comment
candleindark Oct 19, 2023
653f2b2
Provide tests for the log filter
candleindark Oct 20, 2023
ce5ca72
Merge branch 'master' into suppress-git-progress-logs
candleindark Oct 26, 2023
e60c28d
Enable datalad library mode in datalad-registry
candleindark Oct 26, 2023
d0d6270
Enable datalad library mode in datalad-registry-client
candleindark Oct 26, 2023
337bf31
Enable datalad library mode for datalad-registry in module level
candleindark Oct 26, 2023
74bf6ec
Revert "Enable datalad library mode in datalad-registry-client"
candleindark Oct 26, 2023
195ffd2
Remove custom log handler from the datalad package
candleindark Oct 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions datalad_registry/make_celery.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,63 @@
# This file provides Celery commands access to the Celery app created through
# the factory functions in datalad_registry/__init__.py
import logging
import re

from celery import Celery

from . import create_app


# === Code for suppressing known git progress logs ===
class SuppressKnownGitProgressLogs(logging.Filter):
# Known git progress log types
# These types can be found in the definition of
# `datalad.support.gitrepo.GitProgress`
known_git_progress_log_types = {
"Counting objects",
"Compressing objects",
"Writing objects",
"Receiving objects",
"Resolving deltas",
"Finding sources",
"Checking out files",
"Enumerating objects",
}

re_op_absolute = re.compile(r"(?:remote: )?([\w\s]+):\s+\d+.*")
re_op_relative = re.compile(r"(?:remote: )?([\w\s]+):\s+\d+% \(\d+/\d+\).*")

def filter(self, record):
# The following logic is based on the logic in
# `datalad.support.gitrepo.GitProgress._parse_progress_line`

msg = record.getMessage()

match = self.re_op_relative.match(msg)
if match is None:
match = self.re_op_absolute.match(msg)

if match is None:
# === msg does not match the pattern of a git progress report ===
return True

op_name = match.group(1)
if op_name not in self.known_git_progress_log_types:
# === msg matches the pattern of a git progress report
# but of an unknown type ===
return True
else:
# === msg must be a git progress report as indicated by having
# the matching pattern and is of a known type ===
return False


# Retrieve a reference to the "datalad.gitrepo" logger
dl_gitrepo_lgr = logging.getLogger("datalad.gitrepo")

# Add a filter to the "datalad.gitrepo" logger to suppress known git progress logs
dl_gitrepo_lgr.addFilter(SuppressKnownGitProgressLogs())
# === End of code for suppressing known git progress logs ===

flask_app = create_app()
celery_app: Celery = flask_app.extensions["celery"]