Skip to content

Commit ff12a37

Browse files
alexhugovk
andauthored
Remove Python2 from CI and code that branched on it (#5607)
* Remove Python2 from CI and code that branched on it * Update setup.py Co-authored-by: Hugo van Kemenade <[email protected]> * remove * review feedback Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent d634731 commit ff12a37

File tree

20 files changed

+189
-509
lines changed

20 files changed

+189
-509
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@ jobs:
1616
matrix:
1717
PYTHON:
1818
- {VERSION: "3.9", TOXENV: "pep8,packaging,docs", COVERAGE: "false"}
19-
- {VERSION: "pypy2", TOXENV: "pypy-nocoverage", COVERAGE: "false"}
2019
- {VERSION: "pypy3", TOXENV: "pypy3-nocoverage", COVERAGE: "false"}
21-
- {VERSION: "2.7", TOXENV: "py27", OPENSSL: {TYPE: "openssl", VERSION: "1.1.0l"}}
22-
- {VERSION: "2.7", TOXENV: "py27-ssh", OPENSSL: {TYPE: "openssl", VERSION: "1.1.0l"}}
2320
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "openssl", VERSION: "1.1.0l"}}
24-
- {VERSION: "2.7", TOXENV: "py27", OPENSSL: {TYPE: "openssl", VERSION: "1.1.1h"}}
2521
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "openssl", VERSION: "1.1.1h"}}
2622
- {VERSION: "3.9", TOXENV: "py39-ssh", OPENSSL: {TYPE: "openssl", VERSION: "1.1.1h"}}
2723
- {VERSION: "3.9", TOXENV: "py39", OPENSSL: {TYPE: "openssl", VERSION: "1.1.1h", CONFIG_FLAGS: "no-engine no-rc2 no-srtp no-ct"}}
@@ -86,16 +82,13 @@ jobs:
8682
strategy:
8783
matrix:
8884
IMAGE:
89-
- {IMAGE: "pyca/cryptography-runner-centos8", TOXENV: "py27"}
9085
- {IMAGE: "pyca/cryptography-runner-centos8", TOXENV: "py36"}
9186
- {IMAGE: "pyca/cryptography-runner-centos8-fips", TOXENV: "py36", FIPS: true}
92-
- {IMAGE: "pyca/cryptography-runner-stretch", TOXENV: "py27"}
9387
- {IMAGE: "pyca/cryptography-runner-buster", TOXENV: "py37"}
9488
- {IMAGE: "pyca/cryptography-runner-bullseye", TOXENV: "py38"}
9589
- {IMAGE: "pyca/cryptography-runner-sid", TOXENV: "py39"}
9690
- {IMAGE: "pyca/cryptography-runner-ubuntu-bionic", TOXENV: "py36"}
9791
- {IMAGE: "pyca/cryptography-runner-ubuntu-focal", TOXENV: "py38"}
98-
- {IMAGE: "pyca/cryptography-runner-ubuntu-rolling", TOXENV: "py27"}
9992
- {IMAGE: "pyca/cryptography-runner-ubuntu-rolling", TOXENV: "py38"}
10093
- {IMAGE: "pyca/cryptography-runner-ubuntu-rolling", TOXENV: "py38-randomorder"}
10194
- {IMAGE: "pyca/cryptography-runner-fedora", TOXENV: "py39"}
@@ -120,7 +113,6 @@ jobs:
120113
strategy:
121114
matrix:
122115
PYTHON:
123-
- {VERSION: "2.7", TOXENV: "py27", EXTRA_CFLAGS: ""}
124116
- {VERSION: "3.6", TOXENV: "py36", EXTRA_CFLAGS: ""}
125117
- {VERSION: "3.9", TOXENV: "py39", EXTRA_CFLAGS: "-DUSE_OSRANDOM_RNG_FOR_TESTING"}
126118
name: "Python ${{ matrix.PYTHON.VERSION }} on macOS"
@@ -162,7 +154,6 @@ jobs:
162154
- {ARCH: 'x86', WINDOWS: 'win32'}
163155
- {ARCH: 'x64', WINDOWS: 'win64'}
164156
PYTHON:
165-
- {VERSION: "2.7", TOXENV: "py27", MSVC_VERSION: "2010", CL_FLAGS: ""}
166157
- {VERSION: "3.6", TOXENV: "py36", MSVC_VERSION: "2019", CL_FLAGS: ""}
167158
- {VERSION: "3.7", TOXENV: "py37", MSVC_VERSION: "2019", CL_FLAGS: ""}
168159
- {VERSION: "3.8", TOXENV: "py38", MSVC_VERSION: "2019", CL_FLAGS: ""}
@@ -176,13 +167,6 @@ jobs:
176167
python-version: ${{ matrix.PYTHON.VERSION }}
177168
architecture: ${{ matrix.WINDOWS.ARCH }}
178169

179-
- name: Install MSVC for Python 2.7
180-
run: |
181-
Invoke-WebRequest -Uri https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi -OutFile VCForPython27.msi
182-
Start-Process msiexec -Wait -ArgumentList @('/i', 'VCForPython27.msi', '/qn', 'ALLUSERS=1')
183-
Remove-Item VCForPython27.msi -Force
184-
shell: powershell
185-
if: matrix.PYTHON.VERSION == '2.7'
186170
- run: python -m pip install tox requests coverage
187171
- name: Download OpenSSL
188172
run: |

.github/workflows/wheel-builder.yml

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
container: ${{ matrix.MANYLINUX.CONTAINER }}
1212
strategy:
1313
matrix:
14-
PYTHON: ["cp27-cp27m", "cp27-cp27mu", "cp36-cp36m"]
14+
PYTHON: ["cp36-cp36m"]
1515
MANYLINUX:
1616
- NAME: manylinux1_x86_64
1717
CONTAINER: "pyca/cryptography-manylinux1:x86_64"
@@ -57,12 +57,8 @@ jobs:
5757
strategy:
5858
matrix:
5959
PYTHON:
60-
- VERSION: '2.7'
61-
ABI_VERSION: '2.7'
62-
DOWNLOAD_URL: 'https://www.python.org/ftp/python/2.7.17/python-2.7.17-macosx10.9.pkg'
63-
BIN_PATH: '/Library/Frameworks/Python.framework/Versions/2.7/bin/python'
6460
- VERSION: '3.8'
65-
ABI_VERSION: '3.6'
61+
ABI_VERSION: 'cp36'
6662
DOWNLOAD_URL: 'https://www.python.org/ftp/python/3.8.2/python-3.8.2-macosx10.9.pkg'
6763
BIN_PATH: '/Library/Frameworks/Python.framework/Versions/3.8/bin/python3'
6864
name: "${{ matrix.PYTHON.VERSION }} ABI ${{ matrix.PYTHON.ABI_VERSION }} macOS"
@@ -85,16 +81,11 @@ jobs:
8581
- run: venv/bin/pip download cryptography==${{ github.event.inputs.version }} --no-deps --no-binary cryptography && tar zxvf cryptography*.tar.gz && mkdir wheelhouse
8682
- name: Build the wheel
8783
run: |
88-
REGEX="3\.([0-9])*"
89-
if [[ "${{ matrix.PYTHON.ABI_VERSION }}" =~ $REGEX ]]; then
90-
PY_LIMITED_API="--py-limited-api=cp3${BASH_REMATCH[1]}"
91-
fi
92-
9384
cd cryptography*
9485
CRYPTOGRAPHY_SUPPRESS_LINK_FLAGS="1" \
9586
LDFLAGS="${HOME}/openssl-macos-x86-64/lib/libcrypto.a ${HOME}/openssl-macos-x86-64/lib/libssl.a" \
9687
CFLAGS="-I${HOME}/openssl-macos-x86-64/include -mmacosx-version-min=10.10 -march=core2" \
97-
../venv/bin/python setup.py bdist_wheel $PY_LIMITED_API && mv dist/cryptography*.whl ../wheelhouse
88+
../venv/bin/python setup.py bdist_wheel --py-limited-api=${{ matrix.PYTHON.ABI_VERSION }} && mv dist/cryptography*.whl ../wheelhouse
9889
- run: venv/bin/pip install -f wheelhouse --no-index cryptography
9990
- run: |
10091
venv/bin/python -c "from cryptography.hazmat.backends.openssl.backend import backend;print('Loaded: ' + backend.openssl_version_text());print('Linked Against: ' + backend._ffi.string(backend._lib.OPENSSL_VERSION_TEXT).decode('ascii'))"
@@ -114,8 +105,7 @@ jobs:
114105
- {ARCH: 'x86', WINDOWS: 'win32'}
115106
- {ARCH: 'x64', WINDOWS: 'win64'}
116107
PYTHON:
117-
- {VERSION: "2.7", MSVC_VERSION: "2010"}
118-
- {VERSION: "3.8", MSVC_VERSION: "2019", "USE_ABI3": "true", "ABI_VERSION": "cp36"}
108+
- {VERSION: "3.8", MSVC_VERSION: "2019", "ABI_VERSION": "cp36"}
119109
name: "${{ matrix.PYTHON.VERSION }} ${{ matrix.WINDOWS.WINDOWS }} ${{ matrix.PYTHON.ABI_VERSION }}"
120110
steps:
121111
- uses: actions/checkout@v2
@@ -124,13 +114,6 @@ jobs:
124114
with:
125115
python-version: ${{ matrix.PYTHON.VERSION }}
126116
architecture: ${{ matrix.WINDOWS.ARCH }}
127-
- name: Install MSVC for Python 2.7
128-
run: |
129-
Invoke-WebRequest -Uri https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi -OutFile VCForPython27.msi
130-
Start-Process msiexec -Wait -ArgumentList @('/i', 'VCForPython27.msi', '/qn', 'ALLUSERS=1')
131-
Remove-Item VCForPython27.msi -Force
132-
shell: powershell
133-
if: matrix.PYTHON.VERSION == '2.7'
134117
- run: pip install requests
135118
- name: Download OpenSSL
136119
run: |
@@ -144,10 +127,7 @@ jobs:
144127
- run: python -m pip install -U pip wheel cffi six ipaddress "enum34; python_version < '3'"
145128
- run: pip download cryptography==${{ github.event.inputs.version }} --no-deps --no-binary cryptography && tar zxvf cryptography*.tar.gz && mkdir wheelhouse
146129
shell: bash
147-
- run: cd cryptography* && python setup.py bdist_wheel && mv dist/cryptography*.whl ../wheelhouse
148-
if: matrix.PYTHON.USE_ABI3 != 'true'
149130
- run: cd cryptography* && python setup.py bdist_wheel --py-limited-api=${{ matrix.PYTHON.ABI_VERSION }} && mv dist/cryptography*.whl ../wheelhouse
150-
if: matrix.PYTHON.USE_ABI3 == 'true'
151131
- run: pip install -f wheelhouse --no-index cryptography
152132
- name: Print the OpenSSL we built and linked against
153133
run: |

.zuul.d/jobs.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@
2525
vars:
2626
tox_envlist: py36
2727

28-
- job:
29-
name: pyca-cryptography-centos-8-py27-arm64
30-
parent: pyca-cryptography-base
31-
nodeset: centos-8-arm64
32-
vars:
33-
tox_envlist: py27
34-
3528
- job:
3629
name: pyca-cryptography-build-wheel
3730
abstract: true
@@ -57,12 +50,8 @@
5750
- platform: manylinux1_x86_64
5851
image: pyca/cryptography-manylinux1:x86_64
5952
pythons:
60-
- cp27-cp27m
61-
- cp27-cp27mu
6253
- cp36-cp36m
6354
- platform: manylinux2010_x86_64
6455
image: pyca/cryptography-manylinux2010:x86_64
6556
pythons:
66-
- cp27-cp27m
67-
- cp27-cp27mu
6857
- cp36-cp36m

.zuul.d/project.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
- pyca-cryptography-ubuntu-focal-py38-arm64
77
- pyca-cryptography-ubuntu-bionic-py36-arm64
88
- pyca-cryptography-centos-8-py36-arm64
9-
- pyca-cryptography-centos-8-py27-arm64
109
release:
1110
jobs:
1211
- pyca-cryptography-build-wheel-arm64

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Changelog
66

77
.. note:: This version is not yet released and is under active development.
88

9+
* **BACKWARDS INCOMPATIBLE:** Support for Python 2 has been removed.
10+
911
.. _v3-3:
1012

1113
3.3 - 2020-12-08

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pyca/cryptography
1818

1919
``cryptography`` is a package which provides cryptographic recipes and
2020
primitives to Python developers. Our goal is for it to be your "cryptographic
21-
standard library". It supports Python 2.7, Python 3.6+, and PyPy 5.4+.
21+
standard library". It supports Python 3.6+ and PyPy3 7.2+.
2222

2323
``cryptography`` includes both high level recipes and low level interfaces to
2424
common cryptographic algorithms such as symmetric ciphers, message digests, and

docs/development/getting-started.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ each supported Python version and run the tests. For example:
7979
8080
$ tox
8181
...
82-
py27: commands succeeded
8382
ERROR: pypy: InterpreterNotFound: pypy
8483
py38: commands succeeded
8584
docs: commands succeeded

docs/installation.rst

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ You can install ``cryptography`` with ``pip``:
1010
Supported platforms
1111
-------------------
1212

13-
Currently we test ``cryptography`` on Python 2.7, 3.6+,
14-
PyPy 7.3.1, and PyPy3 7.3.1 on these operating systems.
13+
Currently we test ``cryptography`` on Python 3.6+ and PyPy3 7.3.1 on these
14+
operating systems.
1515

16-
* x86-64 CentOS 7.x
1716
* x86-64 & AArch64 CentOS 8.x
1817
* x86-64 Fedora (latest)
1918
* x86-64 macOS 10.15 Catalina
@@ -45,9 +44,9 @@ just run
4544
If you prefer to compile it yourself you'll need to have OpenSSL installed.
4645
You can compile OpenSSL yourself as well or use `a binary distribution`_.
4746
Be sure to download the proper version for your architecture and Python
48-
(VC2010 works for Python 2.7 while VC2015 is required for 3.6 and above).
49-
Wherever you place your copy of OpenSSL you'll need to set the ``LIB`` and ``INCLUDE``
50-
environment variables to include the proper locations. For example:
47+
(VC2015 is required for 3.6 and above). Wherever you place your copy of OpenSSL
48+
you'll need to set the ``LIB`` and ``INCLUDE`` environment variables to include
49+
the proper locations. For example:
5150

5251
.. code-block:: console
5352
@@ -87,8 +86,6 @@ available on your system.
8786
Alpine
8887
~~~~~~
8988

90-
Replace ``python3-dev`` with ``python-dev`` if you're using Python 2.
91-
9289
.. code-block:: console
9390
9491
$ sudo apk add gcc musl-dev python3-dev libffi-dev openssl-dev
@@ -98,8 +95,6 @@ If you get an error with ``openssl-dev`` you may have to use ``libressl-dev``.
9895
Debian/Ubuntu
9996
~~~~~~~~~~~~~
10097

101-
Replace ``python3-dev`` with ``python-dev`` if you're using Python 2.
102-
10398
.. code-block:: console
10499
105100
$ sudo apt-get install build-essential libssl-dev libffi-dev python3-dev

setup.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@
6363
"Operating System :: POSIX :: Linux",
6464
"Operating System :: Microsoft :: Windows",
6565
"Programming Language :: Python",
66-
"Programming Language :: Python :: 2",
67-
"Programming Language :: Python :: 2.7",
6866
"Programming Language :: Python :: 3",
67+
"Programming Language :: Python :: 3 :: Only",
6968
"Programming Language :: Python :: 3.6",
7069
"Programming Language :: Python :: 3.7",
7170
"Programming Language :: Python :: 3.8",
@@ -79,13 +78,10 @@
7978
where="src", exclude=["_cffi_src", "_cffi_src.*"]
8079
),
8180
include_package_data=True,
82-
python_requires=(
83-
">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*"
84-
),
81+
python_requires=">=3.6",
8582
install_requires=["six >= 1.4.1"] + setup_requirements,
8683
setup_requires=setup_requirements,
8784
extras_require={
88-
":python_version < '3'": ["enum34", "ipaddress"],
8985
"test": [
9086
"pytest>=3.6.0,!=3.9.0,!=3.9.1,!=3.9.2",
9187
"pretend",

src/cryptography/__init__.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
from __future__ import absolute_import, division, print_function
66

7-
import sys
8-
import warnings
9-
107
from cryptography.__about__ import (
118
__author__,
129
__copyright__,
@@ -17,7 +14,6 @@
1714
__uri__,
1815
__version__,
1916
)
20-
from cryptography.utils import CryptographyDeprecationWarning
2117

2218

2319
__all__ = [
@@ -30,12 +26,3 @@
3026
"__license__",
3127
"__copyright__",
3228
]
33-
34-
if sys.version_info[0] == 2:
35-
warnings.warn(
36-
"Python 2 is no longer supported by the Python core team. Support for "
37-
"it is now deprecated in cryptography, and will be removed in the "
38-
"next release.",
39-
CryptographyDeprecationWarning,
40-
stacklevel=2,
41-
)

src/cryptography/hazmat/backends/openssl/backend.py

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import warnings
1111
from contextlib import contextmanager
1212

13-
import six
1413
from six.moves import range
1514

1615
from cryptography import utils, x509
@@ -521,24 +520,15 @@ def _consume_errors_with_text(self):
521520
def _bn_to_int(self, bn):
522521
assert bn != self._ffi.NULL
523522

524-
if not six.PY2:
525-
# Python 3 has constant time from_bytes, so use that.
526-
bn_num_bytes = self._lib.BN_num_bytes(bn)
527-
bin_ptr = self._ffi.new("unsigned char[]", bn_num_bytes)
528-
bin_len = self._lib.BN_bn2bin(bn, bin_ptr)
529-
# A zero length means the BN has value 0
530-
self.openssl_assert(bin_len >= 0)
531-
val = int.from_bytes(self._ffi.buffer(bin_ptr)[:bin_len], "big")
532-
if self._lib.BN_is_negative(bn):
533-
val = -val
534-
return val
535-
else:
536-
# Under Python 2 the best we can do is hex()
537-
hex_cdata = self._lib.BN_bn2hex(bn)
538-
self.openssl_assert(hex_cdata != self._ffi.NULL)
539-
hex_str = self._ffi.string(hex_cdata)
540-
self._lib.OPENSSL_free(hex_cdata)
541-
return int(hex_str, 16)
523+
bn_num_bytes = self._lib.BN_num_bytes(bn)
524+
bin_ptr = self._ffi.new("unsigned char[]", bn_num_bytes)
525+
bin_len = self._lib.BN_bn2bin(bn, bin_ptr)
526+
# A zero length means the BN has value 0
527+
self.openssl_assert(bin_len >= 0)
528+
val = int.from_bytes(self._ffi.buffer(bin_ptr)[:bin_len], "big")
529+
if self._lib.BN_is_negative(bn):
530+
val = -val
531+
return val
542532

543533
def _int_to_bn(self, num, bn=None):
544534
"""
@@ -552,24 +542,10 @@ def _int_to_bn(self, num, bn=None):
552542
if bn is None:
553543
bn = self._ffi.NULL
554544

555-
if not six.PY2:
556-
# Python 3 has constant time to_bytes, so use that.
557-
558-
binary = num.to_bytes(int(num.bit_length() / 8.0 + 1), "big")
559-
bn_ptr = self._lib.BN_bin2bn(binary, len(binary), bn)
560-
self.openssl_assert(bn_ptr != self._ffi.NULL)
561-
return bn_ptr
562-
563-
else:
564-
# Under Python 2 the best we can do is hex(), [2:] removes the 0x
565-
# prefix.
566-
hex_num = hex(num).rstrip("L")[2:].encode("ascii")
567-
bn_ptr = self._ffi.new("BIGNUM **")
568-
bn_ptr[0] = bn
569-
res = self._lib.BN_hex2bn(bn_ptr, hex_num)
570-
self.openssl_assert(res != 0)
571-
self.openssl_assert(bn_ptr[0] != self._ffi.NULL)
572-
return bn_ptr[0]
545+
binary = num.to_bytes(int(num.bit_length() / 8.0 + 1), "big")
546+
bn_ptr = self._lib.BN_bin2bn(binary, len(binary), bn)
547+
self.openssl_assert(bn_ptr != self._ffi.NULL)
548+
return bn_ptr
573549

574550
def generate_rsa_private_key(self, public_exponent, key_size):
575551
rsa._verify_rsa_parameters(public_exponent, key_size)

src/cryptography/hazmat/primitives/asymmetric/rsa.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@
55
from __future__ import absolute_import, division, print_function
66

77
import abc
8-
9-
try:
10-
# Only available in math in 3.5+
11-
from math import gcd
12-
except ImportError:
13-
from fractions import gcd
8+
from math import gcd
149

1510
import six
1611

0 commit comments

Comments
 (0)