From 52b46849c4c685d1ca0aa5b11eabeb130cdd19ac Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 6 Dec 2020 00:04:45 +0100 Subject: [PATCH 1/6] update pyinstaller, use python3.9 for CI tasks --- .github/workflows/main.yml | 10 +++++----- tox.ini | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index baedaf5a7..0c48824b7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -85,7 +85,7 @@ jobs: - uses: actions/checkout@v1 - uses: actions/setup-python@v2 with: - python-version: '3.8' + python-version: '3.9' - run: pip install tox - run: tox -e cibuild -- build - uses: actions/upload-artifact@v2 @@ -107,7 +107,7 @@ jobs: - uses: actions/checkout@v1 - uses: actions/setup-python@v2 with: - python-version: '3.7' + python-version: '3.9' - if: matrix.os == 'windows-latest' uses: actions/cache@v1 with: @@ -153,7 +153,7 @@ jobs: - uses: actions/checkout@v1 - uses: actions/setup-python@v2 with: - python-version: '3.8' + python-version: '3.9' - run: pip install tox - run: | wget https://github.com/gohugoio/hugo/releases/download/v0.70.0/hugo_extended_0.70.0_Linux-64bit.deb @@ -173,7 +173,7 @@ jobs: - uses: actions/checkout@v1 - uses: actions/setup-python@v2 with: - python-version: '3.7' + python-version: '3.9' - run: pip install tox - uses: actions/download-artifact@v2 with: @@ -198,7 +198,7 @@ jobs: - uses: actions/checkout@v1 - uses: actions/setup-python@v2 with: - python-version: '3.8' + python-version: '3.9' - uses: actions/download-artifact@v2 with: path: release/dist diff --git a/tox.ini b/tox.ini index e3ba52d2e..374ad818d 100644 --- a/tox.ini +++ b/tox.ini @@ -51,7 +51,7 @@ commands = passenv = CI_* GITHUB_* AWS_* TWINE_* DOCKER_* deps = -rrequirements.txt - pyinstaller==4.0 + pyinstaller==4.1 twine==3.2.0 awscli commands = From c5eae9d75281fcb276e6079755cf60deaca0b3dc Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 6 Dec 2020 00:25:09 +0100 Subject: [PATCH 2/6] drop support for Python 3.6 and 3.7 We require Python 3.8 for sans-io (#1775), so we need to drop support for older versions. --- .github/workflows/main.yml | 4 ---- CHANGELOG.rst | 2 ++ dev.ps1 | 4 ++-- mitmproxy/master.py | 2 +- mitmproxy/net/http/url.py | 2 +- mitmproxy/net/tcp.py | 2 +- mitmproxy/tools/_main.py | 3 +-- mitmproxy/tools/main.py | 6 +++--- mitmproxy/utils/debug.py | 2 -- setup.py | 10 +++------- test/mitmproxy/addons/test_readfile.py | 4 ---- test/mitmproxy/net/http/test_url.py | 2 -- test/mitmproxy/utils/test_asyncio_utils.py | 7 +++---- test/mitmproxy/utils/test_debug.py | 3 +-- tox.ini | 4 ++-- 15 files changed, 20 insertions(+), 37 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0c48824b7..1e4fb7ce3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,10 +51,6 @@ jobs: py: 3.9 - os: ubuntu-latest py: 3.8 - - os: ubuntu-latest - py: 3.7 - - os: ubuntu-latest - py: 3.6 runs-on: ${{ matrix.os }} steps: - run: printenv diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 370634896..f6b9d0c0d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,12 +4,14 @@ Release History Unreleased: mitmproxy next ========================== +* Mitmproxy now requires Python 3.8 or above. * Fix query parameters in asgiapp addon (@jpstotz) * Fix command history failing on file IO errors (@Kriechi) * Deprecation of pathod and pathoc tools and modules. Future releases might not contain them! (@Kriechi) * Addon to suppress unwanted error messages sent by mitmproxy. (@anneborcherding) * Updated imports and styles for web scanner helper addons. (@anneborcherding) * Inform when underscore-formatted options are used in client arg. (@jrblixt) +* Binaries are now built with Python 3.9 (@mhils) * --- TODO: add new PRs above this line --- diff --git a/dev.ps1 b/dev.ps1 index 6193c5f67..d5de05265 100644 --- a/dev.ps1 +++ b/dev.ps1 @@ -1,8 +1,8 @@ $ErrorActionPreference = "Stop" $pyver = python --version -if($pyver -notmatch "3\.[6-9]") { - Write-Warning "Unexpected Python version, expected Python 3.6 or above: $pyver" +if($pyver -notmatch "3\.(8|9|\d{2,})") { + Write-Warning "Unexpected Python version, expected Python 3.8 or above: $pyver" } python -m venv .\venv --copies diff --git a/mitmproxy/master.py b/mitmproxy/master.py index e3867033a..e88c79a93 100644 --- a/mitmproxy/master.py +++ b/mitmproxy/master.py @@ -90,7 +90,7 @@ class Master: if not self.should_exit.is_set(): # pragma: no cover self.shutdown() loop = asyncio.get_event_loop() - tasks = asyncio.all_tasks(loop) if sys.version_info >= (3, 7) else asyncio.Task.all_tasks(loop) + tasks = asyncio.all_tasks(loop) for p in tasks: p.cancel() loop.close() diff --git a/mitmproxy/net/http/url.py b/mitmproxy/net/http/url.py index 902e6157e..14898c31e 100644 --- a/mitmproxy/net/http/url.py +++ b/mitmproxy/net/http/url.py @@ -56,7 +56,7 @@ def parse(url): if isinstance(parsed, urllib.parse.ParseResult): parsed = parsed.encode("ascii") - port = parsed.port # Returns None if port number invalid in Py3.5. Will throw ValueError in Py3.6 + port = parsed.port if not port: port = 443 if parsed.scheme == b"https" else 80 diff --git a/mitmproxy/net/tcp.py b/mitmproxy/net/tcp.py index f27db6ad1..d4cd0c018 100644 --- a/mitmproxy/net/tcp.py +++ b/mitmproxy/net/tcp.py @@ -20,7 +20,7 @@ from mitmproxy.coretypes import basethread socket_fileobject = socket.SocketIO # workaround for https://bugs.python.org/issue29515 -# Python 3.6 for Windows is missing a constant +# Python 3.8 for Windows is missing a constant, fixed in 3.9 IPPROTO_IPV6 = getattr(socket, "IPPROTO_IPV6", 41) diff --git a/mitmproxy/tools/_main.py b/mitmproxy/tools/_main.py index 7e9f91b38..b4c1f5acd 100644 --- a/mitmproxy/tools/_main.py +++ b/mitmproxy/tools/_main.py @@ -1,6 +1,5 @@ """ -This file contains python3.6+ syntax! -Feel free to import and use whatever new package you deem necessary. +This file now contains python3.8+ syntax! """ import os diff --git a/mitmproxy/tools/main.py b/mitmproxy/tools/main.py index 60c3e2e86..84dfee1f3 100644 --- a/mitmproxy/tools/main.py +++ b/mitmproxy/tools/main.py @@ -1,17 +1,17 @@ """ This file must be kept in a python2.7 and python3.5 compatible syntax! -DO NOT use type annotations or other python3.6-only features that makes this file unparsable by older interpreters! +DO NOT use type annotations or other modern features that makes this file unparsable by older interpreters! """ from __future__ import print_function # this is here for the version check to work on Python 2. import sys -if sys.version_info < (3, 6): +if sys.version_info < (3, 8): # This must be before any mitmproxy imports, as they already break! # Keep all other imports below with the 'noqa' magic comment. print("#" * 76, file=sys.stderr) - print("# mitmproxy requires Python 3.6 or higher! #", file=sys.stderr) + print("# mitmproxy requires Python 3.8 or higher! #", file=sys.stderr) print("#" + " " * 74 + "#", file=sys.stderr) print("# Please upgrade your Python interpreter or use our mitmproxy binaries from #", file=sys.stderr) print("# https://mitmproxy.org. If your operating system does not include the #", file=sys.stderr) diff --git a/mitmproxy/utils/debug.py b/mitmproxy/utils/debug.py index 17d594208..986372efa 100644 --- a/mitmproxy/utils/debug.py +++ b/mitmproxy/utils/debug.py @@ -83,8 +83,6 @@ def dump_info(signal=None, frame=None, file=sys.stdout, testing=False): # pragm print(i[1], i[0]) try: - if sys.version_info < (3, 8): - raise RuntimeError asyncio.get_running_loop() except RuntimeError: pass diff --git a/setup.py b/setup.py index ff009188a..e4d96b9dc 100644 --- a/setup.py +++ b/setup.py @@ -34,8 +34,6 @@ setup( "Operating System :: POSIX", "Operating System :: Microsoft :: Windows", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: Implementation :: CPython", @@ -65,6 +63,7 @@ setup( "pathoc = pathod.pathoc_cmdline:go_pathoc" ] }, + python_requires='>=3.8', # https://packaging.python.org/en/latest/requirements/#install-requires # It is not considered best practice to use install_requires to pin dependencies to specific versions. install_requires=[ @@ -75,8 +74,8 @@ setup( "click>=7.0,<8", "cryptography>=3.2,<3.3", "flask>=1.1.1,<1.2", - "h2>=4.0,<5; python_version>='3.6.0'", # python_version only needed to make "py36+ required" message work - "hyperframe>=6.0,<7; python_version>='3.6.0'", # python_version only needed to make "py36+ required" message work + "h2>=4.0,<5", + "hyperframe>=6.0,<7", "kaitaistruct>=0.7,<0.10", "ldap3>=2.8,<2.9", "msgpack>=1.0.0, <1.1.0", @@ -98,9 +97,6 @@ setup( ':sys_platform == "win32"': [ "pydivert>=2.0.3,<2.2", ], - ':python_version == "3.6"': [ - "dataclasses>=0.7", - ], 'dev': [ "hypothesis>=5.8,<6", "parver>=0.1,<2.0", diff --git a/test/mitmproxy/addons/test_readfile.py b/test/mitmproxy/addons/test_readfile.py index 71efb5696..0383beb23 100644 --- a/test/mitmproxy/addons/test_readfile.py +++ b/test/mitmproxy/addons/test_readfile.py @@ -1,6 +1,5 @@ import asyncio import io -import sys import pytest from unittest import mock @@ -47,7 +46,6 @@ class TestReadFile: with pytest.raises(Exception, match="Invalid readfile filter"): tctx.configure(rf, readfile_filter="~~") - @pytest.mark.skipif(sys.version_info < (3, 8), reason='requires Python 3.8 or higher') @pytest.mark.asyncio async def test_read(self, tmpdir, data, corrupt_data): rf = readfile.ReadFile() @@ -95,7 +93,6 @@ class TestReadFile: class TestReadFileStdin: - @pytest.mark.skipif(sys.version_info < (3, 8), reason='requires Python 3.8 or higher') @mock.patch('sys.stdin') @pytest.mark.asyncio async def test_stdin(self, stdin, data, corrupt_data): @@ -111,7 +108,6 @@ class TestReadFileStdin: with pytest.raises(exceptions.FlowReadException): await rf.load_flows(stdin.buffer) - @pytest.mark.skipif(sys.version_info < (3, 8), reason='requires Python 3.8 or higher') @pytest.mark.asyncio async def test_normal(self, tmpdir, data): rf = readfile.ReadFileStdin() diff --git a/test/mitmproxy/net/http/test_url.py b/test/mitmproxy/net/http/test_url.py index a4c586dc3..51435cb0c 100644 --- a/test/mitmproxy/net/http/test_url.py +++ b/test/mitmproxy/net/http/test_url.py @@ -1,7 +1,6 @@ from typing import AnyStr import pytest -import sys from mitmproxy.net.http import url from mitmproxy.net.http.url import parse_authority @@ -62,7 +61,6 @@ def test_ascii_check(): b'%BD%E7%8C%AB%E6%B0%93%E7%8C%AB%E6%B0%93' -@pytest.mark.skipif(sys.version_info < (3, 6), reason='requires Python 3.6 or higher') def test_parse_port_range(): # Port out of range with pytest.raises(ValueError): diff --git a/test/mitmproxy/utils/test_asyncio_utils.py b/test/mitmproxy/utils/test_asyncio_utils.py index ed40e0a34..5446027ae 100644 --- a/test/mitmproxy/utils/test_asyncio_utils.py +++ b/test/mitmproxy/utils/test_asyncio_utils.py @@ -1,5 +1,4 @@ import asyncio -import sys import pytest @@ -15,7 +14,6 @@ async def ttask(): @pytest.mark.asyncio -@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires Python 3.8") async def test_simple(): task = asyncio_utils.create_task( ttask(), @@ -30,7 +28,6 @@ async def test_simple(): assert task.cancelled() -@pytest.mark.skipif(sys.version_info < (3, 8), reason="requires Python 3.8") def test_closed_loop(): # Crude test for line coverage. # This should eventually go, see the description in asyncio_utils.create_task for details. @@ -38,9 +35,11 @@ def test_closed_loop(): ttask(), name="ttask", ) + t = ttask() with pytest.raises(RuntimeError): asyncio_utils.create_task( - ttask(), + t, name="ttask", ignore_closed_loop=False, ) + t.close() # suppress "not awaited" warning \ No newline at end of file diff --git a/test/mitmproxy/utils/test_debug.py b/test/mitmproxy/utils/test_debug.py index 065574293..88a338093 100644 --- a/test/mitmproxy/utils/test_debug.py +++ b/test/mitmproxy/utils/test_debug.py @@ -24,8 +24,7 @@ def test_dump_info(): async def test_dump_info_async(): cs = io.StringIO() debug.dump_info(None, None, file=cs, testing=True) - if sys.version_info >= (3, 8): - assert "Tasks" in cs.getvalue() + assert "Tasks" in cs.getvalue() def test_dump_stacks(): diff --git a/tox.ini b/tox.ini index 374ad818d..355042215 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py35, py36, py37, py38, py39, flake8, filename_matching, mypy, individual_coverage, docs +envlist = py35, py38, py39, flake8, filename_matching, mypy, individual_coverage, docs skipsdist = True toxworkdir={env:TOX_WORK_DIR:.tox} @@ -20,7 +20,7 @@ whitelist_externals = deps = -rrequirements.txt commands = - bash -c "mitmdump --version 2>&1 | grep 'mitmproxy requires Python 3.6'" + bash -c "mitmdump --version 2>&1 | grep 'mitmproxy requires Python 3.8'" [testenv:flake8] deps = flake8==3.8.4 From 41a37eca1c9c1a361c1cd4c6d35a45e2a43f1b18 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 6 Dec 2020 14:01:47 +0100 Subject: [PATCH 3/6] remove legacy main file --- mitmproxy/tools/main.py | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 mitmproxy/tools/main.py diff --git a/mitmproxy/tools/main.py b/mitmproxy/tools/main.py deleted file mode 100644 index 84dfee1f3..000000000 --- a/mitmproxy/tools/main.py +++ /dev/null @@ -1,22 +0,0 @@ -""" -This file must be kept in a python2.7 and python3.5 compatible syntax! -DO NOT use type annotations or other modern features that makes this file unparsable by older interpreters! -""" - -from __future__ import print_function # this is here for the version check to work on Python 2. - -import sys - -if sys.version_info < (3, 8): - # This must be before any mitmproxy imports, as they already break! - # Keep all other imports below with the 'noqa' magic comment. - print("#" * 76, file=sys.stderr) - print("# mitmproxy requires Python 3.8 or higher! #", file=sys.stderr) - print("#" + " " * 74 + "#", file=sys.stderr) - print("# Please upgrade your Python interpreter or use our mitmproxy binaries from #", file=sys.stderr) - print("# https://mitmproxy.org. If your operating system does not include the #", file=sys.stderr) - print("# required Python version, you can try using pyenv or similar tools. #", file=sys.stderr) - print("#" * 76, file=sys.stderr) - sys.exit(1) -else: - from ._main import * # noqa From ee414cde7000c252aec4f29c92c39647c777b2ec Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 6 Dec 2020 14:03:12 +0100 Subject: [PATCH 4/6] move main file, remove checks for outdated Python these are now handled by setup.py's python_requires. --- .github/workflows/main.yml | 9 --------- mitmproxy/tools/{_main.py => main.py} | 0 tox.ini | 8 -------- 3 files changed, 17 deletions(-) rename mitmproxy/tools/{_main.py => main.py} (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1e4fb7ce3..8473162ac 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -64,15 +64,6 @@ jobs: with: file: ./coverage.xml name: ${{ matrix.os }} - test-unsupported-python-version: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - uses: actions/setup-python@v2 - with: - python-version: '3.5' - - run: pip install tox - - run: tox -e py35 build-wheel: runs-on: ubuntu-latest env: diff --git a/mitmproxy/tools/_main.py b/mitmproxy/tools/main.py similarity index 100% rename from mitmproxy/tools/_main.py rename to mitmproxy/tools/main.py diff --git a/tox.ini b/tox.ini index 355042215..cf0bda285 100644 --- a/tox.ini +++ b/tox.ini @@ -14,14 +14,6 @@ commands = --full-cov=mitmproxy/ --full-cov=pathod/ \ {posargs} -[testenv:py35] -whitelist_externals = - bash -deps = - -rrequirements.txt -commands = - bash -c "mitmdump --version 2>&1 | grep 'mitmproxy requires Python 3.8'" - [testenv:flake8] deps = flake8==3.8.4 commands = From 7767fdb6d5c3e8ed60c6a866b0bb0833699613b2 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 6 Dec 2020 14:06:23 +0100 Subject: [PATCH 5/6] remove superfluous python version check --- dev.ps1 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/dev.ps1 b/dev.ps1 index d5de05265..3e776ab6d 100644 --- a/dev.ps1 +++ b/dev.ps1 @@ -1,10 +1,5 @@ $ErrorActionPreference = "Stop" -$pyver = python --version -if($pyver -notmatch "3\.(8|9|\d{2,})") { - Write-Warning "Unexpected Python version, expected Python 3.8 or above: $pyver" -} - python -m venv .\venv --copies & .\venv\Scripts\activate.ps1 From 884b5dc23464904274c86548907b22ca81c24661 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 7 Dec 2020 22:58:53 +0100 Subject: [PATCH 6/6] remove old python leftovers --- mitmproxy/tools/main.py | 4 ---- tox.ini | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/mitmproxy/tools/main.py b/mitmproxy/tools/main.py index b4c1f5acd..a85cb5eee 100644 --- a/mitmproxy/tools/main.py +++ b/mitmproxy/tools/main.py @@ -1,7 +1,3 @@ -""" -This file now contains python3.8+ syntax! -""" - import os import sys import asyncio diff --git a/tox.ini b/tox.ini index cf0bda285..acae7ce11 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py35, py38, py39, flake8, filename_matching, mypy, individual_coverage, docs +envlist = py38, py39, flake8, filename_matching, mypy, individual_coverage, docs skipsdist = True toxworkdir={env:TOX_WORK_DIR:.tox}