From: Cooper Lees Date: Wed, 26 May 2021 12:52:09 +0000 (-0700) Subject: Add optional uvloop import (#2258) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/754eecf69eed0bdc75fe224c19a702a4f0676807 Add optional uvloop import (#2258) * 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 --- diff --git a/.github/workflows/uvloop_test.yml b/.github/workflows/uvloop_test.yml new file mode 100644 index 0000000..5d23ec6 --- /dev/null +++ b/.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 + # 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 diff --git a/CHANGES.md b/CHANGES.md index 1b7a54a..de326e4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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_ diff --git a/setup.py b/setup.py index 2b5f71f..5549ae3 100644 --- a/setup.py +++ b/setup.py @@ -86,6 +86,7 @@ setup( "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=[ diff --git a/src/black/__init__.py b/src/black/__init__.py index f46b866..90aad22 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -54,6 +54,13 @@ from blib2to3.pgen2 import token 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 diff --git a/src/black_primer/cli.py b/src/black_primer/cli.py index 00b54d6..f099704 100644 --- a/src/black_primer/cli.py +++ b/src/black_primer/cli.py @@ -13,6 +13,14 @@ import click 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") diff --git a/src/blackd/__init__.py b/src/blackd/__init__.py index fc68473..10b6168 100644 --- a/src/blackd/__init__.py +++ b/src/blackd/__init__.py @@ -22,6 +22,14 @@ except ImportError as ie: 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