Skip to content

Comments

add python3 compatibility#28

Merged
truebit merged 4 commits intomasterfrom
unknown repository
Apr 1, 2016
Merged

add python3 compatibility#28
truebit merged 4 commits intomasterfrom
unknown repository

Conversation

@heni
Copy link
Contributor

@heni heni commented Mar 15, 2016

No description provided.

@k06a
Copy link

k06a commented Mar 15, 2016

@truebit hope you have time to review this PR :)

@truebit
Copy link
Owner

truebit commented Mar 17, 2016

Hi, @heni
Thanks for the PR. It's good to add python3 compatability.
But IMO, the targeting user (a.k.a iOS developers ) may not be familiar with Python. I do not think that involving a third party package six in the installation process is a good idea。
Could you add python3 compability without 3rd party packages?

@heni
Copy link
Contributor Author

heni commented Mar 22, 2016

Ok, I have written all necessary methods from six explicitely

else:
return cmp(x, y)
def file_dir_order(x):
return ('.' in x, x)
Copy link
Owner

Choose a reason for hiding this comment

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

this new compare method does not act as what I did before. It will put all dirs and files in alphabet order.

What I did before was putting dirs before files, and they both in alphbet order in their type. Doing a diff between the results would be more clear.

I will revert this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are wrong, the next code snippet
python -c "file_dir_order = (lambda x: ('.' in x, x)); print('\n'.join(name for name in sorted(['dir1', 'last_dir', 'file.m', 'a.h'], key=file_dir_order)))"
will print:
dir1 last_dir a.h file.m
(all dirs before files)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The fact is that sorted function in python3 doesn't accept cmp attribute and the challenge is emulate old sorting behavior only with key extracting function

Copy link
Owner

Choose a reason for hiding this comment

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

Your code snippet is correct. But the difference really happened in python 2.7 and python 3.5
So the problem is in python 3 string sort method modification in line 272.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you give me large list (>=20) of strings and wished output order for them?
Having this list I can write method that sort them in one perfect way for python2.7 and python3.5.

if self.main_group_hex not in last_two[0]:
lines.sort(key=lambda file_str: children_pbx_key_ptn.search(file_str).group(),
cmp=file_dir_cmp)
lines.sort(key=lambda file_str: (children_pbx_key_ptn.search(file_str).group(), file_dir_order))
Copy link
Owner

Choose a reason for hiding this comment

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

Yep, I know that python3 removed cmp parameter in sort. But I think your lambda seems not correct. Though I am not very familiar with cmp and key in sort method
But the result could tell the difference. You could run your version and master on the same project file, you would see differences in the sorting dirs and files.

@truebit truebit merged commit 5cd67db into truebit:master Apr 1, 2016
truebit pushed a commit that referenced this pull request Apr 1, 2016
@riveryan
Copy link

riveryan commented Apr 3, 2016

Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 170, in _run_module_as_main
"main", mod_spec)
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.5/site-packages/xUnique.py", line 527, in
main()
File "/usr/local/lib/python3.5/site-packages/xUnique.py", line 504, in main
xcode_proj_path = args[0].decode(sys_get_fs_encoding())
AttributeError: 'str' object has no attribute 'decode'

I got this error with python3.

@truebit
Copy link
Owner

truebit commented Apr 3, 2016

@riveryan What the command arguments did you use?
And please remind, you should try master branch to use python3, instead of the pip version

@truebit
Copy link
Owner

truebit commented Apr 7, 2016

@riveryan I just uploaded new pip version to pypi including this pr. You can update xunique using command: pip install -U xunique

truebit pushed a commit that referenced this pull request Oct 15, 2016
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.

4 participants