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

fix: remove python usage in macOS cli wrapper #138582

Merged
merged 1 commit into from
Feb 1, 2022

Conversation

deepak1556
Copy link
Collaborator

@deepak1556 deepak1556 commented Dec 7, 2021

Fixes #134635
Fixes #137954

@deepak1556 deepak1556 self-assigned this Dec 7, 2021
@deepak1556 deepak1556 added this to the December 2021 milestone Dec 7, 2021
@deepak1556
Copy link
Collaborator Author

@deepak1556 deepak1556 requested a review from bpasero December 7, 2021 10:42
@bpasero bpasero requested a review from joaomoreno December 7, 2021 10:42
@joaomoreno
Copy link
Member

@deepak1556 What are your thoughts on #137954 ?

@deepak1556
Copy link
Collaborator Author

deepak1556 commented Dec 7, 2021

Thanks for the pointer! I agree with the sentiment in that issue, if there is a simpler non-python way to get the absolute path it would also make this script more resilient. But I have to try it out, to confirm if it covers all cases. Let me try to adjust this PR in that front.

@bpasero bpasero removed their request for review January 6, 2022 11:28
@stephanierifai
Copy link

Hi there! Is there an ETA on this? This would help us with a related issue folks have been hitting on Docker Desktop so appreciate the work on it.

@StefanScherer
Copy link

StefanScherer commented Jan 28, 2022

I don't know the history well enough, but I wonder if we can just drop the dependency on python at all. 🤔

What does scripts/code.sh do different? It seems it tries to solve the same problem, but with just plain bash.
See https://github.com/microsoft/vscode/blob/main/scripts/code.sh#L5-L8

if [[ "$OSTYPE" == "darwin"* ]]; then
	realpath() { [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"; }
	ROOT=$(dirname "$(dirname "$(realpath "$0")")")
else

It also seems that Apple doesn't install Python 3 by default in Monterey 12.3. See eg. https://twitter.com/manomarks/status/1486845980527894538?s=21 🤔

@deepak1556 deepak1556 force-pushed the robo/fix_macos_shortcut_wrapper branch from 9a4da49 to dc25e46 Compare January 31, 2022 06:45
@deepak1556 deepak1556 changed the title fix: use python3 on macOS >=12 for the cli wrapper fix: remove python usage in macos cli wrapper Jan 31, 2022
@deepak1556 deepak1556 changed the title fix: remove python usage in macos cli wrapper fix: remove python usage in macOS cli wrapper Jan 31, 2022
@deepak1556
Copy link
Collaborator Author

What does scripts/code.sh do different?

It does try to achieve the same effect but that won't work for symlink cases, resources/darwin/bin/code.sh will usually get symlinked to default binary search path /usr/local/bin so that code command is available to users. We need a bash solution that will also work for this case.

@deepak1556 deepak1556 force-pushed the robo/fix_macos_shortcut_wrapper branch from dc25e46 to e9af584 Compare January 31, 2022 08:52
@deepak1556 deepak1556 marked this pull request as ready for review January 31, 2022 08:53
@deepak1556
Copy link
Collaborator Author

deepak1556 commented Jan 31, 2022

@deepak1556
Copy link
Collaborator Author

This PR does not handle multiple installation cases for the same bundle identifier, I am sure if there is a wide use case for it.

@joaomoreno
Copy link
Member

This PR does not handle multiple installation cases for the same bundle identifier, I am sure if there is a wide use case for it.

Yeah you make a good point. I'm guessing mdfindwill just pick a random installation, if two different versions of the same product are found in disk... I'm not too excited about that.

@deepak1556
Copy link
Collaborator Author

I think we can make a safe fallback case with e9af584 if there are multiple results from mdfind. (ie)

  1. Use mdfind when there is exactly one result
  2. Fallback to sudo realpath implementation otherwise

thoughts ?

@joaomoreno
Copy link
Member

I don't really know. All I know is we went with Python because no matter how hard I tried, I couldn't find a pure shell solution that worked across shells/macOS versions, at the time. If you have confidence in the fallback logic and are up for taking the theoretical issue stream that might arise from it, then I approve 👌

@deepak1556
Copy link
Collaborator Author

You are right, I found myself in the same path when writing this PR. But given the python2 deprecation makes our cli completely useless on macOS monterey for many users, I will go ahead and try this #138582 (comment), will see if I can improve it later based on user feedback.

@n8felton
Copy link

I'm not sure that using mdfind should be an acceptable solution as there are plenty of instances where Spotlight may be completely disabled, or if VScode is installed to a location that is excluded from Spotlight.

I recommend using one of the readlink solutions[1] proposed[2] as it will use the actual symlink used to call code, which helps to simulate what the python realpath code was doing, rather than assume whatever app bundle is found with mdfind.

@deepak1556 deepak1556 force-pushed the robo/fix_macos_shortcut_wrapper branch 4 times, most recently from a6bc470 to 2c14bd4 Compare February 1, 2022 11:55
@deepak1556 deepak1556 requested a review from Tyriar February 1, 2022 15:03
@Tyriar
Copy link
Member

Tyriar commented Feb 1, 2022

The pure bash approach seems like the way to go from my perspective. Since there's a bash shebang it should be guaranteed that the script will run under bash, you just need to make sure you support the lowest expected version of bash shipped in macOS.

I'm not the best with bash scripts so my review of the actual scripts probably wouldn't be too useful.

@deepak1556 deepak1556 force-pushed the robo/fix_macos_shortcut_wrapper branch from 2c14bd4 to 530dae6 Compare February 1, 2022 15:56
@deepak1556
Copy link
Collaborator Author

Verified locally, merging for insiders testing.

@deepak1556 deepak1556 merged commit fc8a612 into main Feb 1, 2022
@deepak1556 deepak1556 deleted the robo/fix_macos_shortcut_wrapper branch February 1, 2022 15:58
@aeschli
Copy link
Contributor

aeschli commented Mar 16, 2022

related: microsoft/vscode-remote-release#6442

@deepak1556
Copy link
Collaborator Author

Thanks for addressing it @aeschli !!

@github-actions github-actions bot locked and limited conversation to collaborators Mar 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

./code helper script needs some fixes "Visual Studio Code - Insiders" needs to be updated on macOS Monterey
7 participants