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

Add Python 3 support #20

Closed
wants to merge 3 commits into from
Closed

Add Python 3 support #20

wants to merge 3 commits into from

Conversation

myint
Copy link

@myint myint commented Feb 18, 2018

This resolves the following problems under Python 3 while maintaining Python 2.7 support.

Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/myint/tmp/cmake_format/cmake_format/__main__.py", line 245, in <module>
    sys.exit(main())
  File "/Users/myint/tmp/cmake_format/cmake_format/__main__.py", line 184, in main
    for key, value in configuration.Configuration().as_dict().iteritems():
AttributeError: 'dict' object has no attribute 'iteritems'
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/myint/tmp/cmake_format/cmake_format/__main__.py", line 245, in <module>
    sys.exit(main())
  File "/Users/myint/tmp/cmake_format/cmake_format/__main__.py", line 223, in main
    process_file(cfg, infile, outfile)
  File "/Users/myint/tmp/cmake_format/cmake_format/__main__.py", line 38, in process_file
    pretty_printer.print_node(fst)
  File "/Users/myint/tmp/cmake_format/cmake_format/formatter.py", line 594, in print_node
    self.print_block(node)
  File "/Users/myint/tmp/cmake_format/cmake_format/formatter.py", line 453, in print_block
    self.print_node(child)
  File "/Users/myint/tmp/cmake_format/cmake_format/formatter.py", line 600, in print_node
    self.print_statement(node)
  File "/Users/myint/tmp/cmake_format/cmake_format/formatter.py", line 573, in print_statement
    self.outfile.write(self.get_indent())
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tempfile.py", line 483, in func_wrapper
    return func(*args, **kwargs)
TypeError: a bytes-like object is required, not 'str'

Travis CI results for Python 2.7 and 3.6.

try:
import StringIO
except ImportError:
import io as StringIO
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: Looks like the io module exists in python 2.7 as well..

Copy link

@DanielChabrowski DanielChabrowski Feb 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But StringIO doesn't in 3.0+.

The StringIO and cStringIO modules are gone. Instead, import the io module and use io.StringIO or io.BytesIO for text and data respectively.

edit:
Or do you mean that you can import StringIO from io in python 2? Then dunno.

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

Successfully merging this pull request may close these issues.

None yet

3 participants