cloudmatrix / esky

an auto-update framework for frozen python apps
BSD 3-Clause "New" or "Revised" License
362 stars 74 forks source link

OSX: unorderable types: str() > NoneType() while creating patch #129

Closed JPFrancoia closed 8 years ago

JPFrancoia commented 8 years ago

Hi,

I'm trying to create a patch for one of my application. I'm on OSX captain with python3.5 this times.

Let's say I have an app:

my_application-1.0_macosx-10_6-intel

When I run

python3 setup.py bdist_esky_patch

for the version 1.1, the zip for the new version is correctly created, no problem. But the creation of the patch fails:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/esky/bdist_esky/__init__.py", line 812, in run
    esky.patch.main(["-Z","diff",source_esky,target_esky,patchfile])
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/esky/patch.py", line 1391, in main
    write_patch(source,target,stream,diff_window_size=opts.diff_window)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/esky/patch.py", line 310, in write_patch
    Differ(stream,**kwds).diff(source,target)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/esky/patch.py", line 979, in diff
    self._diff(source,target)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/esky/patch.py", line 993, in _diff
    self._diff_dir(source,target)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/esky/patch.py", line 1014, in _diff_dir
    sibnm = self._find_similar_sibling(source,target,nm)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/esky/patch.py", line 1247, in _find_similar_sibling
    if cur > best:
TypeError: unorderable types: str() > NoneType()

Looking at the corresponding file:

            best = (2,None)
            print(best)
            for sibnm in os.listdir(source):
                if not os.path.isdir(os.path.join(source,sibnm)):
                    continue
                if os.path.exists(os.path.join(target,sibnm)):
                    continue
                sib_names = set(os.listdir(os.path.join(source,sibnm)))
                cur = (len(sib_names & t_names),sibnm)
                print(cur)
                if cur > best:
                    best = cur
            return best[1]
        else:
            return None

I tried to print cur and best to see what's going wrong:

(2, None)
(2, 'my_application-1.0_macosx-10_6-intel')

So it appears None and str types are not orderable...

rfk commented 8 years ago

So it appears None and str types are not orderable...

Nice catch. Indeed, IIRC this is new behaviour in python3, is used to be that None would compare smaller than anything. It may work to just replace best = (2, None) with best = (2, '') to get the same effect, but then the line with return best[1] would have to check for the empty string and convert it back into a None before returning it.

timeyyy commented 8 years ago

issue has been fixed on py3k branch, ill make a pr now..

JPFrancoia commented 8 years ago

I think you also have to:

                if cur > best:
                    best = cur
            if best[1] ==  '':
                return None
            else:
                return best[1]

As rfk mentionned.

timeyyy commented 8 years ago

The return value only ever gets checked once for None,

I changed the check to fail for '' as well, so now we don't need None to be returned ^^

JPFrancoia commented 8 years ago

Ok