Skip to content

Commit

Permalink
Merge baac374 into fe24a15
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDen committed Dec 19, 2018
2 parents fe24a15 + baac374 commit 34e1a21
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
29 changes: 28 additions & 1 deletion README.md
Expand Up @@ -35,6 +35,7 @@ Try it out now using the [Black Playground](https://black.now.sh).
**[Code style](#the-black-code-style)** |
**[pyproject.toml](#pyprojecttoml)** |
**[Editor integration](#editor-integration)** |
**[Docker image](#docker-image)** |
**[blackd](#blackd)** |
**[Version control integration](#version-control-integration)** |
**[Ignoring unmodified files](#ignoring-unmodified-files)** |
Expand Down Expand Up @@ -280,7 +281,7 @@ ignore = E501
```

You'll find *Black*'s own .flake8 config file is configured like this.
If you're curious about the reasoning behind B950,
If you're curious about the reasoning behind B950,
[Bugbear's documentation](https://github.com/PyCQA/flake8-bugbear#opinionated-warnings)
explains it. The tl;dr is "it's like highway speed limits, we won't
bother you if you overdo it by a few km/h".
Expand Down Expand Up @@ -759,6 +760,32 @@ affect your use case.

This can be used for example with PyCharm's [File Watchers](https://www.jetbrains.com/help/pycharm/file-watchers.html).

## Docker image

### Building

Running `build.sh` in the `docker/` folder will build the docker image tagged as `ambv/black:latest`

### Tagging

Running `tag.sh` in the `docker/` folder will tag the `ambv/black:latest` image based on the `__version__` in `black.py`

### Usage

`docker run ambv/black` defaults to the `--help` flag.

To run a check on a python file:

```bash
docker run --read-only -v $(pwd):$(pwd) -w $(pwd) ambv/black --check foo.py
```

Note that the mounted directory has to be where the file exists, e.g.,

```bash
docker run --read-only -v /home/ubunu/somefolder/:/black/ -w /black/ ambv/black --check foo.py
```

## blackd

`blackd` is a small HTTP server that exposes *Black*'s functionality over
Expand Down
13 changes: 13 additions & 0 deletions docker/Dockerfile
@@ -0,0 +1,13 @@
FROM alpine:3.6

RUN apk add --no-cache --update python3 \
&& apk add --no-cache --virtual .build-deps py-pip \
&& pip3 --no-cache-dir install black \
&& apk del --no-cache --purge .build-deps \
&& rm -rf /usr/lib/python2.* \
&& rm -rf /var/cache/* \
&& rm -rf /root/.cache/* \
&& find /usr/lib/python* -depth \( -name '*.pyo' -o -name '*.pyc' -o -name 'test' -o -name 'tests' \) -exec rm -rf '{}' + ;

ENTRYPOINT ["/usr/bin/black" ]
CMD ["--help"]
7 changes: 7 additions & 0 deletions docker/build.sh
@@ -0,0 +1,7 @@
#!/bin/bash

BASEDIR=$(dirname "$0")
VERSION="latest"
IMAGENAME="ambv/black"

docker build -t ${IMAGENAME}:"${VERSION}" -f "${BASEDIR}"/Dockerfile "${BASEDIR}"
11 changes: 11 additions & 0 deletions docker/tag.sh
@@ -0,0 +1,11 @@
#!/bin/bash

BASEDIR=$(dirname "$0")
VERSION="latest"
IMAGENAME="ambv/black"

if [ -n "$(docker images -q "${IMAGENAME}:${VERSION}" 2> /dev/null)" ]; then
TAG="$(grep -iR "^__version__ =" "${BASEDIR}"/../black.py | awk -F "= " '{print $2}' | sed 's/"//g')"
docker tag "${IMAGENAME}:${VERSION}" "${IMAGENAME}:${TAG}"
echo "tagged image ${IMAGENAME}:${TAG}"
fi

0 comments on commit 34e1a21

Please sign in to comment.