Skip to content

Commit

Permalink
Merge pull request #131 from jdufresne/drop-old-py
Browse files Browse the repository at this point in the history
Remove support for end-of-life Pythons
  • Loading branch information
takluyver authored Nov 27, 2021
2 parents 54ab882 + 3a8e996 commit a942316
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 198 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10"]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
Expand Down
5 changes: 1 addition & 4 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
pytest
pytest-flake8
flake8 < 4 # https://github.com/tholo/pytest-flake8/issues/81
pytest-forward-compatibility; python_version<'3'
mock ; python_version<'3.6'
testpath
toml ; python_version<'3.6'
tomli ; python_version>='3.6'
tomli
setuptools>=30
importlib_metadata ; python_version<'3.8'
zipp ; python_version<'3.8'
6 changes: 6 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

UNRELEASED
----------

- Remove support for end-of-life Pythons. Now requires Python3.6+.
- Remove support for ``toml`` package. Now requires ``tomli``.

0.12
----

Expand Down
3 changes: 1 addition & 2 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
toml ; python_version<'3.6'
tomli ; python_version>='3.6'
tomli
14 changes: 7 additions & 7 deletions pep517/build.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Build a project using PEP 517 hooks.
"""
import argparse
import io
import logging
import os
import shutil
import tempfile

import tomli

from .compat import FileNotFoundError, toml_load
from .dirtools import mkdir_p, tempdir
from .envbuild import BuildEnvironment
from .wrappers import Pep517HookCaller

Expand All @@ -31,8 +31,8 @@ def load_system(source_dir):
Load the build system from a source dir (pyproject.toml).
"""
pyproject = os.path.join(source_dir, 'pyproject.toml')
with io.open(pyproject, 'rb') as f:
pyproject_data = toml_load(f)
with open(pyproject, 'rb') as f:
pyproject_data = tomli.load(f)
return pyproject_data['build-system']


Expand Down Expand Up @@ -64,7 +64,7 @@ def _do_build(hooks, env, dist, dest):
env.pip_install(reqs)
log.info('Installed dynamic build dependencies')

with tempdir() as td:
with tempfile.TemporaryDirectory() as td:
log.info('Trying to build %s in %s', dist, td)
build_name = 'build_{dist}'.format(**locals())
build = getattr(hooks, build_name)
Expand All @@ -76,7 +76,7 @@ def _do_build(hooks, env, dist, dest):
def build(source_dir, dist, dest=None, system=None):
system = system or load_system(source_dir)
dest = os.path.join(source_dir, dest or 'dist')
mkdir_p(dest)
os.makedirs(dest, exist_ok=True)

validate_system(system)
hooks = Pep517HookCaller(
Expand Down
10 changes: 5 additions & 5 deletions pep517/check.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Check a project and backend by attempting to build using PEP 517 hooks.
"""
import argparse
import io
import logging
import os
import shutil
Expand All @@ -13,8 +12,9 @@
from subprocess import CalledProcessError
from tempfile import mkdtemp

import tomli

from .colorlog import enable_colourful_output
from .compat import TOMLDecodeError, toml_load
from .envbuild import BuildEnvironment
from .wrappers import Pep517HookCaller

Expand Down Expand Up @@ -143,15 +143,15 @@ def check(source_dir):
return False

try:
with io.open(pyproject, 'rb') as f:
pyproject_data = toml_load(f)
with open(pyproject, 'rb') as f:
pyproject_data = tomli.load(f)
# Ensure the mandatory data can be loaded
buildsys = pyproject_data['build-system']
requires = buildsys['requires']
backend = buildsys['build-backend']
backend_path = buildsys.get('backend-path')
log.info('Loaded pyproject.toml')
except (TOMLDecodeError, KeyError):
except (tomli.TOMLDecodeError, KeyError):
log.error("Invalid pyproject.toml", exc_info=True)
return False

Expand Down
2 changes: 0 additions & 2 deletions pep517/colorlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ def __init__(self, color=True, datefmt=None):
# right conversion in python 3.
fg_color = (curses.tigetstr("setaf") or
curses.tigetstr("setf") or "")
if (3, 0) < sys.version_info < (3, 2, 3):
fg_color = str(fg_color, "ascii")

for levelno, code in self.DEFAULT_COLORS.items():
self._colors[levelno] = str(
Expand Down
50 changes: 0 additions & 50 deletions pep517/compat.py

This file was deleted.

25 changes: 0 additions & 25 deletions pep517/dirtools.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
import contextlib
import errno
import io
import os
import shutil
import tempfile
import zipfile


@contextlib.contextmanager
def tempdir():
"""Create a temporary directory in a context manager."""
td = tempfile.mkdtemp()
try:
yield td
finally:
shutil.rmtree(td)


def mkdir_p(*args, **kwargs):
"""Like `mkdir`, but does not raise an exception if the
directory already exists.
"""
try:
return os.mkdir(*args, **kwargs)
except OSError as exc:
if exc.errno != errno.EEXIST:
raise


def dir_to_zipfile(root):
"""Construct an in-memory zip file for a directory."""
buffer = io.BytesIO()
Expand Down
10 changes: 5 additions & 5 deletions pep517/envbuild.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Build wheels/sdists by installing build deps to a temporary environment.
"""

import io
import logging
import os
import shutil
Expand All @@ -10,18 +9,19 @@
from sysconfig import get_paths
from tempfile import mkdtemp

from .compat import toml_load
import tomli

from .wrappers import LoggerWrapper, Pep517HookCaller

log = logging.getLogger(__name__)


def _load_pyproject(source_dir):
with io.open(
with open(
os.path.join(source_dir, 'pyproject.toml'),
'rb',
) as f:
pyproject_data = toml_load(f)
pyproject_data = tomli.load(f)
buildsys = pyproject_data['build-system']
return (
buildsys['requires'],
Expand All @@ -30,7 +30,7 @@ def _load_pyproject(source_dir):
)


class BuildEnvironment(object):
class BuildEnvironment:
"""Context manager to install build deps in a simple temporary environment
Based on code I wrote for pip, which is MIT licensed.
Expand Down
30 changes: 9 additions & 21 deletions pep517/in_process/_in_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,18 @@
from importlib import import_module
from os.path import join as pjoin

# This file is run as a script, and `import compat` is not zip-safe, so we
# include write_json() and read_json() from compat.py.
#
# Handle reading and writing JSON in UTF-8, on Python 3 and 2.
# This file is run as a script, and `import wrappers` is not zip-safe, so we
# include write_json() and read_json() from wrappers.py.

if sys.version_info[0] >= 3:
# Python 3
def write_json(obj, path, **kwargs):
with open(path, 'w', encoding='utf-8') as f:
json.dump(obj, f, **kwargs)

def read_json(path):
with open(path, 'r', encoding='utf-8') as f:
return json.load(f)
def write_json(obj, path, **kwargs):
with open(path, 'w', encoding='utf-8') as f:
json.dump(obj, f, **kwargs)

else:
# Python 2
def write_json(obj, path, **kwargs):
with open(path, 'wb') as f:
json.dump(obj, f, encoding='utf-8', **kwargs)

def read_json(path):
with open(path, 'rb') as f:
return json.load(f)
def read_json(path):
with open(path, encoding='utf-8') as f:
return json.load(f)


class BackendUnavailable(Exception):
Expand All @@ -64,7 +52,7 @@ def __init__(self, message):
class HookMissing(Exception):
"""Raised if a hook is missing and we are not executing the fallback"""
def __init__(self, hook_name=None):
super(HookMissing, self).__init__(hook_name)
super().__init__(hook_name)
self.hook_name = hook_name


Expand Down
9 changes: 5 additions & 4 deletions pep517/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import os
import shutil
import tempfile

try:
import importlib.metadata as imp_meta
Expand All @@ -17,7 +18,7 @@
from zipp import Path

from .build import compat_system, load_system, validate_system
from .dirtools import dir_to_zipfile, mkdir_p, tempdir
from .dirtools import dir_to_zipfile
from .envbuild import BuildEnvironment
from .wrappers import Pep517HookCaller, quiet_subprocess_runner

Expand All @@ -31,7 +32,7 @@ def _prep_meta(hooks, env, dest):
env.pip_install(reqs)
log.info('Installed dynamic build dependencies')

with tempdir() as td:
with tempfile.TemporaryDirectory() as td:
log.info('Trying to build metadata in %s', td)
filename = hooks.prepare_metadata_for_build_wheel(td, {})
source = os.path.join(td, filename)
Expand All @@ -41,7 +42,7 @@ def _prep_meta(hooks, env, dest):
def build(source_dir='.', dest=None, system=None):
system = system or load_system(source_dir)
dest = os.path.join(source_dir, dest or 'dist')
mkdir_p(dest)
os.makedirs(dest, exist_ok=True)
validate_system(system)
hooks = Pep517HookCaller(
source_dir, system['build-backend'], system.get('backend-path')
Expand All @@ -54,7 +55,7 @@ def build(source_dir='.', dest=None, system=None):


def build_as_zip(builder=build):
with tempdir() as out_dir:
with tempfile.TemporaryDirectory() as out_dir:
builder(dest=out_dir)
return dir_to_zipfile(out_dir)

Expand Down
Loading

0 comments on commit a942316

Please sign in to comment.