{"action":"created","issue":{"url":"https://api.github.com/repos/anthony-tuininga/cx_Freeze/issues/252","repository_url":"https://api.github.com/repos/anthony-tuininga/cx_Freeze","labels_url":"https://api.github.com/repos/anthony-tuininga/cx_Freeze/issues/252/labels{/name}","comments_url":"https://api.github.com/repos/anthony-tuininga/cx_Freeze/issues/252/comments","events_url":"https://api.github.com/repos/anthony-tuininga/cx_Freeze/issues/252/events","html_url":"https://github.com/anthony-tuininga/cx_Freeze/pull/252","id":213372422,"number":252,"title":"Fixes bug caused by changes in PEP 420","user":{"login":"mhaimes","id":1082331,"avatar_url":"https://avatars2.githubusercontent.com/u/1082331?v=3","gravatar_id":"","url":"https://api.github.com/users/mhaimes","html_url":"https://github.com/mhaimes","followers_url":"https://api.github.com/users/mhaimes/followers","following_url":"https://api.github.com/users/mhaimes/following{/other_user}","gists_url":"https://api.github.com/users/mhaimes/gists{/gist_id}","starred_url":"https://api.github.com/users/mhaimes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhaimes/subscriptions","organizations_url":"https://api.github.com/users/mhaimes/orgs","repos_url":"https://api.github.com/users/mhaimes/repos","events_url":"https://api.github.com/users/mhaimes/events{/privacy}","received_events_url":"https://api.github.com/users/mhaimes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-03-10T15:34:24Z","updated_at":"2017-03-13T20:47:53Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/anthony-tuininga/cx_Freeze/pulls/252","html_url":"https://github.com/anthony-tuininga/cx_Freeze/pull/252","diff_url":"https://github.com/anthony-tuininga/cx_Freeze/pull/252.diff","patch_url":"https://github.com/anthony-tuininga/cx_Freeze/pull/252.patch"},"body":"(https://www.python.org/dev/peps/pep-0420/)\r\n\r\nWhen including a package that doesn't exist in the 'includes' list of\r\nbuild options, the code that prints the error message describing the\r\nincorrect package causes an exception.\r\n\r\n```<module>.__path__``` is now a ```_NamespacePath``` object that does not support\r\n```getitem()```-style indexing. It does support iterable, so this change grabs\r\nthe first element like before.\r\n\r\nThis bug is extremely simple to reproduce, simply add a package to 'includes' that doesn't exist and run the cx_Freeze setup.py script. Here is an example traceback:\r\n\r\n```Traceback (most recent call last):\r\n  File \"setup.py\", line 42, in <module>\r\n    Executable(\"main.py\")\r\n  File \"C:\\Program Files\\Python36\\lib\\site-packages\\cx_Freeze\\dist.py\", line 349, in setup\r\n    distutils.core.setup(**attrs)\r\n  File \"C:\\Program Files\\Python36\\lib\\distutils\\core.py\", line 148, in setup\r\n    dist.run_commands()\r\n  File \"C:\\Program Files\\Python36\\lib\\distutils\\dist.py\", line 955, in run_commands\r\n    self.run_command(cmd)\r\n  File \"C:\\Program Files\\Python36\\lib\\distutils\\dist.py\", line 974, in run_command\r\n    cmd_obj.run()\r\n  File \"C:\\Program Files\\Python36\\lib\\distutils\\command\\build.py\", line 135, in run\r\n    self.run_command(cmd_name)\r\n  File \"C:\\Program Files\\Python36\\lib\\distutils\\cmd.py\", line 313, in run_command\r\n    self.distribution.run_command(command)\r\n  File \"C:\\Program Files\\Python36\\lib\\distutils\\dist.py\", line 974, in run_command\r\n    cmd_obj.run()\r\n  File \"C:\\Program Files\\Python36\\lib\\site-packages\\cx_Freeze\\dist.py\", line 219, in run\r\n    freezer.Freeze()\r\n  File \"C:\\Program Files\\Python36\\lib\\site-packages\\cx_Freeze\\freezer.py\", line 621, in Freeze\r\n    self.finder = self._GetModuleFinder()\r\n  File \"C:\\Program Files\\Python36\\lib\\site-packages\\cx_Freeze\\freezer.py\", line 335, in _GetModuleFinder\r\n    package = finder.IncludeModule(name, namespace = True)\r\n  File \"C:\\Program Files\\Python36\\lib\\site-packages\\cx_Freeze\\finder.py\", line 646, in IncludeModule\r\n    namespace = namespace)\r\n  File \"C:\\Program Files\\Python36\\lib\\site-packages\\cx_Freeze\\finder.py\", line 311, in _ImportModule\r\n    deferredImports, namespace = namespace)\r\n  File \"C:\\Program Files\\Python36\\lib\\site-packages\\cx_Freeze\\finder.py\", line 400, in _InternalImportModule\r\n    fp, path, info = self._FindModule(searchName, path, namespace)\r\n  File \"C:\\Program Files\\Python36\\lib\\site-packages\\cx_Freeze\\finder.py\", line 222, in _FindModule\r\n    return None, module.__path__[0], info\r\nTypeError: '_NamespacePath' object does not support indexing```"},"comment":{"url":"https://api.github.com/repos/anthony-tuininga/cx_Freeze/issues/comments/286238619","html_url":"https://github.com/anthony-tuininga/cx_Freeze/pull/252#issuecomment-286238619","issue_url":"https://api.github.com/repos/anthony-tuininga/cx_Freeze/issues/252","id":286238619,"user":{"login":"mhaimes","id":1082331,"avatar_url":"https://avatars2.githubusercontent.com/u/1082331?v=3","gravatar_id":"","url":"https://api.github.com/users/mhaimes","html_url":"https://github.com/mhaimes","followers_url":"https://api.github.com/users/mhaimes/followers","following_url":"https://api.github.com/users/mhaimes/following{/other_user}","gists_url":"https://api.github.com/users/mhaimes/gists{/gist_id}","starred_url":"https://api.github.com/users/mhaimes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhaimes/subscriptions","organizations_url":"https://api.github.com/users/mhaimes/orgs","repos_url":"https://api.github.com/users/mhaimes/repos","events_url":"https://api.github.com/users/mhaimes/events{/privacy}","received_events_url":"https://api.github.com/users/mhaimes/received_events","type":"User","site_admin":false},"created_at":"2017-03-13T20:47:53Z","updated_at":"2017-03-13T20:47:53Z","body":"Sorry! It was a long day of hacking and my description of the bug and the steps to reproduce it were completely wrong. The patch is valid, and it actually fixes a much more serious issue than just incorrect error reporting. The problem actually occurs when using the ```namespace_packages``` option. The way it falls through the error handling at line 221 of finder.py to realize that the import isn't a basic package but a namespace_package is actually broken, likely as of whenever PEP 420 went into mainstream python (I believe it was 3.3 but I could be really wrong there).\r\n\r\nSo, the steps to reproduce actually have nothing to do with an incorrect name under ```includes``` or ```packages```, but happen when you try to use ```namespace_packages```\r\n\r\nTry the following:\r\n1) Install zope the \"old way\" (into Lib/site-packages) (I got it automatically via pip install -U tornado but that really shouldn't matter)\r\n2) make a setup.py script like:\r\n```\r\nbuild_exe_options = {\r\n    \"namespace_packages\": [\r\n        \"zope\",\r\n    ],\r\n}\r\n```\r\n3) when you run setup.py build, instead of cx_Freeze gracefully handling the ImportError, switching to it's namespace_packages functionality and pulling in zope, instead it spits out\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"C:\\Program Files\\Python36\\lib\\site-packages\\cx_Freeze\\finder.py\", line 217, in _FindModule\r\n    return imp.find_module(name, path)\r\n  File \"C:\\Program Files\\Python36\\lib\\imp.py\", line 296, in find_module\r\n    raise ImportError(_ERR_MSG.format(name), name=name)\r\nImportError: No module named 'zope'\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"setup.py\", line 42, in <module>\r\n    Executable(\"server.py\")\r\n  File \"C:\\Program Files\\Python36\\lib\\site-packages\\cx_Freeze\\dist.py\", line 349, in setup\r\n    distutils.core.setup(**attrs)\r\n  File \"C:\\Program Files\\Python36\\lib\\distutils\\core.py\", line 148, in setup\r\n    dist.run_commands()\r\n  File \"C:\\Program Files\\Python36\\lib\\distutils\\dist.py\", line 955, in run_commands\r\n    self.run_command(cmd)\r\n  File \"C:\\Program Files\\Python36\\lib\\distutils\\dist.py\", line 974, in run_command\r\n    cmd_obj.run()\r\n  File \"C:\\Program Files\\Python36\\lib\\distutils\\command\\build.py\", line 135, in run\r\n    self.run_command(cmd_name)\r\n  File \"C:\\Program Files\\Python36\\lib\\distutils\\cmd.py\", line 313, in run_command\r\n    self.distribution.run_command(command)\r\n  File \"C:\\Program Files\\Python36\\lib\\distutils\\dist.py\", line 974, in run_command\r\n    cmd_obj.run()\r\n  File \"C:\\Program Files\\Python36\\lib\\site-packages\\cx_Freeze\\dist.py\", line 219, in run\r\n    freezer.Freeze()\r\n  File \"C:\\Program Files\\Python36\\lib\\site-packages\\cx_Freeze\\freezer.py\", line 621, in Freeze\r\n    self.finder = self._GetModuleFinder()\r\n  File \"C:\\Program Files\\Python36\\lib\\site-packages\\cx_Freeze\\freezer.py\", line 335, in _GetModuleFinder\r\n    package = finder.IncludeModule(name, namespace = True)\r\n  File \"C:\\Program Files\\Python36\\lib\\site-packages\\cx_Freeze\\finder.py\", line 647, in IncludeModule\r\n    namespace = namespace)\r\n  File \"C:\\Program Files\\Python36\\lib\\site-packages\\cx_Freeze\\finder.py\", line 312, in _ImportModule\r\n    deferredImports, namespace = namespace)\r\n  File \"C:\\Program Files\\Python36\\lib\\site-packages\\cx_Freeze\\finder.py\", line 401, in _InternalImportModule\r\n    fp, path, info = self._FindModule(searchName, path, namespace)\r\n  File \"C:\\Program Files\\Python36\\lib\\site-packages\\cx_Freeze\\finder.py\", line 223, in _FindModule\r\n    return None, module.__path__[0], info\r\nTypeError: '_NamespacePath' object does not support indexing\r\n```\r\n\r\nwhen you fix the line in question:\r\n---> line 221 change ```module.__path__[0]``` to ```next(p for p in module.__path__)```\r\ncx_Freeze can now grab the first path properly, handle the original ```ImportError```, and pull in zope with no complaints. \r\n\r\nMore importantly, the patch should also be backwards-compatible with when ```module.__path__``` was still a normal ```getitem```-able list. There are obviously a few ways to write this change, and if you like a different way of pulling-the-first-element-off-an-iterable, go ahead and use that instead. I just did my best to triple-check that I'm not confused, but that's always still a possibility!"}}
{"actor":{"display_login":"mhaimes"}}