Skip to content

Drop support for Python 2.7 #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
test:
strategy:
matrix:
python: [2.7, 3.6, 3.7, 3.8, 3.9]
python: [3.6, 3.7, 3.8, 3.9]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
1 change: 0 additions & 1 deletion coverage.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ omit =
.tox/*/lib/python*/site-packages/*
*/tests/*.py
*/testing/*.py
importlib_resources/_py${OMIT}.py
importlib_resources/__init__.py
importlib_resources/_compat.py
importlib_resources/abc.py
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
importlib_resources NEWS
==========================

v4.0.0
======

* #108: Drop support for Python 2.7. Now requires Python 3.6+.

v3.3.1
======

Expand Down
41 changes: 13 additions & 28 deletions importlib_resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
"""Read resources contained within a package."""

import sys

from ._common import (
as_file, files,
)

from importlib_resources._py3 import (
Package,
Resource,
contents,
is_resource,
open_binary,
open_text,
path,
read_binary,
read_text,
)
from importlib_resources.abc import ResourceReader

# For compatibility. Ref #88.
# Also requires hook-importlib_resources.py (Ref #101).
__import__('importlib_resources.trees')
Expand All @@ -25,29 +36,3 @@
'read_binary',
'read_text',
]


if sys.version_info >= (3,):
from importlib_resources._py3 import (
Package,
Resource,
contents,
is_resource,
open_binary,
open_text,
path,
read_binary,
read_text,
)
from importlib_resources.abc import ResourceReader
else:
from importlib_resources._py2 import (
contents,
is_resource,
open_binary,
open_text,
path,
read_binary,
read_text,
)
del __all__[:3]
9 changes: 3 additions & 6 deletions importlib_resources/_common.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from __future__ import absolute_import

import os
import tempfile
import contextlib
import types
import importlib
from pathlib import Path
from functools import singledispatch

from ._compat import (
Path, FileNotFoundError,
singledispatch, package_spec,
)
from ._compat import package_spec

if False: # TYPE_CHECKING
from typing import Union, Any, Optional
Expand Down
62 changes: 4 additions & 58 deletions importlib_resources/_compat.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,9 @@
from __future__ import absolute_import
import abc
import sys
from contextlib import suppress

# flake8: noqa

if sys.version_info > (3,5):
from pathlib import Path, PurePath
else:
from pathlib2 import Path, PurePath # type: ignore


if sys.version_info > (3,):
from contextlib import suppress
else:
from contextlib2 import suppress # type: ignore


try:
from functools import singledispatch
except ImportError:
from singledispatch import singledispatch # type: ignore


try:
from abc import ABC # type: ignore
except ImportError:
from abc import ABCMeta

class ABC(object): # type: ignore
__metaclass__ = ABCMeta


try:
FileNotFoundError = FileNotFoundError # type: ignore
except NameError:
FileNotFoundError = OSError # type: ignore


try:
NotADirectoryError = NotADirectoryError # type: ignore
except NameError:
NotADirectoryError = OSError # type: ignore


try:
from zipfile import Path as ZipPath # type: ignore
except ImportError:
Expand All @@ -58,15 +20,7 @@ def runtime_checkable(cls): # type: ignore
try:
from typing import Protocol # type: ignore
except ImportError:
Protocol = ABC # type: ignore


__metaclass__ = type


class PackageSpec:
def __init__(self, **kwargs):
vars(self).update(kwargs)
Protocol = abc.ABC # type: ignore


class TraversableResourcesAdapter:
Expand All @@ -88,7 +42,6 @@ def __init__(self, spec):

@property
def path(self):
# Python < 3
return self.spec.origin

def get_resource_reader(self, name):
Expand Down Expand Up @@ -129,11 +82,4 @@ def package_spec(package):
matching the interfaces this library relies upon
in later Python versions.
"""
spec = getattr(package, '__spec__', None) or \
PackageSpec(
origin=package.__file__,
loader=getattr(package, '__loader__', None),
name=package.__name__,
submodule_search_locations=getattr(package, '__path__', None),
)
return TraversableResourcesAdapter(spec)
return TraversableResourcesAdapter(package.__spec__)
107 changes: 0 additions & 107 deletions importlib_resources/_py2.py

This file was deleted.

6 changes: 2 additions & 4 deletions importlib_resources/abc.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from __future__ import absolute_import

import abc

from ._compat import ABC, FileNotFoundError, runtime_checkable, Protocol
from ._compat import runtime_checkable, Protocol

# Use mypy's comment syntax for Python 2 compatibility
try:
Expand All @@ -11,7 +9,7 @@
pass


class ResourceReader(ABC):
class ResourceReader(metaclass=abc.ABCMeta):
"""Abstract base class for loaders to provide resource reading support."""

@abc.abstractmethod
Expand Down
4 changes: 2 additions & 2 deletions importlib_resources/readers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os.path

from collections import OrderedDict
from pathlib import Path

from . import abc

from ._compat import Path, ZipPath
from ._compat import FileNotFoundError, NotADirectoryError
from ._compat import ZipPath


class FileReader(abc.TraversableResources):
Expand Down
23 changes: 6 additions & 17 deletions importlib_resources/tests/_compat.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
try:
from test.support import import_helper # type: ignore
except ImportError:
try:
# Python 3.9 and earlier
class import_helper: # type: ignore
from test.support import modules_setup, modules_cleanup
except ImportError:
from . import py27compat

class import_helper: # type: ignore
modules_setup = staticmethod(py27compat.modules_setup)
modules_cleanup = staticmethod(py27compat.modules_cleanup)
import os


try:
from os import fspath # type: ignore
from test.support import import_helper # type: ignore
except ImportError:
# Python 3.5
fspath = str # type: ignore
# Python 3.9 and earlier
class import_helper: # type: ignore
from test.support import modules_setup, modules_cleanup


try:
Expand All @@ -27,4 +16,4 @@ class import_helper: # type: ignore
from test.support import unlink as _unlink

def unlink(target):
return _unlink(fspath(target))
return _unlink(os.fspath(target))
23 changes: 0 additions & 23 deletions importlib_resources/tests/py27compat.py

This file was deleted.

1 change: 0 additions & 1 deletion importlib_resources/tests/test_open.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import importlib_resources as resources
from . import data01
from . import util
from .._compat import FileNotFoundError


class CommonBinaryTests(util.CommonTests, unittest.TestCase):
Expand Down
Loading