Skip to content

Commit 593cdb2

Browse files
committed
Add compat module.
1 parent 35a0c90 commit 593cdb2

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

doc-source/api/compat.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
=================================
2+
:mod:`domdf_python_tools.compat`
3+
=================================
4+
5+
.. automodule:: domdf_python_tools.compat
6+
:no-members:

domdf_python_tools/compat.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# !/usr/bin/env python
2+
#
3+
# compat.py
4+
"""
5+
Cross-version compatibility helpers.
6+
7+
.. versionadded :: 0.12.0
8+
9+
Provides the following:
10+
11+
.. py:data:: importlib_resources
12+
13+
`importlib_resources <https://importlib-resources.readthedocs.io/en/latest/>`_ on Python 3.6;
14+
:mod:`importlib.resources` on Python 3.7 and later.
15+
"""
16+
#
17+
# Copyright © 2020 Dominic Davis-Foster <[email protected]>
18+
#
19+
# This program is free software; you can redistribute it and/or modify
20+
# it under the terms of the GNU Lesser General Public License as published by
21+
# the Free Software Foundation; either version 3 of the License, or
22+
# (at your option) any later version.
23+
#
24+
# This program is distributed in the hope that it will be useful,
25+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
26+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+
# GNU Lesser General Public License for more details.
28+
#
29+
# You should have received a copy of the GNU Lesser General Public License
30+
# along with this program; if not, write to the Free Software
31+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
32+
# MA 02110-1301, USA.
33+
#
34+
35+
# stdlib
36+
import sys
37+
38+
__all__ = ["importlib_resources"]
39+
40+
if sys.version_info < (3, 7):
41+
# 3rd party
42+
import importlib_resources
43+
else:
44+
# stdlib
45+
import importlib.resources as importlib_resources

domdf_python_tools/words.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@
4040
from string import ascii_lowercase, ascii_uppercase
4141
from typing import Any, Dict, Iterable, List, Optional
4242

43-
# 3rd party
44-
import importlib_resources
45-
4643
# this package
4744
import domdf_python_tools
45+
from domdf_python_tools.compat import importlib_resources
4846

4947
__all__ = [
5048
"greek_uppercase",

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
colorama>=0.4.3
22
deprecation>=2.1.0
3-
importlib_resources>=3.0.0
3+
importlib_resources>=3.0.0; python_version < "3.7"
44
pydash>=4.7.4
55
typing_extensions>=3.7.4.3

0 commit comments

Comments
 (0)