ssato / python-anyconfig

Python library provides common APIs to load and dump configuration files in various formats
MIT License
278 stars 31 forks source link

Fix "error: unbalanced parenthesis at position 15" #133

Closed jamesmyatt closed 3 years ago

jamesmyatt commented 3 years ago

When I do import anyconfig using v0.11.1 and Python 3.9.7 on Windows, I get the following. I think this PR fixes it.

Although, TBH, I don't think it's a good idea to parse file names using regular expressions. You're better off with pathlib, in my experience. Regardless, there's an issue with split_path_by_marker that, if split_re needs to be updated based on marker and path_sep, i.e. they're not independent inputs.

``` ... \lib\site-packages\anyconfig\ioinfo\utils.py in 8 import typing 9 ---> 10 from .constants import ( 11 GLOB_MARKER, PATH_SEP, SPLIT_PATH_RE 12 ) \lib\site-packages\anyconfig\ioinfo\constants.py in 14 PATH_SEP: str = os.path.sep 15 ---> 16 SPLIT_PATH_RE: typing.Pattern = re.compile( 17 fr'([^{GLOB_MARKER}]+)' 18 fr'{PATH_SEP}' \lib\re.py in compile(pattern, flags) 250 def compile(pattern, flags=0): 251 "Compile a regular expression pattern, returning a Pattern object." --> 252 return _compile(pattern, flags) 253 254 def purge(): \lib\re.py in _compile(pattern, flags) 302 if not sre_compile.isstring(pattern): 303 raise TypeError("first argument must be string or compiled pattern") --> 304 p = sre_compile.compile(pattern, flags) 305 if not (flags & DEBUG): 306 if len(_cache) >= _MAXCACHE: \lib\sre_compile.py in compile(p, flags) 762 if isstring(p): 763 pattern = p --> 764 p = sre_parse.parse(p, flags) 765 else: 766 pattern = None \lib\sre_parse.py in parse(str, flags, state) 960 if source.next is not None: 961 assert source.next == ")" --> 962 raise source.error("unbalanced parenthesis") 963 964 if flags & SRE_FLAG_DEBUG: error: unbalanced parenthesis at position 15 ```
ssato commented 3 years ago

Thanks a lot for your report!

I don't think it's a good idea to parse file names using regular expressions. You're better off with pathlib, in my experience.

You're absolutely right. I've been migrating to use pathlib.Path recently and this is the one I have to fix in the same way.

I've just committed several changes (5b9bae8 and related ones) may resolve this issue together with adding windows test targets for running CI (5456fbc). Could you please test the latest one in the next branch if it' possible, or wait for the next release which I'm planning to release within a few days?

jamesmyatt commented 3 years ago

Thanks. I'll take a look when it's released. I'm not sure when expand_from_path is used but I think it can be simplified. I'll try to take another look some time.

jtszalay commented 3 years ago

I was also having this issue. I've installed from the branch next and the issue is resolved! @ssato

jamesmyatt commented 3 years ago

Seems fixed. Thanks