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

update dockutil to be python3 compatible #87

Closed
wants to merge 1 commit into from
Closed

Conversation

erikng
Copy link

@erikng erikng commented Dec 4, 2019

figured I would help others, but I made it python 3 compatible.

I tested this against Greg's relocatable python, but using my own python 3 requirements https://github.com/erikng/installapplications/blob/embeddedpython3/py3_requirements.txt from my installapplications tool.

I tested everything except manipulating the user template and the --allhomes functionality. If someone needs that, they can test this PR and comment if it works or not.

@kcrawford
Copy link
Owner

Thank you for this!

I have questions because I am not up to speed on python3 and best practices.

Is this meant to work seamlessly with either python version? Can it be made to? I had started attempting that at PSU hack night but didn't get far struggling with unicode.

In order to work with either python2 or python3 with same code, are additional modules required?

I am kind of a purist about wanting tools to work seamlessly without dependencies. At least that is a goal anyway.

Thanks again. I will probably have more questions.

@@ -1,5 +1,3 @@
#!/usr/bin/python
Copy link
Owner

Choose a reason for hiding this comment

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

What should shebang be? #!/usr/bin/env python (if it also works in python2) or #!/usr/bin/env python3 ? or something else?

Copy link
Author

@erikng erikng Dec 6, 2019

Choose a reason for hiding this comment

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

Great question. I didn't have an answer to that question so I axed it from the PR.

Ideally it would be interesting to test this with official python3 package and then use #!/usr/bin/env python3 but you could run into an issue where someone has a different python installed in their user path. dockutil is typically ran in the user space so that shebang could be a bad assumption.

My gut feeling is people triggering dockutil should use it without a shebang and then invoke it against the python3 of their choice. So for myself I do /Library/InstallApplications/Python.framework/blahblahblah/bin/python3 /path/to/shebangless/dockutil

Everyone writing python3 is going to run into this. If you want to be authoritative, it's highly likely you will have to include your own python framework for others to use and it will increase your support burden.

Wish I had a better answer.

@@ -403,7 +401,9 @@ def writePlist(pl, plist_path):
# get a tempfile path for writing our plist
plist_import_path = tempfile.mktemp(dir='/tmp')
# Write the plist to our temporary plist for importing because defaults can't import from a pipe (yet)
plistlib.writePlist(pl, plist_import_path)
Copy link
Owner

Choose a reason for hiding this comment

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

I might want to check if method exists if plistlib has changed and we want to support either.

Copy link
Author

Choose a reason for hiding this comment

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

It doesn't. Python 3.4 and higher only :/

@@ -543,10 +543,6 @@ def addItem(pl, add_path, replace_label=None, position=None, before_item=None, a
if showas == None: showas = 0
if arrangement == None: arrangement = 2

#fix problems with unicode file names
enc = (sys.stdin.encoding if sys.stdin.encoding else 'UTF-8')
Copy link
Owner

Choose a reason for hiding this comment

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

I will need to test with emojis etc.

Copy link
Author

Choose a reason for hiding this comment

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

Python 3 handles Unicode much better than 2.7, but definitely did not test items with emojis

@@ -584,18 +580,14 @@ def addItem(pl, add_path, replace_label=None, position=None, before_item=None, a
if tile_type == 'file-tile':
new_item = {'GUID': new_guid, 'tile-data': {'file-data': {'_CFURLString': add_path, '_CFURLStringType': 0},'file-label': label_name, 'file-type': 32}, 'tile-type': tile_type}
elif tile_type == 'directory-tile':
if subprocess.Popen(['/usr/bin/sw_vers', '-productVersion'],
Copy link
Owner

Choose a reason for hiding this comment

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

Oh no we've dropped support for Mac OS X Tiger. 🤣

Copy link
Author

Choose a reason for hiding this comment

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

Heh yep. I figure it was worth dropping.

@erikng
Copy link
Author

erikng commented Dec 6, 2019

Thank you for this!

I have questions because I am not up to speed on python3 and best practices.

Is this meant to work seamlessly with either python version? Can it be made to? I had started attempting that at PSU hack night but didn't get far struggling with unicode.

In order to work with either python2 or python3 with same code, are additional modules required?

I am kind of a purist about wanting tools to work seamlessly without dependencies. At least that is a goal anyway.

Thanks again. I will probably have more questions.

I only tested python3 because python2 is EOL. Should you decide to be dual compliant, you can certainly try, but python2 and 3 handle Unicode very differently as well as strings and the methods used in the PR would have to be adapted for python2 as they don't exist until python 3.4

I personally don't have time to implement it in that fashion but if that's something you want to do, maybe just import this PR into a branch and use this as a starting point. It certainly wouldn't hurt my feelings :)

@acahir
Copy link

acahir commented Sep 1, 2020

Just a note, in Big Sur apple is even marking python2 EOL. The following displayed when launching "python" in terminal:

WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.

and python3 is installed in /usr/bin, just like it was in Catalina. Catalina might even have had same warning, I can't remember.

So I'd vote for making current version last supporting python2, and use python3 going forward. Prob not worth the effort of making dual compliant, and can always point to current version for anyone needing to use python2.

@flammable
Copy link

Bumping this! In macOS Monterey, anything that calls Python 2 displays an alert to the user about its deprecation. For a tool like docktutil, we'd want it to run silently, so this is an issue for us.

Should I switch to @erikng's fork, or hold out for an official release that utilizes Python 3?

Thanks for this tool, @kcrawford!

@kcrawford
Copy link
Owner

This will be addressed.

Note the GUI prompts only present if running python from an app.

@kcrawford
Copy link
Owner

I see python2 is removed in macOS 12.3
So I'll try to have a new version out ASAP

@ryangball
Copy link
Contributor

Is there a reason the version is not being bumped to 2.0.6 or later, or did I miss that?

@kcrawford
Copy link
Owner

I expect a beta version that works on macOS 12.3 will be available within a few days.

@kcrawford
Copy link
Owner

dockutil 3.0.0 beta
https://github.com/kcrawford/dockutil/releases
Sorry package is not signed yet

@erikng erikng closed this Mar 3, 2022
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.

5 participants