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

Installing black 19.10b0 without gcc installed causes an error #1112

Closed
jonadaly opened this issue Oct 29, 2019 · 23 comments · Fixed by #1232
Closed

Installing black 19.10b0 without gcc installed causes an error #1112

jonadaly opened this issue Oct 29, 2019 · 23 comments · Fixed by #1232
Labels
C: packaging Installation and packaging of Black

Comments

@jonadaly
Copy link

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
@jonadaly jonadaly added the T: bug Something isn't working label Oct 29, 2019
@miguelsimon
Copy link

It seems black's regex dependency fails to build without gcc, here's reproducing in ubuntu in virtualenvs (this is where it broke in our systems):

FROM ubuntu:18.04
RUN apt-get update && apt-get install -y python3-venv
RUN python3 -m venv env && env/bin/pip install black

output:

Failed to build pathspec regex
Installing collected packages: attrs, appdirs, typed-ast, toml, pathspec, click, regex, black
  Running setup.py install for pathspec: started
    Running setup.py install for pathspec: finished with status 'done'
  Running setup.py install for regex: started
    Running setup.py install for regex: finished with status 'error'
    Complete output from command /env/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-o_hpuz1z/regex/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-tzk8s1zz-record/install-record.txt --single-version-externally-managed --compile --install-headers /env/include/site/python3.6/regex:
    BASE_DIR is /tmp/pip-build-o_hpuz1z/regex
    /env/lib/python3.6/site-packages/setuptools/dist.py:397: UserWarning: Normalizing '2019.08.19' to '2019.8.19'
      normalized_version,
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/regex
    copying regex_3/regex/__init__.py -> build/lib.linux-x86_64-3.6/regex
    copying regex_3/regex/regex.py -> build/lib.linux-x86_64-3.6/regex
    copying regex_3/regex/_regex_core.py -> build/lib.linux-x86_64-3.6/regex
    creating build/lib.linux-x86_64-3.6/regex/test
    copying regex_3/regex/test/__init__.py -> build/lib.linux-x86_64-3.6/regex/test
    copying regex_3/regex/test/test_regex.py -> build/lib.linux-x86_64-3.6/regex/test
    running build_ext
    building 'regex._regex' extension
    creating build/temp.linux-x86_64-3.6
    creating build/temp.linux-x86_64-3.6/regex_3
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/env/include -I/usr/include/python3.6m -c regex_3/_regex.c -o build/temp.linux-x86_64-3.6/regex_3/_regex.o
    unable to execute 'x86_64-linux-gnu-gcc': No such file or directory
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    
    ----------------------------------------
Command "/env/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-o_hpuz1z/regex/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-tzk8s1zz-record/install-record.txt --single-version-externally-managed --compile --install-headers /env/include/site/python3.6/regex" failed with error code 1 in /tmp/pip-build-o_hpuz1z/regex/
The command '/bin/sh -c python3 -m venv env && env/bin/pip install black' returned a non-zero code: 1

Including python3-dev headers and build-essential makes the build succeed:

FROM ubuntu:18.04
RUN apt-get update && apt-get install -y python3-venv build-essential python3-dev
RUN python3 -m venv env && env/bin/pip install black

output:

    Running setup.py install for regex: finished with status 'done'
Successfully installed appdirs-1.4.3 attrs-19.3.0 black-19.10b0 click-7.0 pathspec-0.6.0 regex-2019.8.19 toml-0.10.0 typed-ast-1.4.0

@mwysokin
Copy link

I wouldn't say it's a bug, but it's definitely an inconvenience which might have an actual impact on the global docker related traffic.

@zwing99
Copy link

zwing99 commented Oct 31, 2019

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

@kvikshaug
Copy link

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.

@zsol
Copy link
Collaborator

zsol commented Nov 1, 2019

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.

@jezdez
Copy link
Member

jezdez commented Nov 1, 2019

Since I've been involved with some wheel building platforms I just wanted to chime in and say that it's a non-zero amount of effort to maintain such systems and it's totally okay for the author of regex to decline doing that.

And IMO it's not super fair to reply to the legitimate concern about this new requirement of the C compiler that we should simply help build this non-trivial system either.

I haven't seen efforts to look for alternatives (in the public issues/PRs at least) that would be vastly less time-intensive. @zsol Do you know of any work in that direction?

@zsol
Copy link
Collaborator

zsol commented Nov 1, 2019

I don't think anyone has spent time looking at regex alternatives while keeping binary wheel availability in mind. I certainly haven't.

I'd like to clarify - I don't think it's unacceptable to replace Black's dependency on regex with something that has all of: correct unicode handling, similar performance characteristics, binary wheels published. If someone wants to do that, I'm all ears and happy to review PRs. I personally think it's worth investing in regex this way because otherwise it's a high quality library.

@impredicative
Copy link

impredicative commented Nov 1, 2019

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.

@cs01
Copy link

cs01 commented Nov 4, 2019

This was recently solved for pipx's CI in pypa/pipx#269. pipx uses travis, and the fix was to add the path /usr/bin to the PATH environment variable. Just wanted to mention that here in case it helps anyone.

@impredicative
Copy link

impredicative commented Nov 4, 2019

pipx uses travis, and the fix was to add the path /usr/bin to the PATH environment variable.

Builds are often containerized, and I doubt that many containers have /usr/bin/gcc by default.


I don't know what regex offers anyway that black can't do with re.

@JelleZijlstra
Copy link
Collaborator

@impredicative regex has better Unicode support. Using regex fixed a bug where Black couldn't deal with certain Unicode identifiers.

@jdufresne
Copy link
Contributor

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.

@hugovk
Copy link
Contributor

hugovk commented Nov 5, 2019

#1047 is the PR which added regex, and has tests for the tricky Unicode bits.

#455 is the issue it fixed, with several examples.

ynezz added a commit to ynezz/openwrt-ci that referenced this issue Nov 11, 2019
Black seems to have dependencies on musl-dev and gcc past 19.3b0
version.  Hopefully this is just temporary. If we wanted to continue
using the latest versions, we could instead add something like `apk add
musl-dev gcc` but this increases the duration of the process
significantly.

Fixes following CI check failure[1]:

 $ make ci-py-checks -f Makefile.ci
  python3 -m venv /builds/openwrtorg/gitlab-evaluation/.venv/openwrt-ci
  ...
  /.venv/openwrt-ci/bin/pip3 install black flake8
  ...
  Installing collected packages: regex, click, attrs, appdirs, toml, typed-ast, pathspec, black, pycodestyle, mccabe, entrypoints, pyflakes, flake8
    Running setup.py install for regex: started
    Running setup.py install for regex: finished with status 'error'
    ...
    gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -Os -fomit-frame-pointer -g -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/builds/openwrtorg/gitlab-evaluation/.venv/openwrt-ci/include -I/usr/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

1. https://gitlab.com/ynezz/openwrt-gitlab-evaluation/-/jobs/326228113

Ref: psf/black#1112
Signed-off-by: Petr Štetiar <ynezz@true.cz>
mmlb added a commit to packethost/packet-python that referenced this issue Nov 13, 2019
Recent versions of black require gcc to build a new regex dependency.
This may go away, so we'll just pin to a specific version black (which
is best practice anyway).

Related to psf/black#1112.
eventh added a commit to cognitedata/cognite-replicator that referenced this issue Nov 14, 2019
I added tests for the functions in __main___.
Also added pytest-mock as depedencies.
I had to pin black to version 19.3b0 because the
newer version comes with regex depedency that require a C
compiler. Known issue with black:
psf/black#1112

Signed-off-by: Even Wiik Thomassen <even.thomassen@cognite.com>
eventh added a commit to cognitedata/cognite-replicator that referenced this issue Nov 16, 2019
…ILE (#103)

* Configure config file path with environment variable COGNITE_CONFIG_FILE

Signed-off-by: Even Wiik Thomassen <even.thomassen@cognite.com>

* Added tests and locked black on version 19.3b0.

I added tests for the functions in __main___.
Also added pytest-mock as depedencies.
I had to pin black to version 19.3b0 because the
newer version comes with regex depedency that require a C
compiler. Known issue with black:
psf/black#1112

Signed-off-by: Even Wiik Thomassen <even.thomassen@cognite.com>
@vemel
Copy link
Contributor

vemel commented Nov 21, 2019

I added a PR #1172 that makes typed_ast optional and adds PyPy support.

It would be great if you could help me to test my changes. assert_equivalent is potentially broken for Python <3.8 with no typed_ast installed. I could not find an input that triggers it, so please help me.

@evolutics
Copy link

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.

@impredicative
Copy link

For people looking for a compact Alpine Docker image with Black 19.10b0

Why is there a reason for black to be in a final release image at all? I use black, among other analyzers, in an intermediate throwaway test image, not in the release image. Dockerfile

@vemel
Copy link
Contributor

vemel commented Dec 8, 2019

@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.

@cas--
Copy link
Contributor

cas-- commented Dec 13, 2019

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?

@zwing99
Copy link

zwing99 commented Dec 13, 2019

I love the suggestion of give up on weird edge cases of Unicode, it is not even 1% of the folks using black if I had to guess that face this odd edge case. That being said, I think that you could also take the library of regex internally into black (Much like urllib3 is embedded in requests) and build black as wheels for all deploy targets.

But whatever the decision something needs to happen or folks will start to abandon ship.

cas-- added a commit to cas--/Deluge that referenced this issue Dec 13, 2019
Black version 19.10b0 has a new `regex` dependency which requires
building from source on Linux. Until this is fixed pin to earlier
version.

See: psf/black#1112
@vemel
Copy link
Contributor

vemel commented Dec 13, 2019

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.

@jezdez
Copy link
Member

jezdez commented Dec 13, 2019

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.

@zsol
Copy link
Collaborator

zsol commented Dec 16, 2019

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

@zsol zsol added C: packaging Installation and packaging of Black and removed T: bug Something isn't working labels Dec 16, 2019
@ghost
Copy link

ghost commented Jan 15, 2020

@zsol , I couldn't find the pull request, but looks like there are wheels for mrab-regex 🎉

JelleZijlstra pushed a commit that referenced this issue Jan 18, 2020
joao-p-marques added a commit to Tecnativa/doodba-qa that referenced this issue Oct 7, 2020
According to psf/black#1112, black > 19.10b0
needs gcc installed.
Installing build-essential and python3-dev solves the issue.

TT26059
yajo added a commit to Tecnativa/doodba-qa that referenced this issue Oct 7, 2020
According to psf/black#1112, black > 19.10b0
needs gcc installed.
Installing build-essential and python3-dev solves the issue.

TT26059

Co-authored-by: Jairo Llopis <Yajo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: packaging Installation and packaging of Black
Projects
None yet
Development

Successfully merging a pull request may close this issue.