Brotli 1.1.0 breaks Python 2 compatibility #477

Open
opened 2026-01-29 20:44:36 +00:00 by claunia · 4 comments
Owner

Originally created by @nonatomiclabs on GitHub (Sep 8, 2023).

The latest release of Brotli breaks compatibility with Python 2, due to using f-strings in the setup.py:

> python --version
Python 2.7.18
> pip install brotli

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting brotli
  Downloading Brotli-1.1.0.tar.gz (7.4 MB)
     |████████████████████████████████| 7.4 MB 3.9 MB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Command errored out with exit status 1:
   command: /Users/jean/Desktop/venv2/bin/python /Users/jean/Desktop/venv2/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /var/folders/3q/mfpgkgl960xcdx3y00zd46hm0000gp/T/tmpYNqwFZ
       cwd: /private/var/folders/3q/mfpgkgl960xcdx3y00zd46hm0000gp/T/pip-install-N9sWxP/brotli
  Complete output (17 lines):
  Traceback (most recent call last):
    File "/Users/jean/Desktop/venv2/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py", line 280, in <module>
      main()
    File "/Users/jean/Desktop/venv2/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py", line 263, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "/Users/jean/Desktop/venv2/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py", line 114, in get_requires_for_build_wheel
      return hook(config_settings)
    File "/private/var/folders/3q/mfpgkgl960xcdx3y00zd46hm0000gp/T/pip-build-env-1DHL2I/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 146, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=['wheel'])
    File "/private/var/folders/3q/mfpgkgl960xcdx3y00zd46hm0000gp/T/pip-build-env-1DHL2I/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 127, in _get_build_requires
      self.run_setup()
    File "/private/var/folders/3q/mfpgkgl960xcdx3y00zd46hm0000gp/T/pip-build-env-1DHL2I/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 142, in run_setup
      exec(compile(code, __file__, 'exec'), locals())
    File "setup.py", line 30
      m = re.match(rf'#define\s{macro}\s+(.+)', line)
                                             ^
  SyntaxError: invalid syntax
  ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/jean/Desktop/venv2/bin/python /Users/jean/Desktop/venv2/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /var/folders/3q/mfpgkgl960xcdx3y00zd46hm0000gp/T/tmpYNqwFZ Check the logs for full command output.

I'm not sure of the correct way to solve the issue:

  • If the decision is to keep the compatibility, I can confirm that removing the two f-strings fixes the issue and that the package can then be installed with Python 2.
  • Otherwise, it would be nice if the Python 2 classifiers were removed and if the python_requires field was used to specify that the package needs at least Python 3.6+.
Originally created by @nonatomiclabs on GitHub (Sep 8, 2023). The latest release of Brotli breaks compatibility with Python 2, due to using `f`-strings in the `setup.py`: ```bash > python --version Python 2.7.18 > pip install brotli DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality. Collecting brotli Downloading Brotli-1.1.0.tar.gz (7.4 MB) |████████████████████████████████| 7.4 MB 3.9 MB/s Installing build dependencies ... done Getting requirements to build wheel ... error ERROR: Command errored out with exit status 1: command: /Users/jean/Desktop/venv2/bin/python /Users/jean/Desktop/venv2/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /var/folders/3q/mfpgkgl960xcdx3y00zd46hm0000gp/T/tmpYNqwFZ cwd: /private/var/folders/3q/mfpgkgl960xcdx3y00zd46hm0000gp/T/pip-install-N9sWxP/brotli Complete output (17 lines): Traceback (most recent call last): File "/Users/jean/Desktop/venv2/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py", line 280, in <module> main() File "/Users/jean/Desktop/venv2/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py", line 263, in main json_out['return_val'] = hook(**hook_input['kwargs']) File "/Users/jean/Desktop/venv2/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py", line 114, in get_requires_for_build_wheel return hook(config_settings) File "/private/var/folders/3q/mfpgkgl960xcdx3y00zd46hm0000gp/T/pip-build-env-1DHL2I/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 146, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=['wheel']) File "/private/var/folders/3q/mfpgkgl960xcdx3y00zd46hm0000gp/T/pip-build-env-1DHL2I/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 127, in _get_build_requires self.run_setup() File "/private/var/folders/3q/mfpgkgl960xcdx3y00zd46hm0000gp/T/pip-build-env-1DHL2I/overlay/lib/python2.7/site-packages/setuptools/build_meta.py", line 142, in run_setup exec(compile(code, __file__, 'exec'), locals()) File "setup.py", line 30 m = re.match(rf'#define\s{macro}\s+(.+)', line) ^ SyntaxError: invalid syntax ---------------------------------------- ERROR: Command errored out with exit status 1: /Users/jean/Desktop/venv2/bin/python /Users/jean/Desktop/venv2/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /var/folders/3q/mfpgkgl960xcdx3y00zd46hm0000gp/T/tmpYNqwFZ Check the logs for full command output. ``` I'm not sure of the correct way to solve the issue: - If the decision is to keep the compatibility, I can confirm that removing the two `f`-strings fixes the issue and that the package can then be installed with Python 2. - Otherwise, it would be nice if the Python 2 classifiers were removed and if the `python_requires` field was used to specify that the package needs at least Python 3.6+.
Author
Owner

@Vangelis66 commented on GitHub (Sep 17, 2023):

... The same underlying root cause (no support for f-strings) also breaks compatibility with py3.4:

python -m pip install -U brotli =>

Collecting brotli
  Downloading https://files.pythonhosted.org/packages/2f/c2/f9e977608bdf958650638c3f1e28f85a1b075f075ebbe77db8555463787b/Brotli-1.1.0.tar.gz (7.4MB)
     |████████████████████████████████| 7.4MB 386kB/s
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  ERROR: Complete output from command 'C:\Python3410-32\python.exe' 'C:\Python3410-32\lib\site-packages\pip\_vendor\pep517\_in_process.py' get_requires_for_build_wheel 'C:\Users\<redacted>\AppData\Local\Temp\tmpgh2zno9_':
  ERROR: Traceback (most recent call last):
    File "C:\Python3410-32\lib\site-packages\pip\_vendor\pep517\_in_process.py", line 207, in <module>
      main()
    File "C:\Python3410-32\lib\site-packages\pip\_vendor\pep517\_in_process.py", line 197, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])
    File "C:\Python3410-32\lib\site-packages\pip\_vendor\pep517\_in_process.py", line 54, in get_requires_for_build_wheel
      return hook(config_settings)
    File "C:\Users\<redacted>\AppData\Local\Temp\pip-build-env-hltq7py2\overlay\Lib\site-packages\setuptools\build_meta.py", line 146, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=['wheel'])
    File "C:\Users\<redacted>\AppData\Local\Temp\pip-build-env-hltq7py2\overlay\Lib\site-packages\setuptools\build_meta.py", line 127, in _get_build_requires
      self.run_setup()
    File "C:\Users\<redacted>\AppData\Local\Temp\pip-build-env-hltq7py2\overlay\Lib\site-packages\setuptools\build_meta.py", line 142, in run_setup
      exec(compile(code, __file__, 'exec'), locals())
    File "setup.py", line 30
      m = re.match(rf'#define\s{macro}\s+(.+)', line)
                                             ^
  SyntaxError: invalid syntax
  ----------------------------------------
ERROR: Command "'C:\Python3410-32\python.exe' 'C:\Python3410-32\lib\site-packages\pip\_vendor\pep517\_in_process.py' get_requires_for_build_wheel 'C:\Users\<redacted>\AppData\Local\Temp\tmpgh2zno9_'" failed with error code 1 in C:\Users\<redacted>\AppData\Local\Temp\pip-install-e18xc5rq\brotli

PyPI, on the Brotli-1.1.0 page, advertises:

brotlipypi

I can confirm that removing the two f-strings fixes the issue and that the package can then be installed with Python 2.

For those not fluent in Python 😉 , what was the exact code you used in lieu of L30+L44 of current setup.py ? FWIW, f-strings inside setup.py were first introduced in 27a9a80992 ...

Thanks 😄

@Vangelis66 commented on GitHub (Sep 17, 2023): ... The same underlying root cause (no support for `f-strings`) also **breaks compatibility** with **py3.4**: ```console python -m pip install -U brotli => Collecting brotli Downloading https://files.pythonhosted.org/packages/2f/c2/f9e977608bdf958650638c3f1e28f85a1b075f075ebbe77db8555463787b/Brotli-1.1.0.tar.gz (7.4MB) |████████████████████████████████| 7.4MB 386kB/s Installing build dependencies ... done Getting requirements to build wheel ... error ERROR: Complete output from command 'C:\Python3410-32\python.exe' 'C:\Python3410-32\lib\site-packages\pip\_vendor\pep517\_in_process.py' get_requires_for_build_wheel 'C:\Users\<redacted>\AppData\Local\Temp\tmpgh2zno9_': ERROR: Traceback (most recent call last): File "C:\Python3410-32\lib\site-packages\pip\_vendor\pep517\_in_process.py", line 207, in <module> main() File "C:\Python3410-32\lib\site-packages\pip\_vendor\pep517\_in_process.py", line 197, in main json_out['return_val'] = hook(**hook_input['kwargs']) File "C:\Python3410-32\lib\site-packages\pip\_vendor\pep517\_in_process.py", line 54, in get_requires_for_build_wheel return hook(config_settings) File "C:\Users\<redacted>\AppData\Local\Temp\pip-build-env-hltq7py2\overlay\Lib\site-packages\setuptools\build_meta.py", line 146, in get_requires_for_build_wheel return self._get_build_requires(config_settings, requirements=['wheel']) File "C:\Users\<redacted>\AppData\Local\Temp\pip-build-env-hltq7py2\overlay\Lib\site-packages\setuptools\build_meta.py", line 127, in _get_build_requires self.run_setup() File "C:\Users\<redacted>\AppData\Local\Temp\pip-build-env-hltq7py2\overlay\Lib\site-packages\setuptools\build_meta.py", line 142, in run_setup exec(compile(code, __file__, 'exec'), locals()) File "setup.py", line 30 m = re.match(rf'#define\s{macro}\s+(.+)', line) ^ SyntaxError: invalid syntax ---------------------------------------- ERROR: Command "'C:\Python3410-32\python.exe' 'C:\Python3410-32\lib\site-packages\pip\_vendor\pep517\_in_process.py' get_requires_for_build_wheel 'C:\Users\<redacted>\AppData\Local\Temp\tmpgh2zno9_'" failed with error code 1 in C:\Users\<redacted>\AppData\Local\Temp\pip-install-e18xc5rq\brotli ``` PyPI, on the `Brotli-1.1.0` [page](https://pypi.org/project/Brotli/1.1.0/), advertises: ![brotlipypi](https://github.com/google/brotli/assets/9669492/b5450a8b-fa42-409e-9068-ea41d58b91ca) > I can confirm that removing the two `f-strings` fixes the issue and that the package can then be installed with Python 2. For those not fluent in Python 😉 , what was _the exact code_ you used in lieu of L30+L44 of current `setup.py` ? FWIW, `f-strings` inside `setup.py` were first introduced in 27a9a80992e2 ... Thanks 😄
Author
Owner

@rouilj commented on GitHub (Sep 18, 2023):

... The same underlying root cause (no support for f-strings) also breaks compatibility with py3.4:
[...]
File "setup.py", line 30
m = re.match(rf'#define\s{macro}\s+(.+)', line)
^
SyntaxError: invalid syntax
[...]
For those not fluent in Python 😉 , what was the exact code you used in lieu of L30+L44 of current setup.py ? FWIW, f-strings inside setup.py were first introduced in 27a9a80 ...

Can you try:

m = re.match(r'#define\s%s\s+(.+)' % macro, line)

and see if that works. If so the other rf line can be similarly munged by:

  • replace rf' with r'
  • replace {variable} in the r string with %s and add % varname as above.
    If there is more than 1 variable in the r string, use % ( var1, var2, ...) matching the varX and the %s
    tokens 1 for 1.
@rouilj commented on GitHub (Sep 18, 2023): > ... The same underlying root cause (no support for `f-strings`) also **breaks compatibility** with **py3.4**: >[...] > File "setup.py", line 30 > m = re.match(rf'#define\s{macro}\s+(.+)', line) > ^ > SyntaxError: invalid syntax >[...] > For those not fluent in Python 😉 , what was _the exact code_ you used in lieu of L30+L44 of current `setup.py` ? FWIW, `f-strings` inside `setup.py` were first introduced in [27a9a80](https://github.com/google/brotli/commit/27a9a80992e2308ef60bc6d840c8b59293c32d67) ... Can you try: ``` m = re.match(r'#define\s%s\s+(.+)' % macro, line) ``` and see if that works. If so the other rf line can be similarly munged by: * replace ```rf'``` with ```r'``` * replace ```{variable}``` in the r string with %s and add ```% varname``` as above. If there is more than 1 variable in the r string, use ```% ( var1, var2, ...)``` matching the varX and the ```%s``` tokens 1 for 1.
Author
Owner

@JacobChrist commented on GitHub (Sep 30, 2023):

This is affecting me too, how can I help? I'm trying to install in Python 2.7.18 venv on a rPi. I can successfully install version 1.0.9
pip install brotli==1.0.9

@JacobChrist commented on GitHub (Sep 30, 2023): This is affecting me too, how can I help? I'm trying to install in Python 2.7.18 venv on a rPi. I can successfully install version 1.0.9 `pip install brotli==1.0.9`
Author
Owner

@Yb2S3Man commented on GitHub (Feb 19, 2025):

I highly recommend to release a new version to fix this issue. So far as I know, many script are still in the python2 version and when they have dependency with Brotli, that was not version 1.1.0 but some older version. However, when someone others who're maintaining those scripts nowadays, the Brotli's dependency is version 1.1.0, that's not a feasible solution for users.

@Yb2S3Man commented on GitHub (Feb 19, 2025): I highly recommend to release a new version to fix this issue. So far as I know, many script are still in the python2 version and when they have dependency with Brotli, that was not version 1.1.0 but some older version. However, when someone others who're maintaining those scripts nowadays, the Brotli's dependency is version 1.1.0, that's not a feasible solution for users.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/brotli#477