Skip to content

Commit b7f883e

Browse files
committed
Remove Python2 from CI and code that branched on it
1 parent d634731 commit b7f883e

File tree

19 files changed

+184
-492
lines changed

19 files changed

+184
-492
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: 2 additions & 17 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,10 +57,6 @@ 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'
6561
ABI_VERSION: '3.6'
6662
DOWNLOAD_URL: 'https://www.python.org/ftp/python/3.8.2/python-3.8.2-macosx10.9.pkg'
@@ -114,8 +110,7 @@ jobs:
114110
- {ARCH: 'x86', WINDOWS: 'win32'}
115111
- {ARCH: 'x64', WINDOWS: 'win64'}
116112
PYTHON:
117-
- {VERSION: "2.7", MSVC_VERSION: "2010"}
118-
- {VERSION: "3.8", MSVC_VERSION: "2019", "USE_ABI3": "true", "ABI_VERSION": "cp36"}
113+
- {VERSION: "3.8", MSVC_VERSION: "2019", "ABI_VERSION": "cp36"}
119114
name: "${{ matrix.PYTHON.VERSION }} ${{ matrix.WINDOWS.WINDOWS }} ${{ matrix.PYTHON.ABI_VERSION }}"
120115
steps:
121116
- uses: actions/checkout@v2
@@ -124,13 +119,6 @@ jobs:
124119
with:
125120
python-version: ${{ matrix.PYTHON.VERSION }}
126121
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'
134122
- run: pip install requests
135123
- name: Download OpenSSL
136124
run: |
@@ -144,10 +132,7 @@ jobs:
144132
- run: python -m pip install -U pip wheel cffi six ipaddress "enum34; python_version < '3'"
145133
- run: pip download cryptography==${{ github.event.inputs.version }} --no-deps --no-binary cryptography && tar zxvf cryptography*.tar.gz && mkdir wheelhouse
146134
shell: bash
147-
- run: cd cryptography* && python setup.py bdist_wheel && mv dist/cryptography*.whl ../wheelhouse
148-
if: matrix.PYTHON.USE_ABI3 != 'true'
149135
- 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'
151136
- run: pip install -f wheelhouse --no-index cryptography
152137
- name: Print the OpenSSL we built and linked against
153138
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 5.4+.
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/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: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@
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",
6967
"Programming Language :: Python :: 3.6",
7068
"Programming Language :: Python :: 3.7",
@@ -79,13 +77,10 @@
7977
where="src", exclude=["_cffi_src", "_cffi_src.*"]
8078
),
8179
include_package_data=True,
82-
python_requires=(
83-
">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*"
84-
),
80+
python_requires=">=3.6",
8581
install_requires=["six >= 1.4.1"] + setup_requirements,
8682
setup_requires=setup_requirements,
8783
extras_require={
88-
":python_version < '3'": ["enum34", "ipaddress"],
8984
"test": [
9085
"pytest>=3.6.0,!=3.9.0,!=3.9.1,!=3.9.2",
9186
"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

src/cryptography/hazmat/primitives/padding.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ def _byte_padding_update(buffer_, data, block_size):
4242

4343
utils._check_byteslike("data", data)
4444

45-
# six.PY2: Only coerce non-bytes objects to avoid triggering bad behavior
46-
# of future's newbytes type. Unconditionally call bytes() after Python 2
47-
# support is gone.
48-
buffer_ += data if isinstance(data, bytes) else bytes(data)
45+
buffer_ += bytes(data)
4946

5047
finished_blocks = len(buffer_) // (block_size // 8)
5148

@@ -69,10 +66,7 @@ def _byte_unpadding_update(buffer_, data, block_size):
6966

7067
utils._check_byteslike("data", data)
7168

72-
# six.PY2: Only coerce non-bytes objects to avoid triggering bad behavior
73-
# of future's newbytes type. Unconditionally call bytes() after Python 2
74-
# support is gone.
75-
buffer_ += data if isinstance(data, bytes) else bytes(data)
69+
buffer_ += bytes(data)
7670

7771
finished_blocks = max(len(buffer_) // (block_size // 8) - 1, 0)
7872

src/cryptography/hazmat/primitives/serialization/ssh.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import re
1010
import struct
11+
from base64 import encodebytes as _base64_encode
1112

1213
import six
1314

@@ -34,11 +35,6 @@ def _bcrypt_kdf(*args, **kwargs):
3435
raise UnsupportedAlgorithm("Need bcrypt module")
3536

3637

37-
try:
38-
from base64 import encodebytes as _base64_encode
39-
except ImportError:
40-
from base64 import encodestring as _base64_encode
41-
4238
_SSH_ED25519 = b"ssh-ed25519"
4339
_SSH_RSA = b"ssh-rsa"
4440
_SSH_DSA = b"ssh-dss"

0 commit comments

Comments
 (0)