Skip to content

Commit

Permalink
Apply pre-commit fixes to all files
Browse files Browse the repository at this point in the history
  • Loading branch information
Delgan committed Jun 19, 2022
1 parent ae3ed2c commit 7ef57c3
Show file tree
Hide file tree
Showing 68 changed files with 383 additions and 331 deletions.
2 changes: 1 addition & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ coverage:
project:
default:
target: 100%
threshold: null
threshold:
26 changes: 13 additions & 13 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ jobs:
strategy:
matrix:
python-version:
- '3.10'
- '3.10'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .[dev]
- name: Build documentation
run: |
sphinx-build -a -b html -W --keep-going docs/ docs/_build
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .[dev]
- name: Build documentation
run: |
sphinx-build -a -b html -W --keep-going docs/ docs/_build
64 changes: 32 additions & 32 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,46 @@ name: Tests
on:
push:
schedule:
- cron: 0 0 * * 0
- cron: 0 0 * * 0

jobs:
tests:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- ubuntu-latest
python-version:
- '3.5'
- '3.6'
- '3.7'
- '3.8'
- '3.9'
- '3.10'
- '3.11-dev'
- 'pypy-3.9'
- '3.5'
- '3.6'
- '3.7'
- '3.8'
- '3.9'
- '3.10'
- 3.11-dev
- pypy-3.9
include:
- os: windows-latest
python-version: '3.10'
- os: macos-latest
python-version: '3.10'
- os: windows-latest
python-version: '3.10'
- os: macos-latest
python-version: '3.10'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: Run tox
run: |
tox -e py
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
flags: ${{ matrix.os }}_${{ matrix.python-version }}
verbose: true
fail_ci_if_error: true
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: Run tox
run: |
tox -e py
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
flags: ${{ matrix.os }}_${{ matrix.python-version }}
verbose: true
fail_ci_if_error: true
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ repos:
rev: 4.0.1
hooks:
- id: flake8
args: [--exclude, tests/exceptions/source]
additional_dependencies:
- flake8-bugbear
- pep8-naming
26 changes: 13 additions & 13 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
version: 2

build:
os: ubuntu-20.04
tools:
python: "3.10"
os: ubuntu-20.04
tools:
python: '3.10'

python:
install:
- method: pip
path: .
extra_requirements:
- dev
install:
- method: pip
path: .
extra_requirements:
- dev

sphinx:
builder: html
configuration: docs/conf.py
builder: html
configuration: docs/conf.py

formats:
- htmlzip
- pdf
- epub
- htmlzip
- pdf
- epub
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017
Copyright (c) 2017

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion docs/_static/img/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/_static/img/sadhu.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/resources/recipes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ Files relate to Loguru as follows:

* It is the entry point when your project is used as a script (``python mypackage/main.py``).
* It can contain logging configuration inside an ``if __name__ == "__main__":`` block.

* File ``mymodule.py``:

* It is an internal module used by your project.
Expand Down
2 changes: 1 addition & 1 deletion loguru/_colorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def prepare_format(string):
return ColoredFormat(tokens, messages_color_tokens)

@staticmethod
def prepare_message(string, args=(), kwargs={}):
def prepare_message(string, args=(), kwargs={}): # noqa: B006
tokens = Colorizer._parse_with_formatting(string, args, kwargs)
return ColoredMessage(tokens)

Expand Down
2 changes: 1 addition & 1 deletion loguru/_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
pattern = re.compile(r"(?:{0})|\[(?:{0}|!UTC)\]".format(tokens))


class datetime(datetime_):
class datetime(datetime_): # noqa: N801
def __format__(self, spec):
if spec.endswith("!UTC"):
dt = self.astimezone(timezone.utc)
Expand Down
66 changes: 34 additions & 32 deletions loguru/_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,7 @@
from ._get_frame import get_frame
from ._handler import Handler
from ._locks_machinery import create_logger_lock
from ._recattrs import (
RecordException,
RecordFile,
RecordLevel,
RecordProcess,
RecordThread,
)
from ._recattrs import RecordException, RecordFile, RecordLevel, RecordProcess, RecordThread
from ._simple_sinks import AsyncSink, CallableSink, StandardSink, StreamSink

if sys.version_info >= (3, 6):
Expand Down Expand Up @@ -802,7 +796,9 @@ def add(
encoding = getattr(sink, "encoding", None)
terminator = ""
exception_prefix = "\n"
elif iscoroutinefunction(sink) or iscoroutinefunction(getattr(sink, "__call__", None)):
elif iscoroutinefunction(sink) or iscoroutinefunction(
getattr(sink, "__call__", None) # noqa: B004
):
name = getattr(sink, "__name__", None) or repr(sink)

if colorize is None:
Expand Down Expand Up @@ -1084,10 +1080,12 @@ def complete(self):
for handler in handlers.values():
handler.complete_queue()

logger = self

class AwaitableCompleter:
def __await__(self_):
with self._core.lock:
handlers = self._core.handlers.copy()
def __await__(self):
with logger._core.lock:
handlers = logger._core.handlers.copy()
for handler in handlers.values():
yield from handler.complete_async().__await__()

Expand Down Expand Up @@ -1183,14 +1181,16 @@ def catch(
):
return self.catch()(exception)

logger = self

class Catcher:
def __init__(self_, from_decorator):
self_._from_decorator = from_decorator
def __init__(self, from_decorator):
self._from_decorator = from_decorator

def __enter__(self_):
def __enter__(self):
return None

def __exit__(self_, type_, value, traceback_):
def __exit__(self, type_, value, traceback_):
if type_ is None:
return

Expand All @@ -1200,22 +1200,24 @@ def __exit__(self_, type_, value, traceback_):
if exclude is not None and issubclass(type_, exclude):
return False

from_decorator = self_._from_decorator
_, depth, _, *options = self._options
from_decorator = self._from_decorator
_, depth, _, *options = logger._options

if from_decorator:
depth += 1

catch_options = [(type_, value, traceback_), depth, True] + options
level_id, static_level_no = self._dynamic_level(level)
self._log(level_id, static_level_no, from_decorator, catch_options, message, (), {})
level_id, static_level_no = logger._dynamic_level(level)
logger._log(
level_id, static_level_no, from_decorator, catch_options, message, (), {}
)

if onerror is not None:
onerror(value)

return not reraise

def __call__(_, function):
def __call__(self, function):
if isclass(function):
raise TypeError(
"Invalid object decorated with 'catch()', it must be a function, "
Expand Down Expand Up @@ -1349,7 +1351,7 @@ def opt(
args = self._options[-2:]
return Logger(self._core, exception, depth, record, lazy, colors, raw, capture, *args)

def bind(__self, **kwargs):
def bind(__self, **kwargs): # noqa: N805
"""Bind attributes to the ``extra`` dict of each logged message record.
This is used to add custom context to each logging call.
Expand Down Expand Up @@ -1386,7 +1388,7 @@ def bind(__self, **kwargs):
return Logger(__self._core, *options, {**extra, **kwargs})

@contextlib.contextmanager
def contextualize(__self, **kwargs):
def contextualize(__self, **kwargs): # noqa: N805
"""Bind attributes to the context-local ``extra`` dict while inside the ``with`` block.
Contrary to |bind| there is no ``logger`` returned, the ``extra`` dict is modified in-place
Expand Down Expand Up @@ -1757,7 +1759,7 @@ def modules_depth(x):
self._core.enabled = enabled

@staticmethod
def parse(file, pattern, *, cast={}, chunk=2**16):
def parse(file, pattern, *, cast={}, chunk=2**16): # noqa: B006
"""Parse raw logs and extract each entry as a |dict|.
The logging format has to be specified as the regex ``pattern``, it will then be
Expand Down Expand Up @@ -1986,40 +1988,40 @@ def _log(self, level_id, static_level_no, from_decorator, options, message, args
for handler in core.handlers.values():
handler.emit(log_record, level_id, from_decorator, raw, colored_message)

def trace(__self, __message, *args, **kwargs):
def trace(__self, __message, *args, **kwargs): # noqa: N805
r"""Log ``message.format(*args, **kwargs)`` with severity ``'TRACE'``."""
__self._log("TRACE", None, False, __self._options, __message, args, kwargs)

def debug(__self, __message, *args, **kwargs):
def debug(__self, __message, *args, **kwargs): # noqa: N805
r"""Log ``message.format(*args, **kwargs)`` with severity ``'DEBUG'``."""
__self._log("DEBUG", None, False, __self._options, __message, args, kwargs)

def info(__self, __message, *args, **kwargs):
def info(__self, __message, *args, **kwargs): # noqa: N805
r"""Log ``message.format(*args, **kwargs)`` with severity ``'INFO'``."""
__self._log("INFO", None, False, __self._options, __message, args, kwargs)

def success(__self, __message, *args, **kwargs):
def success(__self, __message, *args, **kwargs): # noqa: N805
r"""Log ``message.format(*args, **kwargs)`` with severity ``'SUCCESS'``."""
__self._log("SUCCESS", None, False, __self._options, __message, args, kwargs)

def warning(__self, __message, *args, **kwargs):
def warning(__self, __message, *args, **kwargs): # noqa: N805
r"""Log ``message.format(*args, **kwargs)`` with severity ``'WARNING'``."""
__self._log("WARNING", None, False, __self._options, __message, args, kwargs)

def error(__self, __message, *args, **kwargs):
def error(__self, __message, *args, **kwargs): # noqa: N805
r"""Log ``message.format(*args, **kwargs)`` with severity ``'ERROR'``."""
__self._log("ERROR", None, False, __self._options, __message, args, kwargs)

def critical(__self, __message, *args, **kwargs):
def critical(__self, __message, *args, **kwargs): # noqa: N805
r"""Log ``message.format(*args, **kwargs)`` with severity ``'CRITICAL'``."""
__self._log("CRITICAL", None, False, __self._options, __message, args, kwargs)

def exception(__self, __message, *args, **kwargs):
def exception(__self, __message, *args, **kwargs): # noqa: N805
r"""Convenience method for logging an ``'ERROR'`` with exception information."""
options = (True,) + __self._options[1:]
__self._log("ERROR", None, False, options, __message, args, kwargs)

def log(__self, __level, __message, *args, **kwargs):
def log(__self, __level, __message, *args, **kwargs): # noqa: N805
r"""Log ``message.format(*args, **kwargs)`` with severity ``level``."""
level_id, static_level_no = __self._dynamic_level(__level)
__self._log(level_id, static_level_no, False, __self._options, __message, args, kwargs)
Expand Down
2 changes: 1 addition & 1 deletion loguru/_string_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def parse_size(size):
u = "kmgtpezy".index(u.lower()) + 1 if u else 0
i = 1024 if i else 1000
b = {"b": 8, "B": 1}[b] if b else 1
size = s * i ** u / b
size = s * i**u / b

return size

Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
from collections import namedtuple

import freezegun
import loguru
import pytest

import loguru

if sys.version_info < (3, 5, 3):

def run(coro):
Expand Down
Loading

0 comments on commit 7ef57c3

Please sign in to comment.