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

Support version specifiers in GH action #3265

Merged
merged 4 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@

<!-- For example, Docker, GitHub Actions, pre-commit, editors -->

- Update GitHub Action to support use of version specifiers (e.g. `<23`) for Black
version (#3265)

### Documentation

<!-- Major changes to documentation and policies. Small docs changes
Expand Down
7 changes: 4 additions & 3 deletions action/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

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

req = "black[colorama]"
if VERSION:
req += f"=={VERSION}"
version_specifier = VERSION
if VERSION and VERSION[0] in "0123456789":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if VERSION and VERSION[0] in "0123456789":
if VERSION and VERSION[0].isdigit():

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah damn, I didn't notice this comment before I made mine 😄 I can change it, though I would like to note that isdecimal is less wide check than isdigit so it might be better choice if we're switching it.

Copy link
Contributor Author

@Jackenmen Jackenmen Sep 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could do VERSION[0].isdecimal() here though that's rather wide due to it supporting all Unicode characters in the Unicode General Category “Nd”. Personally, I tend to avoid isdecimal/isdigit/isnumeric methods because they evaluate to True for more than I actually want but I can change this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's fine either way, since we only care about recognising version specifier characters, which won't be decimal or digits. But no biggie.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do packaging tools normalize non-ascii digits? If so, I'd prefer isdecimal() otherwise I'd prefer being stricter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pip doesn't handle Unicode numbers:

❯ pip install 'black==२२.१'
ERROR: Could not find a version that satisfies the requirement black==२२.१ (from versions: 18.3a0, 18.3a1, 18.3a2, 18.3a3, 18.3a4, 18.4a0, 18.4a1, 18.4a2, 18.4a3, 18.4a4, 18.5b0, 18.5b1, 18.6b0, 18.6b1, 18.6b2, 18.6b3, 18.6b4, 18.9b0, 19.3b0, 19.10b0, 20.8b0, 20.8b1, 21.4b0, 21.4b1, 21.4b2, 21.5b0, 21.5b1, 21.5b2, 21.6b0, 21.7b0, 21.8b0, 21.9b0, 21.10b0, 21.11b0, 21.11b1, 21.12b0, 22.1.0, 22.3.0, 22.6.0, 22.8.0)
ERROR: No matching distribution found for black==२२.१

So in the end, it shouldn't matter whether we use isdecimal() or the in check as it will fail anyway.

version_specifier = f"=={VERSION}"
req = f"black[colorama]{version_specifier}"
pip_proc = run(
[str(ENV_BIN / "python"), "-m", "pip", "install", req],
stdout=PIPE,
Expand Down
21 changes: 18 additions & 3 deletions docs/integrations/github_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ We recommend the use of the `@stable` tag, but per version tags also exist if yo
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.
The version of _Black_ the action will use can be configured via `version`. This can be
any
[valid version specifier](https://packaging.python.org/en/latest/glossary/#term-Version-Specifier)
or just the version number if you want an exact 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 `'.'`)
Expand All @@ -48,3 +51,15 @@ Here's an example configuration:
src: "./src"
version: "21.5b1"
```

If you want to match versions covered by Black's
[stability policy](labels/stability-policy), you can use the compatible release operator
(`~=`):

```yaml
- uses: psf/black@stable
with:
options: "--check --verbose"
src: "./src"
version: "~= 22.0"
```