logger: type-safe logger.trace (#10083)

* use logger.getChild from `dvc.log` instead of `logging.getLogger`

I got tired adding `# type: ignore[attr-defined]` while using `logger.trace`.
So, now you need to import logger from `from dvc.log import logger` and
create a child logger using `logger.getChild(__name__)`. `logger.getChild`
will return a logger type-hinted as a logger having a `trace` method.

So, from now on, instead of:
```python
import logging

logger = logging.getogger(__name__)
```

you'll have to do following:
```python
from dvc.log import logger

logger = logger.getChild(__name__)
```

* remove all dvc imports from dvc.logger

* use Tqdm back
This commit is contained in:
skshetry
2023-11-10 12:55:49 +05:45
committed by GitHub
parent cbc111b519
commit 519cce3fe4
132 changed files with 328 additions and 349 deletions
+1 -2
View File
@@ -7,8 +7,7 @@ from dvc.cli import main
from dvc.dvcfile import PROJECT_FILE
from dvc.exceptions import OverlappingOutputPathsError
from dvc.repo import Repo
from dvc.repo.plots import PlotMetricTypeError
from dvc.utils import onerror_collect
from dvc.repo.plots import PlotMetricTypeError, onerror_collect
from dvc.utils.fs import remove
from dvc.utils.serialize import EncodingError, YAMLFileCorruptedError, modify_yaml
from tests.utils.plots import get_plot
+5 -3
View File
@@ -4,7 +4,7 @@ import re
import subprocess
import sys
from collections import defaultdict
from contextlib import contextmanager
from contextlib import contextmanager, suppress
from http.server import HTTPServer, SimpleHTTPRequestHandler
from pathlib import Path
from threading import Thread
@@ -108,7 +108,8 @@ def test_analytics(tmp_path, server):
assert match, "no match for the pid"
pid = int(match.group(1).strip())
psutil.Process(pid).wait(timeout=10)
with suppress(psutil.NoSuchProcess):
psutil.Process(pid).wait(timeout=10)
assert not os.path.exists(report_file)
assert f"Process {pid} exiting with 0" in logfile.read_text(encoding="utf8")
assert server.RequestHandlerClass.hits == {"POST": 1}
@@ -138,7 +139,8 @@ def test_updater(tmp_dir, dvc, server):
assert match, "no match for the pid"
pid = int(match.group(1).strip())
psutil.Process(pid).wait(timeout=10)
with suppress(psutil.NoSuchProcess):
psutil.Process(pid).wait(timeout=10)
assert f"Process {pid} exiting with 0" in logfile.read_text(encoding="utf8")
assert server.RequestHandlerClass.hits == {"GET": 1}
# check that the file is saved correctly