black: Installing black 19.10b0 without gcc installed causes an error

Installing black version 19.10b0 in an environment without gcc causes an error.

To Reproduce:

  1. Build a docker image (docker build .) using this Dockerfile:
FROM python:3.7-slim
RUN pip install black
  1. See error:
Building wheels for collected packages: pathspec, regex
  Building wheel for pathspec (setup.py): started
  Building wheel for pathspec (setup.py): finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/62/b8/e1/e2719465b5947c40cd85d613d6cb33449b86a1ca5a6c574269
  Building wheel for regex (setup.py): started
  Building wheel for regex (setup.py): finished with status 'error'
  ERROR: Complete output from command /usr/local/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-t05gdu90/regex/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-2uuo3rjn --python-tag cp37:
  ERROR: BASE_DIR is /tmp/pip-install-t05gdu90/regex
  /usr/local/lib/python3.7/site-packages/setuptools/dist.py:472: UserWarning: Normalizing '2019.08.19' to '2019.8.19'
    normalized_version,
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.7
  creating build/lib.linux-x86_64-3.7/regex
  copying regex_3/regex/__init__.py -> build/lib.linux-x86_64-3.7/regex
  copying regex_3/regex/regex.py -> build/lib.linux-x86_64-3.7/regex
  copying regex_3/regex/_regex_core.py -> build/lib.linux-x86_64-3.7/regex
  creating build/lib.linux-x86_64-3.7/regex/test
  copying regex_3/regex/test/__init__.py -> build/lib.linux-x86_64-3.7/regex/test
  copying regex_3/regex/test/test_regex.py -> build/lib.linux-x86_64-3.7/regex/test
  running build_ext
  building 'regex._regex' extension
  creating build/temp.linux-x86_64-3.7
  creating build/temp.linux-x86_64-3.7/regex_3
  gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/usr/local/include/python3.7m -c regex_3/_regex.c -o build/temp.linux-x86_64-3.7/regex_3/_regex.o
  unable to execute 'gcc': No such file or directory
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for regex
  Running setup.py clean for regex
Successfully built pathspec
Failed to build regex

Expected behavior:

We should be able to install black without needing to have gcc installed separately.

Environment (please complete the following information):

  • Version: 19.10b0
  • OS and Python version: Docker image (python:3.7-slim) running on MacOS/Linux hosts

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 25
  • Comments: 23 (8 by maintainers)

Commits related to this issue

Most upvoted comments

There should be an alternative to a hard dependency of regex for a year old low priority bug that causes widespread disruption to users. Also relying on third-party library in pull requests and packaging availability must be questioned.

The author of regex is not going to provide wheels:

https://bitbucket.org/mrabarnett/mrab-regex/issues/343/wheel-for-linux

@Seth Morton: I, personally, am not interested in building wheels for anything other than Windows (and I’m not sure how long I’ll be building ones for Python 2, what with it about to reach end-of-life), but I would accept a contribution that would enable others to do build them.

Why not revert the fix and dependency to reconsider a better solution?

This makes using black pretty hard on modern CI/CD which usually uses docker. Can we please find a better tool other than regex or MR something into that library, so that it builds binary linux wheels

Instead of looking for an alternative to regex itself, I would offer to make it better by contributing a CI pipeline to it that builds wheels on all platforms.

There’s a pull request merged that will soon produce linux wheels for regex.

Everywhere in code regex can be safely replaced by re, so regex can be imported with a fallback to re and installed as an extra.

I ran into this issue in an image that uses continuumio/miniconda3:latest which in turn uses debian:latest. I addressed it by adding the following line:

RUN apt-get update && apt-get -y install gcc

I didn’t need to install all of build-essential. In any case, this resolution is now going to stress the debian repositories.

FWIW, I’ve just asked @ambv to revert the change again given the low priority nature of the bug and the impact it has on many people.

@impredicative I have a library that generates Python source code from jinja templates and then formats it with black, so it is a direct dependency.

For people looking for a compact Alpine Docker image with Black 19.10b0, installing Black with GCC can be done in a separate build stage to reduce the final image size. Example (see original Dockerfile):

FROM alpine:3.10.3 AS black
RUN apk add --no-cache \
    gcc~=8.3.0 \
    musl-dev~=1.1.22 \
    python3-dev~=3.7.5 \
  && pip3 install --target /opt/black black==19.10b0

FROM alpine:3.10.3
RUN apk add --no-cache python3~=3.7.5
COPY --from=black /opt/black /opt/black
ENV PATH="${PATH}:/opt/black/bin" \
  PYTHONPATH="${PYTHONPATH}:/opt/black"

This one results in an image of about 64.8MB in size. I hope this helps.

If an example of the problematic Unicode pattern and input string is known, perhaps it could be shared here so someone could report it to https://bugs.python.org/ in the hopes that is could be improved in the re module.

The regex author doesn’t seem to be willing to add pre-built linux wheels. We also find that requiring a source build is inconvenient, both in terms of added complexity and build times.