From e3f234b78baf2f0a4931cfb82389f4a065118d10 Mon Sep 17 00:00:00 2001 From: olii Date: Thu, 4 Mar 2021 01:41:59 +0100 Subject: [PATCH 1/2] Add compatibility for Python 3.9. --- .travis.yml | 1 + setup.py | 3 ++- tox.ini | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 98fb79dd..bfc00450 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ python: - 3.6 - 3.7 - 3.8 + - 3.9 before_install: pip install --upgrade setuptools install: pip install tox tox-travis coveralls before_script: if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then tox -e flake8; fi diff --git a/setup.py b/setup.py index f84c1209..a17ed72f 100755 --- a/setup.py +++ b/setup.py @@ -46,7 +46,8 @@ def run_tests(self): 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8' + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', ], packages=[ 'pyhocon', diff --git a/tox.ini b/tox.ini index c5b2e28c..b91501d2 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = flake8, py{27,34,35,36,37,38} +envlist = flake8, py{27,34,35,36,37,38,39} [testenv] passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH From 5cff474572078edb84446bc5d6204b1d9dae8578 Mon Sep 17 00:00:00 2001 From: olii Date: Thu, 4 Mar 2021 01:45:30 +0100 Subject: [PATCH 2/2] Fix deprecation warning with newer Pythons and 'imp' library. This warning is shown: ``` /opt/appuser/.local/lib/python3.9/site-packages/pyhocon/config_parser.py:4: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses import imp -- Docs: https://docs.pytest.org/en/stable/warnings.html ``` `imp.find_module()` (https://docs.python.org/3/library/imp.html#imp.find_module) was deprecated since version 3.3. However Pyhocon has no support for Python 3.3. We can use the alternative function `importlib.util.find_spec()` (https://docs.python.org/3/library/importlib.html#importlib.util.find_spec) which was added in Python 3.4 as advised in the docs. See:https://github.com/chimpler/pyhocon/issues/248 --- pyhocon/config_parser.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/pyhocon/config_parser.py b/pyhocon/config_parser.py index 9241de87..6811cc4b 100644 --- a/pyhocon/config_parser.py +++ b/pyhocon/config_parser.py @@ -1,7 +1,6 @@ import codecs import contextlib import copy -import imp import itertools import logging import os @@ -63,6 +62,27 @@ def glob(pathname, recursive=False): else: from glob import glob + +# Fix deprecated warning with 'imp' library and Python 3.4+. +# See: https://github.com/chimpler/pyhocon/issues/248 +if sys.version_info >= (3, 4): + import importlib.util + + def find_package_dir(name): + spec = importlib.util.find_spec(name) + # When `imp.find_module()` cannot find a package it raises ImportError. + # Here we should simulate it to keep the compatibility with older + # versions. + if not spec: + raise ImportError('No module named {!r}'.format(name)) + return os.path.dirname(spec.origin) +else: + import imp + + def find_package_dir(name): + return imp.find_module(name)[1] + + logger = logging.getLogger(__name__) # @@ -727,7 +747,7 @@ def resolve_package_path(cls, package_path): if ':' not in package_path: raise ValueError("Expected format is 'PACKAGE:PATH'") package_name, path_relative = package_path.split(':', 1) - package_dir = imp.find_module(package_name)[1] + package_dir = find_package_dir(package_name) path_abs = os.path.join(package_dir, path_relative) return path_abs