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

Brotli support does not work if brotlipy is installed #308

Open
mgorny opened this issue Apr 25, 2020 · 2 comments
Open

Brotli support does not work if brotlipy is installed #308

mgorny opened this issue Apr 25, 2020 · 2 comments

Comments

@mgorny
Copy link

mgorny commented Apr 25, 2020

Apparently both brotli and brotlipy use the same name, except the former installs brotli.py module and the latter brotli/ package. Therefore, the latter takes precedence if installed, and breaks logbook:

__________________________________________ test_compression_file_handler[ContextEnteringStrategy-False] ___________________________________________

logfile = '/tmp/pytest-of-mgorny/pytest-5/test_compression_file_handler_1/logfile.log'
activation_strategy = <class 'tests.conftest.ContextEnteringStrategy'>, logger = <logbook.base.Logger object at 0x7f13c9433198>, use_gzip = False

    @pytest.mark.parametrize("use_gzip", [True, False])
    def test_compression_file_handler(logfile, activation_strategy, logger, use_gzip):
        handler = logbook.GZIPCompressionHandler(logfile) if use_gzip else logbook.BrotliCompressionHandler(logfile)
        handler.format_string = '{record.level_name}:{record.channel}:{record.message}'
        with activation_strategy(handler):
            logger.warn('warning message')
        handler.close()
>       assert  _decompress(logfile, use_gzip) == 'WARNING:testlogger:warning message\n'
E       AssertionError: assert '' == 'WARNING:test...ing message\n'
E         - WARNING:testlogger:warning message

tests/test_file_handler.py:242: AssertionError
-------------------------------------------------------------- Captured stderr call ---------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/logbook/logbook/handlers.py", line 216, in handle
    self.emit(record)
  File "/tmp/logbook/logbook/handlers.py", line 586, in emit
    self.write(self.encode(msg))
  File "/tmp/logbook/logbook/handlers.py", line 699, in write
    ret = self._compressor.process(item)
AttributeError: 'Compressor' object has no attribute 'process'
Logged from file /tmp/logbook/tests/test_file_handler.py, line 240
______________________________________________ test_compression_file_handler[PushingStrategy-False] _______________________________________________

logfile = '/tmp/pytest-of-mgorny/pytest-5/test_compression_file_handler_3/logfile.log'
activation_strategy = <class 'tests.conftest.PushingStrategy'>, logger = <logbook.base.Logger object at 0x7f13c940b5f8>, use_gzip = False

    @pytest.mark.parametrize("use_gzip", [True, False])
    def test_compression_file_handler(logfile, activation_strategy, logger, use_gzip):
        handler = logbook.GZIPCompressionHandler(logfile) if use_gzip else logbook.BrotliCompressionHandler(logfile)
        handler.format_string = '{record.level_name}:{record.channel}:{record.message}'
        with activation_strategy(handler):
            logger.warn('warning message')
        handler.close()
>       assert  _decompress(logfile, use_gzip) == 'WARNING:testlogger:warning message\n'
E       AssertionError: assert '' == 'WARNING:test...ing message\n'
E         - WARNING:testlogger:warning message

tests/test_file_handler.py:242: AssertionError
-------------------------------------------------------------- Captured stderr call ---------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/logbook/logbook/handlers.py", line 216, in handle
    self.emit(record)
  File "/tmp/logbook/logbook/handlers.py", line 586, in emit
    self.write(self.encode(msg))
  File "/tmp/logbook/logbook/handlers.py", line 699, in write
    ret = self._compressor.process(item)
AttributeError: 'Compressor' object has no attribute 'process'
Logged from file /tmp/logbook/tests/test_file_handler.py, line 240

This is a major problem since brotlipy is required by hyper-h2.

@mgorny
Copy link
Author

mgorny commented Apr 25, 2020

Easy repro:

diff --git a/tox.ini b/tox.ini
index 7c21509..26d79e2 100644
--- a/tox.ini
+++ b/tox.ini
@@ -8,6 +8,7 @@ whitelist_externals =
 deps =
     py{27}: mock
     pytest
+    brotlipy
     speedups: Cython
 setenv =
     !speedups: DISABLE_LOGBOOK_CEXT=1

@RazerM
Copy link
Collaborator

RazerM commented Aug 3, 2021

brotlipy was renamed to brotlicffi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants