kvalle/diy-lang

Import statements -- qualify with diylisp?

kevinushey opened this issue · 5 comments

My initial attempt at running tests gave me the following error (following from the instructions):

kevinushey@Kevin-MBP:~/git/diy-lisp$ nosetests tests/test_1_parsing.py --stop

======================================================================
ERROR: Failure: ImportError (cannot import name 'is_boolean')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/site-packages/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/usr/local/lib/python3.4/site-packages/nose/loader.py", line 414, in loadTestsFromName
    addr.filename, addr.module)
  File "/usr/local/lib/python3.4/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/usr/local/lib/python3.4/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/usr/local/Cellar/python3/3.4.0_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imp.py", line 235, in load_module
    return load_source(name, filename, file)
  File "/usr/local/Cellar/python3/3.4.0_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imp.py", line 171, in load_source
    module = methods.load()
  File "<frozen importlib._bootstrap>", line 1220, in load
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1448, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/Users/kevinushey/git/diy-lisp/tests/test_1_parsing.py", line 5, in <module>
    from diylisp.parser import parse, unparse
  File "/Users/kevinushey/git/diy-lisp/diylisp/parser.py", line 4, in <module>
    from ast import is_boolean, is_list
ImportError: cannot import name 'is_boolean'

Should we be using from diylisp.ast import ... instead; ie, qualifying with the directory?

(My lack of proficiency with Python is probably showing here...)

My best guess is that your problem is somehow caused by the tests not working as expected with Python 3. I've used Python 2.7.3 all the while working on this. Could you check to see if that works any better?

Just had a chance to check. Indeed it seems this problem occurs when using Python 3. @kevinushey I suggest you use Python 2.7 instead. I'll add a note about that to the README as well.

Let me know if you have any other problems.

Gotcha -- thanks for investigating!

(Now through part 2 of the lessons; it's going quite smoothly. Thanks for putting this together!)

I'm having the same problem with Python 2.7.6.

@Nefron That's strange. I wouldn't expect 2.7.6 to handle imports any different from 2.7.3. Are you sure you're running the nosetests command from the project root directory? And could you post the output?