adang1345 / delvewheel

Self-contained Python wheels for Windows

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error parsing __init__.py

vtraag opened this issue · comments

Thanks @adang1345 for this library, it looks promising! I am trying to get it to work to build wheels for Windows for the python-igraph library, see the CI build here.

It seems that I am running into a problem with the parsing of __init__.py. For some reason, delvewheel throws

ValueError: Error parsing __init__.py: docstring exists but is not the first element of the parse tree

When trying to debug _patch_init, it seems that I am locally seeing that children[0] yields a ast.Str not a ast.Constant, which is currently being checked in

if len(children) == 0 or not isinstance(children[0], ast.Expr) or \
not isinstance(children[0].value, ast.Constant) or \
children[0].value.value != docstring:

I am not too experience with ast though, so I don't know exactly what is going wrong.

It seems that Python returns these things differently for different versions of Python. For Python 3.6 and 3.7, the first element (which is the docstring) is of the type ast.Str, while for Python 3.8 it is an ast.Constant.

Moreover, isinstance(ds, ast.Str) evaluates true on Python 3.6, 3.7 and 3.8, while isinstance(ds, ast.Constant) evaluates to true on 3.8 only.

Thanks for the analysis!

You're correct that for Python 3.8, the docstring is parsed as an ast.Constant, while for earlier Python versions, it is an ast.Str. I don't think that doing isinstance(children[0].value, ast.Str) is the best move, though, because ast.Str is deprecated as of Python 3.8. A better fix would be to use ast.Str for Python 3.7 and lower and to use ast.Constant for Python 3.8 and higher. I'll make this change shortly.

Release 0.0.12 fixes this issue.

Great, thanks for the quick response! If it is indeed deprecated, better to solve it some other way indeed.