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

'include required(file(…))' is broken #187

Open
ElkMonster opened this issue Oct 25, 2018 · 2 comments
Open

'include required(file(…))' is broken #187

ElkMonster opened this issue Oct 25, 2018 · 2 comments

Comments

@ElkMonster
Copy link

While include required("file.conf") works as expected, include required(file("file.conf")) raises due to this line (265) in config_parser.py:

path = file if basedir is None else os.path.join(basedir, file)

If the filename to include is wrapped in file(…), the file variable is of type ConfigQuotedString instead of str, so os.path.join() fails.

>>> pyhocon.ConfigFactory.parse_string('include required(file("file.conf"))')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.7/site-packages/pyhocon/config_parser.py", line 130, in parse_string
    return ConfigParser().parse(content, basedir, resolve, unresolved_value)
  File "/usr/lib/python3.7/site-packages/pyhocon/config_parser.py", line 346, in parse
    config = config_expr.parseString(content, parseAll=True)[0]
  File "/usr/lib/python3.7/site-packages/pyparsing.py", line 1644, in parseString
    loc, tokens = self._parse( instring, 0 )
  File "/usr/lib/python3.7/site-packages/pyparsing.py", line 1402, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib/python3.7/site-packages/pyparsing.py", line 3446, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/usr/lib/python3.7/site-packages/pyparsing.py", line 1402, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib/python3.7/site-packages/pyparsing.py", line 3581, in parseImpl
    ret = e._parse( instring, loc, doActions )
  File "/usr/lib/python3.7/site-packages/pyparsing.py", line 1402, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib/python3.7/site-packages/pyparsing.py", line 3768, in parseImpl
    return self.expr._parse( instring, loc, doActions, callPreParse=False )
  File "/usr/lib/python3.7/site-packages/pyparsing.py", line 1402, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib/python3.7/site-packages/pyparsing.py", line 3970, in parseImpl
    return super(ZeroOrMore, self).parseImpl(instring, loc, doActions)
  File "/usr/lib/python3.7/site-packages/pyparsing.py", line 3899, in parseImpl
    loc, tokens = self_expr_parse( instring, loc, doActions, callPreParse=False )
  File "/usr/lib/python3.7/site-packages/pyparsing.py", line 1402, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/usr/lib/python3.7/site-packages/pyparsing.py", line 3581, in parseImpl
    ret = e._parse( instring, loc, doActions )
  File "/usr/lib/python3.7/site-packages/pyparsing.py", line 1428, in _parseNoCache
    tokens = fn( instring, tokensStart, retTokens )
  File "/usr/lib/python3.7/site-packages/pyparsing.py", line 1072, in wrapper
    ret = func(*args[limit[0]:])
  File "/usr/lib/python3.7/site-packages/pyhocon/config_parser.py", line 271, in include_config
    unresolved_value=NO_SUBSTITUTION
  File "/usr/lib/python3.7/site-packages/pyhocon/config_parser.py", line 77, in parse_file
    with codecs.open(filename, 'r', encoding=encoding) as fd:
  File "/usr/lib/python3.7/codecs.py", line 898, in open
    file = builtins.open(filename, mode, buffering)
TypeError: expected str, bytes or os.PathLike object, not ConfigQuotedString
@andreas-thomik
Copy link

Here's a mwe for the above:

test.conf:
{
"a" : "Hello",
"b" : "World"
}

test_include.conf:
{
include required(file("test.conf"))
"c" : ${a}" "${b}"!"
}

This fails because of line 317 in config_parser.py:
value = final_tokens[1].value if isinstance(token[1], ConfigQuotedString) else final_tokens[1]

I believe it should instead read
value = final_tokens[1].value if isinstance(final_tokens[1], ConfigQuotedString) else final_tokens[1]

@jrouly
Copy link
Contributor

jrouly commented May 26, 2020

Should be fixed by #229.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants