Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
enzet committed Jun 1, 2021
2 parents 26f79d6 + 4005246 commit be4fe0c
Show file tree
Hide file tree
Showing 9 changed files with 323 additions and 59 deletions.
19 changes: 17 additions & 2 deletions CHANGES.md
Expand Up @@ -5,21 +5,36 @@
### _Black_

- Fix an issue with indentation and `fmt: skip` (#2281)
- Correct max string length calculation when there are string operators (#2292)

## 21.5b2

### _Black_

- A space is no longer inserted into empty docstrings (#2249)
- Fix handling of .gitignore files containing non-ASCII characters on Windows (#2229)
- Respect `.gitignore` files in all levels, not only `root/.gitignore` file (apply
`.gitignore` rules like `git` does) (#2225)
- Restored compatibility with Click 8.0 on Python 3.6 when LANG=C used (#2227)
- Add extra uvloop install + import support if in python env (#2258)
- Fix --experimental-string-processing crash when matching parens are not found (#2283)
- Make sure to split lines that start with a string operator (#2286)
- Fix regular expression that black uses to identify f-expressions (#2287)

### _Blackd_

- Add a lower bound for the `aiohttp-cors` dependency. Only 0.4.0 or higher is
supported. (#2231)

### _Packaging_
### Integrations

- The official Black action now supports choosing what version to use, and supports the
major 3 OSes. (#1940)

### Packaging

- Release self-contained macOS binaries as part of the GitHub release pipeline (#2198)
- Release self-contained x86_64 MacOS binaries as part of the GitHub release pipeline
(#2198)
- Always build binaries with the latest available Python (#2260)

### Documentation
Expand Down
43 changes: 39 additions & 4 deletions action.yml
Expand Up @@ -4,21 +4,56 @@ author: "Łukasz Langa and contributors to Black"
inputs:
options:
description:
"Options passed to black. Use `black --help` to see available options. Default:
"Options passed to Black. Use `black --help` to see available options. Default:
'--check'"
required: false
default: "--check --diff"
src:
description: "Source to run black. Default: '.'"
description: "Source to run Black. Default: '.'"
required: false
default: "."
black_args:
description: "[DEPRECATED] Black input arguments."
required: false
default: ""
deprecationMessage:
"Input `with.black_args` is deprecated. Use `with.options` and `with.src` instead."
version:
description: 'Python Version specifier (PEP440) - e.g. "21.5b1"'
required: false
default: ""
branding:
color: "black"
icon: "check-circle"
runs:
using: "docker"
image: "action/Dockerfile"
using: composite
steps:
- run: |
# Exists since using github.action_path + path to main script doesn't work because bash
# interprets the backslashes in github.action_path (which are used when the runner OS
# is Windows) destroying the path to the target file.
#
# Also semicolons are necessary because I can't get the newlines to work
entrypoint="import sys;
import subprocess;
from pathlib import Path;
MAIN_SCRIPT = Path(r'${{ github.action_path }}') / 'action' / 'main.py';
proc = subprocess.run([sys.executable, str(MAIN_SCRIPT)]);
sys.exit(proc.returncode)
"
if [ "$RUNNER_OS" == "Windows" ]; then
echo $entrypoint | python
else
echo $entrypoint | python3
fi
env:
# TODO: Remove once https://github.com/actions/runner/issues/665 is fixed.
INPUT_OPTIONS: ${{ inputs.options }}
INPUT_SRC: ${{ inputs.src }}
INPUT_BLACK_ARGS: ${{ inputs.black_args }}
INPUT_VERSION: ${{ inputs.version }}
pythonioencoding: utf-8
shell: bash
10 changes: 0 additions & 10 deletions action/Dockerfile

This file was deleted.

9 changes: 0 additions & 9 deletions action/entrypoint.sh

This file was deleted.

39 changes: 39 additions & 0 deletions action/main.py
@@ -0,0 +1,39 @@
import os
import shlex
import sys
from pathlib import Path
from subprocess import run, PIPE, STDOUT

ACTION_PATH = Path(os.environ["GITHUB_ACTION_PATH"])
ENV_PATH = ACTION_PATH / ".black-env"
ENV_BIN = ENV_PATH / ("Scripts" if sys.platform == "win32" else "bin")
OPTIONS = os.getenv("INPUT_OPTIONS", default="")
SRC = os.getenv("INPUT_SRC", default="")
BLACK_ARGS = os.getenv("INPUT_BLACK_ARGS", default="")
VERSION = os.getenv("INPUT_VERSION", default="")

run([sys.executable, "-m", "venv", str(ENV_PATH)], check=True)

req = "black[colorama,python2]"
if VERSION:
req += f"=={VERSION}"
pip_proc = run(
[str(ENV_BIN / "python"), "-m", "pip", "install", req],
stdout=PIPE,
stderr=STDOUT,
encoding="utf-8",
)
if pip_proc.returncode:
print(pip_proc.stdout)
print("::error::Failed to install Black.", flush=True)
sys.exit(pip_proc.returncode)


base_cmd = [str(ENV_BIN / "black")]
if BLACK_ARGS:
# TODO: remove after a while since this is deprecated in favour of SRC + OPTIONS.
proc = run([*base_cmd, *shlex.split(BLACK_ARGS)])
else:
proc = run([*base_cmd, *shlex.split(OPTIONS), *shlex.split(SRC)])

sys.exit(proc.returncode)
23 changes: 19 additions & 4 deletions docs/integrations/github_actions.md
Expand Up @@ -3,6 +3,14 @@
You can use _Black_ within a GitHub Actions workflow without setting your own Python
environment. Great for enforcing that your code matches the _Black_ code style.

## Compatiblity

This action is known to support all GitHub-hosted runner OSes. In addition, only
published versions of _Black_ are supported (i.e. whatever is available on PyPI).

Finally, this action installs _Black_ with both the `colorama` and `python2` extras so
the `--color` flag and formatting Python 2 code are supported.

## Usage

Create a file named `.github/workflows/black.yml` inside your repository with:
Expand All @@ -17,19 +25,26 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: psf/black@stable
```

We recommend the use of the `@stable` tag, but per version tags also exist if you prefer
that.
that. Note that the action's version you select is independent of the version of _Black_
the action will use.

The version of _Black_ the action will use can be configured via `version`. The action
defaults to the latest release available on PyPI. Only versions available from PyPI are
supported, so no commit SHAs or branch names.

You can also configure the arguments passed to _Black_ via `options` (defaults to
`'--check --diff'`) and `src` (default is `'.'`)

You may use `options` (Default is `'--check --diff'`) and `src` (Default is `'.'`) as
follows:
Here's an example configuration:

```yaml
- uses: psf/black@stable
with:
options: "--check --verbose"
src: "./src"
version: "21.5b1"
```

0 comments on commit be4fe0c

Please sign in to comment.