FlyRanch / figurefirst

A layout-first approach to figure making
http://flyranch.github.io/figurefirst
MIT License
80 stars 15 forks source link

Feature Request: Python 3.x compatibility #20

Closed scollis closed 6 years ago

scollis commented 7 years ago

Love the idea, but as some one who is avoiding going back to 2.7 at all costs no 3.x is a non-starter.

I see prints are still being used as statements.

psilentp commented 7 years ago

Thanks @scollis , I've changed the print statements to functions. I don't have python3 running on my laptop at the moment so I haven't tested compatibility yet, but I don't think there should be any other problems.

scollis commented 7 years ago

OK.. Cool. I just started working on this here: https://github.com/scollis/figurefirst/tree/py3x/figurefirst

I did the same and ran into this issue:


In [1]: import numpy as np
   ...: import matplotlib.pyplot as plt
   ...: from figurefirst import FigureLayout
   ...: 
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-66233f663224> in <module>()
      1 import numpy as np
      2 import matplotlib.pyplot as plt
----> 3 from figurefirst import FigureLayout

/Users/scollis/anaconda/envs/houston/lib/python3.5/site-packages/figurefirst/__init__.py in <module>()
----> 1 import svg_to_axes
      2 reload(svg_to_axes)
      3 import mpl_functions
      4 from svg_to_axes import FigureLayout

ImportError: No module named 'svg_to_axes'
scollis commented 7 years ago

Also found an error here.. I am working on a PR:

In [3]: layout = FigureLayout('/Users/scollis/example_hello_world_layout.svg')

AttributeError Traceback (most recent call last)

in () ----> 1 layout = FigureLayout('/Users/scollis/example_hello_world_layout.svg') /Users/scollis/anaconda/envs/houston/lib/python3.5/site-packages/figurefirst/svg_to_axes.py in __init__(self, layout_filename, autogenlayers, make_mplfigures, dpi) 557 #layout_filename = layout_filename 558 self.layout = minidom.parse(self.layout_filename).getElementsByTagName('svg')[0] --> 559 self.layout_width = upar(self.layout.getAttribute('width')) 560 if self.layout_width[1] == 'u': 561 self.layout_width = (self.layout_width[0], 'px') ``` /Users/scollis/anaconda/envs/houston/lib/python3.5/site-packages/figurefirst/svg_to_axes.py in upar(unit_st) 46 unit_st = str(unit_st) 47 try: ---> 48 ind = map(str.isalpha, unit_st).index(True) 49 num, unit = float(unit_st[:ind]), unit_st[ind:] 50 except ValueError: AttributeError: 'map' object has no attribute 'index' ``` See: https://stackoverflow.com/questions/33717314/attributeerror-map-obejct-has-no-attribute-index-python-3
scollis commented 7 years ago

Found another issue:


/Users/scollis/anaconda/envs/houston/lib/python3.5/site-packages/figurefirst/svg_to_axes.py in parse_transform(transform_str)
    176     ##################
    177     trnsfrms = [mtrx for (pos,mtrx) in sorted(zip([tr_pos,mt_pos,sc_pos],
--> 178                                               [tr,mt,sc]))]
    179     trnsfrms = [m for m in trnsfrms if not(m is None)]
    180     from numpy import dot

TypeError: unorderable types: NoneType() < int()

In [4]: sorted?
Signature: sorted(iterable, key=None, reverse=False)
Docstring:
Return a new list containing all items from the iterable in ascending order.

A custom key function can be supplied to customize the sort order, and the
reverse flag can be set to request the result in descending order.
Type:      builtin_function_or_method
scollis commented 7 years ago

I kinda cant fix that... Too mixed up.. packaging some quick work I did into a PR.

psilentp commented 6 years ago

Long time getting to this but I think we mostly have python3 compatibility now.