summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo van Kemenade <hugovk@users.noreply.github.com>2021-01-09 05:28:48 +0200
committerGitHub <noreply@github.com>2021-01-08 21:28:48 -0600
commit39e9548b9940505b8509ef673af22f994714cb14 (patch)
treeaa62cb0403e86a130ffaf00780389d003fa5d243
parent841a7271750b2694589f292e3f395541319a2a44 (diff)
downloadurllib3-39e9548b9940505b8509ef673af22f994714cb14.tar.gz
Use pyupgrade, black, isort, and flake8 via pre-commit
-rw-r--r--.github/workflows/ci.yml15
-rw-r--r--.github/workflows/lint.yml21
-rw-r--r--.pre-commit-config.yaml23
-rw-r--r--noxfile.py32
-rw-r--r--src/urllib3/request.py4
-rw-r--r--test/contrib/test_socks.py2
6 files changed, 67 insertions, 30 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 35ea5eeb..e3cc7851 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -7,21 +7,6 @@ defaults:
shell: bash
jobs:
- lint:
- runs-on: ubuntu-latest
-
- steps:
- - name: Checkout Repository
- uses: actions/checkout@v2
- - name: Set up Python 3.8
- uses: actions/setup-python@v2
- with:
- python-version: 3.8
- - name: Install dependencies
- run: python3.8 -m pip install nox
- - name: Lint the code
- run: nox -s lint
-
package:
runs-on: ubuntu-latest
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
new file mode 100644
index 00000000..055446cf
--- /dev/null
+++ b/.github/workflows/lint.yml
@@ -0,0 +1,21 @@
+name: lint
+
+on: [push, pull_request]
+
+jobs:
+ lint:
+ runs-on: ubuntu-20.04
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v2
+ - name: Set up Python 3.8
+ uses: actions/setup-python@v2
+ with:
+ python-version: 3.8
+ - name: Lint the code
+ uses: pre-commit/action@v2.0.0
+ - name: Install dependencies
+ run: python3.8 -m pip install nox
+ - name: Run mypy
+ run: nox -s mypy
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 00000000..467b4831
--- /dev/null
+++ b/.pre-commit-config.yaml
@@ -0,0 +1,23 @@
+repos:
+ - repo: https://github.com/asottile/pyupgrade
+ rev: v2.7.4
+ hooks:
+ - id: pyupgrade
+ args: ["--py36-plus"]
+
+ - repo: https://github.com/psf/black
+ rev: 20.8b1
+ hooks:
+ - id: black
+ args: ["--target-version", "py36"]
+
+ - repo: https://github.com/PyCQA/isort
+ rev: 5.6.4
+ hooks:
+ - id: isort
+
+ - repo: https://gitlab.com/pycqa/flake8
+ rev: 3.8.4
+ hooks:
+ - id: flake8
+ additional_dependencies: [flake8-2020]
diff --git a/noxfile.py b/noxfile.py
index ba0ec52c..4aa84a7d 100644
--- a/noxfile.py
+++ b/noxfile.py
@@ -86,23 +86,33 @@ def unsupported_python2(session):
@nox.session()
def format(session):
"""Run code formatters."""
- session.install("black", "isort")
- session.run("black", *SOURCE_FILES)
- session.run("isort", *SOURCE_FILES)
+ session.install("pre-commit")
+ session.run("pre-commit", "--version")
- lint(session)
+ process = subprocess.run(
+ ["pre-commit", "run", "--all-files"],
+ env=session.env,
+ text=True,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ )
+ # Ensure that pre-commit itself ran successfully
+ assert process.returncode in (0, 1)
@nox.session
def lint(session):
- session.install("flake8", "flake8-2020", "black", "isort", "mypy")
- session.run("flake8", "--version")
- session.run("black", "--version")
- session.run("isort", "--version")
+ session.install("pre-commit")
+ session.run("pre-commit", "run", "--all-files")
+
+ mypy(session)
+
+
+@nox.session()
+def mypy(session):
+ """Run mypy."""
+ session.install("mypy")
session.run("mypy", "--version")
- session.run("black", "--check", *SOURCE_FILES)
- session.run("isort", "--check", *SOURCE_FILES)
- session.run("flake8", *SOURCE_FILES)
session.log("mypy --strict src/urllib3")
all_errors, errors = [], []
diff --git a/src/urllib3/request.py b/src/urllib3/request.py
index dc9e9e7d..9907d9ec 100644
--- a/src/urllib3/request.py
+++ b/src/urllib3/request.py
@@ -48,7 +48,7 @@ class RequestMethods:
headers=None,
encode_multipart=True,
multipart_boundary=None,
- **kw
+ **kw,
) -> BaseHTTPResponse: # Abstract
raise NotImplementedError(
"Classes extending RequestMethods must implement "
@@ -107,7 +107,7 @@ class RequestMethods:
headers=None,
encode_multipart=True,
multipart_boundary=None,
- **urlopen_kw
+ **urlopen_kw,
) -> BaseHTTPResponse:
"""
Make a request using :meth:`urlopen` with the ``fields`` encoded in
diff --git a/test/contrib/test_socks.py b/test/contrib/test_socks.py
index a068a621..693d8ec0 100644
--- a/test/contrib/test_socks.py
+++ b/test/contrib/test_socks.py
@@ -1,5 +1,3 @@
-from __future__ import absolute_import
-
import socket
import threading
from socket import getaddrinfo as real_getaddrinfo