diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 2faf9a753..f0b51b67e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/setup-python@v5 with: python-version: "3.12" - + - name: Install build dependencies run: pip install -r docs/requirements.txt - name: Rendering HTML documentation diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 619ed4ced..000000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Lint - -on: - push: - branches: - - master - pull_request: - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - - name: Install dependencies - run: pip install ruff - - name: Lint - run: | - ruff --version - ruff format --check --diff . - ruff check --diff . diff --git a/.github/workflows/pre-commit-detect-outdated.yml b/.github/workflows/pre-commit-detect-outdated.yml new file mode 100644 index 000000000..8b782d1ad --- /dev/null +++ b/.github/workflows/pre-commit-detect-outdated.yml @@ -0,0 +1,62 @@ +# Copyright (c) 2023 Sebastian Pipping +# Licensed under the MIT license + +name: Detect outdated pre-commit hooks + +on: + schedule: + - cron: '0 16 * * 5' # Every Friday 4pm + +# NOTE: This will drop all permissions from GITHUB_TOKEN except metadata read, +# and then (re)add the ones listed below: +permissions: + contents: write + pull-requests: write + +jobs: + pre_commit_detect_outdated: + name: Detect outdated pre-commit hooks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3.12 + uses: actions/setup-python@v4 + with: + python-version: 3.12 + + - name: Install pre-commit + run: |- + pip install \ + --disable-pip-version-check \ + --no-warn-script-location \ + --user \ + pre-commit + echo "PATH=${HOME}/.local/bin:${PATH}" >> "${GITHUB_ENV}" + + - name: Check for outdated hooks + run: |- + pre-commit autoupdate + git diff -- .pre-commit-config.yaml + + - name: Create pull request from changes (if any) + id: create-pull-request + uses: peter-evans/create-pull-request@v5 + with: + author: 'pre-commit ' + base: master + body: |- + For your consideration. + + :warning: Please **CLOSE AND RE-OPEN** this pull request so that [further workflow runs get triggered](https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#triggering-further-workflow-runs) for this pull request. + branch: precommit-autoupdate + commit-message: "pre-commit: Autoupdate" + delete-branch: true + draft: true + labels: enhancement + title: "pre-commit: Autoupdate" + + - name: Log pull request URL + if: "${{ steps.create-pull-request.outputs.pull-request-url }}" + run: | + echo "Pull request URL is: ${{ steps.create-pull-request.outputs.pull-request-url }}" diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 000000000..a7bb78bb3 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,20 @@ +# Copyright (c) 2023 Sebastian Pipping +# Licensed under the MIT license + +name: Run pre-commit + +on: +- pull_request +- push +- workflow_dispatch + +jobs: + pre-commit: + name: Run pre-commit + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.12 + - uses: pre-commit/action@v3.0.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..9d4273ee6 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,17 @@ +# Copyright (c) 2023 Sebastian Pipping +# Licensed under the MIT license + +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.7 + hooks: + - id: ruff + args: ["--show-source"] + - id: ruff-format + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-merge-conflict + - id: end-of-file-fixer + - id: trailing-whitespace diff --git a/docs/_static/vcr.svg b/docs/_static/vcr.svg index 061b5b153..b0957dc68 100644 --- a/docs/_static/vcr.svg +++ b/docs/_static/vcr.svg @@ -24,4 +24,4 @@ - \ No newline at end of file + diff --git a/docs/advanced.rst b/docs/advanced.rst index 65b3d4be9..118570f33 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -16,7 +16,7 @@ a nice addition. Here's an example: with vcr.use_cassette('fixtures/vcr_cassettes/synopsis.yaml') as cass: response = urllib2.urlopen('http://www.zombo.com/').read() # cass should have 1 request inside it - assert len(cass) == 1 + assert len(cass) == 1 # the request uri should have been http://www.zombo.com/ assert cass.requests[0].uri == 'http://www.zombo.com/' @@ -208,7 +208,7 @@ So these two calls are the same: # original (still works) vcr = VCR(filter_headers=['authorization']) - + # new vcr = VCR(filter_headers=[('authorization', None)]) @@ -218,7 +218,7 @@ Here are two examples of the new functionality: # replace with a static value (most common) vcr = VCR(filter_headers=[('authorization', 'XXXXXX')]) - + # replace with a callable, for example when testing # lots of different kinds of authorization. def replace_auth(key, value, request): @@ -286,7 +286,7 @@ sensitive data from the response body: before_record_response=scrub_string(settings.USERNAME, 'username'), ) with my_vcr.use_cassette('test.yml'): - # your http code here + # your http code here Decode compressed response diff --git a/docs/changelog.rst b/docs/changelog.rst index 17d145719..52f698082 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -287,4 +287,3 @@ All help in providing PRs to close out bug issues is appreciated. Even if that i - Add support for requests / urllib3 - 0.0.1 - Initial Release - diff --git a/runtests.sh b/runtests.sh index f21972554..9e40a2dcf 100755 --- a/runtests.sh +++ b/runtests.sh @@ -1,7 +1,7 @@ #!/bin/bash # https://blog.ionelmc.ro/2015/04/14/tox-tricks-and-patterns/#when-it-inevitably-leads-to-shell-scripts -# If you are getting an INVOCATION ERROR for this script then there is +# If you are getting an INVOCATION ERROR for this script then there is # a good chance you are running on Windows. # You can and should use WSL for running tox on Windows when it calls bash scripts. REQUESTS_CA_BUNDLE=`python3 -m pytest_httpbin.certs` exec pytest "$@" diff --git a/tests/fixtures/migration/new_cassette.json b/tests/fixtures/migration/new_cassette.json index 5526989b5..822fa2a72 100644 --- a/tests/fixtures/migration/new_cassette.json +++ b/tests/fixtures/migration/new_cassette.json @@ -15,9 +15,9 @@ }, "response": { "status": { - "message": "OK", + "message": "OK", "code": 200 - }, + }, "headers": { "access-control-allow-origin": ["*"], "content-type": ["application/json"], @@ -25,7 +25,7 @@ "server": ["gunicorn/0.17.4"], "content-length": ["32"], "connection": ["keep-alive"] - }, + }, "body": { "string": "{\n \"origin\": \"217.122.164.194\"\n}" } diff --git a/tests/fixtures/migration/new_cassette.yaml b/tests/fixtures/migration/new_cassette.yaml index e319dc8e1..b30652f27 100644 --- a/tests/fixtures/migration/new_cassette.yaml +++ b/tests/fixtures/migration/new_cassette.yaml @@ -2,7 +2,7 @@ version: 1 interactions: - request: body: null - headers: + headers: accept: ['*/*'] accept-encoding: ['gzip, deflate, compress'] user-agent: ['python-requests/2.2.1 CPython/2.6.1 Darwin/10.8.0'] diff --git a/tests/fixtures/migration/old_cassette.json b/tests/fixtures/migration/old_cassette.json index f6bfed1b5..7c4ff680a 100644 --- a/tests/fixtures/migration/old_cassette.json +++ b/tests/fixtures/migration/old_cassette.json @@ -1,31 +1,31 @@ [ { "request": { - "body": null, - "protocol": "http", - "method": "GET", + "body": null, + "protocol": "http", + "method": "GET", "headers": { - "accept-encoding": "gzip, deflate, compress", - "accept": "*/*", + "accept-encoding": "gzip, deflate, compress", + "accept": "*/*", "user-agent": "python-requests/2.2.1 CPython/2.6.1 Darwin/10.8.0" - }, - "host": "httpbin.org", - "path": "/ip", + }, + "host": "httpbin.org", + "path": "/ip", "port": 80 - }, + }, "response": { "status": { - "message": "OK", + "message": "OK", "code": 200 - }, + }, "headers": [ - "access-control-allow-origin: *\r\n", - "content-type: application/json\r\n", - "date: Mon, 21 Apr 2014 23:13:40 GMT\r\n", - "server: gunicorn/0.17.4\r\n", - "content-length: 32\r\n", + "access-control-allow-origin: *\r\n", + "content-type: application/json\r\n", + "date: Mon, 21 Apr 2014 23:13:40 GMT\r\n", + "server: gunicorn/0.17.4\r\n", + "content-length: 32\r\n", "connection: keep-alive\r\n" - ], + ], "body": { "string": "{\n \"origin\": \"217.122.164.194\"\n}" } diff --git a/tests/fixtures/wild/domain_redirect.yaml b/tests/fixtures/wild/domain_redirect.yaml index 618babc18..5df92106e 100644 --- a/tests/fixtures/wild/domain_redirect.yaml +++ b/tests/fixtures/wild/domain_redirect.yaml @@ -10,7 +10,7 @@ interactions: uri: http://seomoz.org/ response: body: {string: ''} - headers: + headers: Location: ['http://moz.com/'] Server: ['BigIP'] Connection: ['Keep-Alive']