Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add optional uvloop import - If we find `uvloop` in the env for black, blackd or black-primer lets try and use it - Add a uvloop extra install Fixes #2257 Test: - Add ci job to install black[uvloop] and run a primer run with uvloop - Only with latest python (3.9) - Will be handy to compare runtimes as a very unoffical benchmark * Remove tox install * Add to CHANGES/news
- Loading branch information
1 parent
92f20d7
commit 754eecf
Showing
6 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: test uvloop | ||
|
||
on: | ||
push: | ||
paths-ignore: | ||
- "docs/**" | ||
- "*.md" | ||
|
||
pull_request: | ||
paths-ignore: | ||
- "docs/**" | ||
- "*.md" | ||
|
||
jobs: | ||
build: | ||
# We want to run on external PRs, but not on our own internal PRs as they'll be run | ||
# by the push to the branch. Without this if check, checks are duplicated since | ||
# internal PRs match both the push and pull_request events. | ||
if: | ||
github.event_name == 'push' || github.event.pull_request.head.repo.full_name != | ||
github.repository | ||
|
||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, macOS-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
|
||
- name: Install latest pip | ||
run: | | ||
python -m pip install --upgrade pip | ||
- name: Test uvloop Extra Install | ||
run: | | ||
python -m pip install -e ".[uvloop]" | ||
- name: Primer uvloop run | ||
run: | | ||
black-primer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,14 @@ | |
import black | ||
import click | ||
|
||
# If our environment has uvloop installed lets use it | ||
try: | ||
import uvloop | ||
|
||
uvloop.install() | ||
This comment has been minimized.
Sorry, something went wrong.
skrawcz
|
||
except ImportError: | ||
pass | ||
|
||
from _black_version import version as __version__ | ||
|
||
# This is used internally by tests to shut down the server prematurely | ||
|
Opinion: Black as a library shouldn't assume it isn't already running within a system with an already established eventloop. Calling
uvloop.install()
wipes out the current event loop settings if there were any set.Suggestion: check for a running event loop before calling install.
e.g.