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

GetVersion failed in setup.py for python3. #336

Closed
gsmith-to opened this issue May 3, 2015 · 1 comment
Closed

GetVersion failed in setup.py for python3. #336

gsmith-to opened this issue May 3, 2015 · 1 comment

Comments

@gsmith-to
Copy link

GetVersion failed for me under python3, because it relies on the exec operation modifying the locals of GetVersion. According to python docs, code executed by exec(str) can read the function's locals but modifications to them may not work.
The fix is to create a namespace and to read the result from the namespace (which is a good idea whenever exec is used; but here we need to avoid python2's syntax 'exec expr in ns' in order to be python 3 compatible.)

As I understand it, python 2 normally 'compiles' functions so that the locals aren't in a dictionary, eliminating name lookups; supporting exec requires functions using exec to be compiled quite differently. I guess that was dropped in python3, and exec now fabricates a 'locals' dictionary, to support local access, but it can't propagate changes back (in particular, the exec function can't create locals which did not exist in the function at 'compile time').


I did a PR but I'm not going to sign a CLA for 4 lines of code. So instead here it is.

In GetVersion() change everything below the 'with' to something along the lines of


inifile = version_file.read()
if sys.version_info[0] >= 3:  # exec Can't reliably modify locals in python3
    nsp = {}
    exec(inifile, nsp, nsp)
    return nsp['__version__']
else:
    exec(inifile)
    return __version__
@haberman
Copy link
Member

I believe this was fixed in cd14108. Please re-open if you observe this issue with the latest code.

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

2 participants