Page MenuHomePhabricator

Show clearer error on non-recursive clone
Closed, ResolvedPublic

Description

If someone uses 'git clone https://..../pywikibot-core' or -compat, instead of 'git clone --recursive', the bot doesn't work, due to httplib2 missing (-core) and i18n missing (core and compat). However, the errors are less than clear:

Core

Traceback (most recent call last):

File "C:\rewrite\pwb.py", line 123, in <module>
  tryimport_pwb()
File "C:\rewrite\pwb.py", line 30, in tryimport_pwb
  import pywikibot
File "C:\rewrite\pywikibot\__init__.py", line 412, in <module>
  from .page import Page, ImagePage, Category, Link, User, ItemPage, PropertyP

age, Claim

File "C:\rewrite\pywikibot\page.py", line 17, in <module>
  import pywikibot.site
File "C:\rewrite\pywikibot\site.py", line 32, in <module>
  from pywikibot import pagegenerators
File "C:\rewrite\pywikibot\pagegenerators.py", line 31, in <module>
  from pywikibot.comms import http
File "C:\rewrite\pywikibot\comms\http.py", line 35, in <module>
  import queue as Queue

ImportError: No module named queue

Compat

Traceback (most recent call last):

File "replace.py", line 970, in <module>
  main()
File "replace.py", line 636, in main
  {'description': u''})
File "/home/valhallasw/src/pwb/compat-svn/trunk/pywikibot/i18n.py", line 336, in twtranslate
  transdict = getattr(__import__("i18n", {}, {}, [package]), package).msg

ImportError: No module named i18n

In both cases, we should check for the existance of the externals, and respond with a clear error message otherwise.


Version: core-(2.0)
Severity: normal

Details

Reference
bz59970

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 2:40 AM
bzimport set Reference to bz59970.
bzimport added a subscriber: Unknown Object (????).

Actually the problem seems to be the missing queue module.

In pywikibot\comms\http.py there is a try ... except ... to handle a missing hhtplib2, unless this is not updated any longer.

try:
    from httplib2 import SSLHandshakeError
    import Queue  -> this looks to be preferred!!
    import urlparse
    import cookielib
except ImportError:
    from ssl import SSLError as SSLHandshakeError
    import queue as Queue
    import urllib as urlparse
    from http import cookiejar as cookielib

Speaking about queue ... in different parts of pywikibot, there is a preference for "Queue" over "queue" and viceversa.

In pywikibot\__init__.py there is:

try:
    from queue import Queue -> this looks to be preferred!!
except ImportError:
    from Queue import Queue

Sounds strange to me.

Both are python 2 (Queue)/ python 3 (queue) import blocks. However, the issue is *not* queue, even though the error sounds like that.

What happens is:

try:
   from httplib2 import SSLHandshakeError <-- fails
   import Queue
   import urlparse
   import cookielib
except ImportError: <- this is meant for people who run python 3
   from ssl import SSLError as SSLHandshakeError <-- this also works on py2
   import queue as Queue <-- but this doesn't!

I think we should probably change those blocks to explicit blocks, i.e.

if sys.version_info[0] == 2:
   from httplib2 import SSLHandshakeError
else:
   ...

However, that would just change the error to

Traceback (most recent call last):

File "C:\rewrite\pwb.py", line 123, in <module>
  tryimport_pwb()
File "C:\rewrite\pwb.py", line 30, in tryimport_pwb
  import pywikibot
File "C:\rewrite\pywikibot\__init__.py", line 412, in <module>
  from .page import Page, ImagePage, Category, Link, User, ItemPage,

PropertyPage, Claim

File "C:\rewrite\pywikibot\page.py", line 17, in <module>
  import pywikibot.site
File "C:\rewrite\pywikibot\site.py", line 32, in <module>
  from pywikibot import pagegenerators
File "C:\rewrite\pywikibot\pagegenerators.py", line 31, in <module>
  from pywikibot.comms import http
File "C:\rewrite\pywikibot\comms\http.py", line 35, in <module>
  from httplib2 import SSLHandshakeError

ImportError: No module named httplib2

which still needs the 'You probably forgot the submodules' clarification

Clearer now, thanks. I was missing the Python 3 ... next year may be ... :-)

Change 112334 had a related patch set uploaded by Merlijn van Deen:
(bug 59970) Python 3 import blocks are now explicit

https://gerrit.wikimedia.org/r/112334

Change 112334 merged by jenkins-bot:
(bug 59970) Python 3 import blocks are now explicit

https://gerrit.wikimedia.org/r/112334

Change 112336 had a related patch set uploaded by Merlijn van Deen:
(bug 59970) show clear error message if httplib2 is not found

https://gerrit.wikimedia.org/r/112336

Change 112336 merged by jenkins-bot:
(bug 59970) show clear error message if httplib2 is not found

https://gerrit.wikimedia.org/r/112336