Skip to content
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

Add support for Python 3.9 and fix deprecation warning #254

Merged
merged 2 commits into from
Jul 11, 2021
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 22 additions & 2 deletions pyhocon/config_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import codecs
import contextlib
import copy
import imp
import itertools
import logging
import os
Expand Down Expand Up @@ -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__)

#
Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand Down