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

Add optional uvloop import #2258

Merged
merged 3 commits into from May 26, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/uvloop_test.yml
@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

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

what does internal vs external mean in this context?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is copy pasta to maintain other CI behavior - this stops running the same CI twice for maintainers like me who make a branch and push to the black repo itself. @ichard26 did this and I like that it saves some resources. GitHub should really default to this to save CPU. One of us should go work there and claim the reward points.

# 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
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -9,6 +9,7 @@
- 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)

### _Blackd_

Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -86,6 +86,7 @@ def get_long_description() -> str:
"d": ["aiohttp>=3.6.0", "aiohttp-cors>=0.4.0"],
"colorama": ["colorama>=0.4.3"],
"python2": ["typed-ast>=1.4.2"],
"uvloop": ["uvloop>=0.15.2"],
},
test_suite="tests.test_black",
classifiers=[
Expand Down
7 changes: 7 additions & 0 deletions src/black/__init__.py
Expand Up @@ -54,6 +54,13 @@

from _black_version import version as __version__

# If our environment has uvloop installed lets use it
try:
import uvloop

uvloop.install()
except ImportError:
pass

# types
FileContent = str
Expand Down
8 changes: 8 additions & 0 deletions src/black_primer/cli.py
Expand Up @@ -13,6 +13,14 @@

from black_primer import lib

# If our environment has uvloop installed lets use it
try:
import uvloop

uvloop.install()
except ImportError:
pass


DEFAULT_CONFIG = Path(__file__).parent / "primer.json"
_timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
Expand Down
8 changes: 8 additions & 0 deletions src/blackd/__init__.py
Expand Up @@ -22,6 +22,14 @@
import black
import click

# If our environment has uvloop installed lets use it
try:
import uvloop

uvloop.install()
except ImportError:
pass

from _black_version import version as __version__

# This is used internally by tests to shut down the server prematurely
Expand Down