Skip to content

Commit

Permalink
compatibility with python 2.7
Browse files Browse the repository at this point in the history
srsly, python 2 is no fun. at all.
  • Loading branch information
klamann committed Oct 23, 2020
1 parent 4bd159e commit aaf8ba8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pyhocon/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ def resolve_substitutions(cls, config, accept_unresolved=False):
return has_unresolved

@classmethod
def resolve_package_path(cls, package_path: str) -> str:
def resolve_package_path(cls, package_path):
"""
Resolve the path to a file inside a Python package. Expected format: "PACKAGE:PATH"
Expand All @@ -726,7 +726,7 @@ def resolve_package_path(cls, package_path: str) -> str:
"""
if ':' not in package_path:
raise ValueError("Expected format is 'PACKAGE:PATH'")
package_name, path_relative = package_path.split(':', maxsplit=1)
package_name, path_relative = package_path.split(':', 1)
package_dir = imp.find_module(package_name)[1]
path_abs = os.path.join(package_dir, path_relative)
return path_abs
Expand Down
7 changes: 5 additions & 2 deletions tests/test_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import os
import shutil
import tempfile
from collections import OrderedDict
from datetime import timedelta
Expand Down Expand Up @@ -1279,8 +1280,8 @@ def test_resolve_package_path_missing(self):
ConfigParser.resolve_package_path("non_existent_module:foo.py")

def test_include_package_file(self, monkeypatch):
with tempfile.TemporaryDirectory() as temp_dir:
# define paths
temp_dir = tempfile.mkdtemp()
try:
module_dir = os.path.join(temp_dir, 'my_module')
module_conf = os.path.join(module_dir, 'my.conf')
# create the module folder and necessary files (__init__ and config)
Expand All @@ -1300,6 +1301,8 @@ def test_include_package_file(self, monkeypatch):
)
# check that the contents of both config files are available
assert dict(config.as_plain_ordered_dict()) == {'a': 1, 'b': 2, 'c': 3}
finally:
shutil.rmtree(temp_dir, ignore_errors=True)

def test_include_dict(self):
expected_res = {
Expand Down

0 comments on commit aaf8ba8

Please sign in to comment.