awslabs / aws-shell

An integrated shell for working with the AWS CLI.
Apache License 2.0
7.17k stars 772 forks source link

Python 3 startup issues #13

Closed donnemartin closed 8 years ago

donnemartin commented 8 years ago

I'll be plugging the holes as they pop up, here are the first three I've encountered:

$ aws-shell
First run, creating autocomplete index...
Traceback (most recent call last):
  File "/Users/donnemartin/.virtualenvs/aws-shell3/bin/aws-shell", line 9, in <module>
    load_entry_point('aws-shell==0.0.1', 'console_scripts', 'aws-shell')()
  File "/Users/donnemartin/Dev/github/forks/aws-shell/awsshell/__init__.py", line 47, in main
    from awsshell.makeindex import write_index
  File "/Users/donnemartin/Dev/github/forks/aws-shell/awsshell/makeindex.py", line 17
    print "Couldn't import awscli: pip install awscli"
                                                     ^
SyntaxError: Missing parentheses in call to 'print'
$ aws-shell
First run, creating autocomplete index...
Traceback (most recent call last):
  File "/Users/donnemartin/.virtualenvs/aws-shell3/bin/aws-shell", line 9, in <module>
    load_entry_point('aws-shell==0.0.1', 'console_scripts', 'aws-shell')()
  File "/Users/donnemartin/Dev/github/forks/aws-shell/awsshell/__init__.py", line 47, in main
    from awsshell.makeindex import write_index
  File "/Users/donnemartin/Dev/github/forks/aws-shell/awsshell/makeindex.py", line 8, in <module>
    from cStringIO import StringIO
ImportError: No module named 'cStringIO'
$ aws-shell
First run, creating autocomplete index...
Traceback (most recent call last):
  File "/Users/donnemartin/.virtualenvs/aws-shell3/bin/aws-shell", line 9, in <module>
    load_entry_point('aws-shell==0.0.1', 'console_scripts', 'aws-shell')()
  File "/Users/donnemartin/Dev/github/forks/aws-shell/awsshell/__init__.py", line 48, in main
    write_index(index_file)
  File "/Users/donnemartin/Dev/github/forks/aws-shell/awsshell/makeindex.py", line 72, in write_index
    index_command(current, help_command)
  File "/Users/donnemartin/Dev/github/forks/aws-shell/awsshell/makeindex.py", line 47, in index_command
    metadata['minidoc'] = remove_html(arg_obj.documentation.split('\n')[0])
  File "/Users/donnemartin/Dev/github/forks/aws-shell/awsshell/utils.py", line 7, in remove_html
    s.feed(html)
  File "/Users/donnemartin/.pyenv/versions/3.4.3/lib/python3.4/html/parser.py", line 165, in feed
    self.goahead(0)
  File "/Users/donnemartin/.pyenv/versions/3.4.3/lib/python3.4/html/parser.py", line 198, in goahead
    if self.convert_charrefs and not self.cdata_elem:
AttributeError: 'DataOnly' object has no attribute 'convert_charrefs'
donnemartin commented 8 years ago

@jamesls this one seems to be a little more complex I haven't yet figured out the best place to make the fix. Do you mind taking a look?

First run, creating autocomplete index... First run, creating doc index, this will take a few minutes, but only needs to run once. Traceback (most recent call last): File "/Users/donnemartin/.virtualenvs/aws-shell3/bin/aws-shell", line 9, in load_entry_point('aws-shell==0.0.1', 'console_scripts', 'aws-shell')() File "/Users/donnemartin/Dev/github/forks/aws-shell-dev/awsshell/init.py", line 60, in main write_doc_index() File "/Users/donnemartin/Dev/github/forks/aws-shell-dev/awsshell/makeindex.py", line 88, in wrix _index_docs(db, help_command) File "/Users/donnemartin/Dev/github/forks/aws-shell-dev/awsshell/makeindex.py", line 98, in _ins text_docs = _render_docs_for_cmd(sub_help_command) File "/Users/donnemartin/Dev/github/forks/aws-shell-dev/awsshell/makeindex.py", line 107, in _rd helpcommand(None, None) File "/Users/donnemartin/.virtualenvs/aws-shell3/lib/python3.4/site-packages/awscli/help.py", l self.renderer.render(self.doc.getvalue()) File "/Users/donnemartin/Dev/github/forks/aws-shell-dev/awsshell/makeindex.py", line 127, in rer self._io.write(contents) TypeError: string argument expected, got 'bytes'

jamesls commented 8 years ago

Taking a look

jamesls commented 8 years ago

After fixing the above issue with bytes, I see another error with shelve. I think the main problem is that in py2 it adds the key to the db without modification, but in python 3 it always encodes the string. This is unfortunate because in py2, unicode strings do not work with shelve:

f[u'\u2713'] = 'asdfasfdasdf'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shelve.py", line 133, in __setitem__
    self.dict[key] = f.getvalue()
TypeError: gdbm mappings have string indices only

I think the fix is going to have to not use shelve, and use dbm directly.

I think long term I'd probably like to switch over to sqlite, which has better cross platform support.

donnemartin commented 8 years ago

Sounds good, thanks for looking into it and for the update!