Skip to content

Commit

Permalink
fixup! Drop Python 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed May 6, 2021
1 parent 96c0c1d commit 249b1cd
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 64 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ What does it do?
- Bundles shared library dependencies on Linux and macOS through [auditwheel](https://github.com/pypa/auditwheel) and [delocate](https://github.com/matthew-brett/delocate)
- Runs your library's tests against the wheel-installed version of your library

See the [cibuildwheel 1 documentation](https://cibuildwheel.readthedocs.io/en/1.x/) if you need to build unsupported versions of Python, such as Python 2.

Usage
-----

Expand Down
3 changes: 0 additions & 3 deletions cibuildwheel/resources/install_certifi.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
| stat.S_IXOTH
)

if sys.version_info[0] == 2:
FileNotFoundError = OSError


def main():
openssl_dir, openssl_cafile = os.path.split(ssl.get_default_verify_paths().openssl_cafile)
Expand Down
33 changes: 4 additions & 29 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ If your wheel didn't compile, check the list below for some debugging tips.

- MacOS: calling cibuildwheel from a python3 script and getting a `ModuleNotFoundError`? Due to a (fixed) [bug](https://bugs.python.org/issue22490) in CPython, you'll need to [unset the `__PYVENV_LAUNCHER__` variable](https://github.com/joerick/cibuildwheel/issues/133#issuecomment-478288597) before activating a venv.

### Classic versions of Python

See the [cibuildwheel verison 1 docs](https://cibuildwheel.readthedocs.io/en/1.x/) for information about building Python 2.7 wheels. There are lots of tricks and workaround there that are no longer required for Python 3 in cibuildwheel 2.

### Linux builds on Docker

Linux wheels are built in the [`manylinux` docker images](https://github.com/pypa/manylinux) to provide binary compatible wheels on Linux, according to [PEP 571](https://www.python.org/dev/peps/pep-0571/). Because of this, when building with `cibuildwheel` on Linux, a few things should be taken into account:
Expand Down Expand Up @@ -136,35 +140,6 @@ Here's an example GitHub Actions workflow with a job that builds for Apple Silic
{% include "../examples/github-apple-silicon.yml" %}
```

### Windows and Python 2.7

Building 2.7 extensions on Windows is difficult, because the VS 2008 compiler that was used for the original Python compilation was discontinued in 2018, and has since been removed from Microsoft's downloads. Most people choose to not build Windows 2.7 wheels, or to override the compiler to something more modern.

To override, you need to have a modern compiler toolchain activated, and set `DISTUTILS_USE_SDK=1` and `MSSdk=1`. For example, on GitHub Actions, you would add these steps:

```yaml
- name: Prepare compiler environment for Windows
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64

- name: Set Windows environment variables
if: runner.os == 'Windows'
shell: bash
run: |
echo "DISTUTILS_USE_SDK=1" >> $GITHUB_ENV
echo "MSSdk=1" >> $GITHUB_ENV
# invoke cibuildwheel...
```

cibuildwheel will not try to build 2.7 on Windows unless it detects that the above two variables are set. Note that changing to a more modern compiler will mean your wheel picks up a runtime dependency to a different [Visual C++ Redistributable][]. You also need to be [a bit careful][] in designing your extension; some major binding tools like pybind11 do this for you.

More on setting a custom Windows toolchain in our docs on modern C++ standards [here](cpp_standards.md#windows-and-python-27).

[Visual C++ Redistributable]: https://support.microsoft.com/en-us/topic/the-latest-supported-visual-c-downloads-2647da03-1eea-4433-9aff-95f26a218cc0
[a bit careful]: https://pybind11.readthedocs.io/en/stable/faq.html#working-with-ancient-visual-studio-2008-builds-on-windows

### Building packages with optional C extensions

Expand Down
2 changes: 2 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ The format is `python_tag-platform_tag`, with tags similar to those in [PEP 425]

For CPython, the minimally supported macOS version is 10.9; for PyPy 3.6/3.7, macOS 10.13 or higher is required.

See the [cibuildwheel 1 documentation](https://cibuildwheel.readthedocs.io/en/1.x/) for past end of life versions of Python, and PyPy2.7.

#### Examples

```yaml
Expand Down
8 changes: 3 additions & 5 deletions test/test_cpp_standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,9 @@ def test_cpp14(tmp_path):

cpp17_project = cpp_test_project.copy()

# Python and PyPy 2.7 headers use the `register` keyword, which is forbidden in
# the C++17 standard, so we need the -Wno-register or /wd5033 options
cpp17_project.template_context["extra_compile_args"] = (
["/std:c++17", "/wd5033"] if utils.platform == "windows" else ["-std=c++17", "-Wno-register"]
)
cpp17_project.template_context["extra_compile_args"] = [
"/std:c++17" if utils.platform == "windows" else "-std=c++17"
]
cpp17_project.template_context[
"spam_cpp_top_level_add"
] = r"""
Expand Down
8 changes: 2 additions & 6 deletions test/test_pep518.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
"""
# Will fail if PEP 518 does work
import requests
if sys.version_info < (3, 6, 0):
assert requests.__version__ == "2.22.0", "Requests found but wrong version ({0})".format(requests.__version__)
else:
assert requests.__version__ == "2.23.0", "Requests found but wrong version ({0})".format(requests.__version__)
assert requests.__version__ == "2.23.0", "Requests found but wrong version ({0})".format(requests.__version__)
# Just making sure environment is still set
import os
Expand All @@ -29,8 +26,7 @@
"setuptools >= 42",
"setuptools_scm[toml]>=4.1.2",
"wheel",
"requests==2.22.0; python_version<'3.6'",
"requests==2.23.0; python_version>='3.6'"
"requests==2.23.0"
]
build-backend = "setuptools.build_meta"
Expand Down
5 changes: 1 addition & 4 deletions test/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
r"""
import ssl
if sys.version_info[0] == 2:
from urllib2 import urlopen
else:
from urllib.request import urlopen
from urllib.request import urlopen
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
data = urlopen("https://www.nist.gov", context=context)
Expand Down
3 changes: 1 addition & 2 deletions test/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def test_virtualenv(self):
# sys.prefix is different from sys.base_prefix when running a virtualenv
# See https://docs.python.org/3/library/venv.html, which virtualenv seems
# to honor in recent releases
# Python 2 doesn't have sys.base_prefix by default
if not hasattr(sys, 'base_prefix') or sys.prefix == sys.base_prefix:
if sys.prefix == sys.base_prefix:
self.fail("Not running in a virtualenv")
self.assertTrue(path_contains(sys.prefix, sys.executable))
Expand Down
17 changes: 2 additions & 15 deletions test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

import os
import platform as pm
import shutil
import subprocess
import sys
from contextlib import contextmanager
from tempfile import mkdtemp
from tempfile import TemporaryDirectory

platform: str

Expand All @@ -26,17 +24,6 @@
raise Exception("Unsupported platform")


# Python 2 does not have a tempfile.TemporaryDirectory context manager
@contextmanager
def TemporaryDirectoryIfNone(path):
_path = path or mkdtemp()
try:
yield _path
finally:
if path is None:
shutil.rmtree(_path)


def cibuildwheel_get_build_identifiers(project_path, env=None):
"""
Returns the list of build identifiers that cibuildwheel will try to build
Expand Down Expand Up @@ -76,7 +63,7 @@ def cibuildwheel_run(project_path, package_dir=".", env=None, add_env=None, outp
if add_env is not None:
env.update(add_env)

with TemporaryDirectoryIfNone(output_dir) as _output_dir:
with TemporaryDirectory(output_dir) as _output_dir:
subprocess.run(
[
sys.executable,
Expand Down

0 comments on commit 249b1cd

Please sign in to comment.