JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
17.38k stars 2.39k forks source link

Julia Segment unable to find Julia executable installed through Microsoft Store #1269

Closed dact221 closed 2 years ago

dact221 commented 2 years ago

Code of Conduct

What happened?

Dear developers,

I installed Oh My Posh in Windows 11 through winget and created a custom theme. I also installed Julia through the Microsoft Store and the executable is at %USERPROFILE%\AppData\Local\Microsoft\WindowsApps (in %PATH%). However, the Julia segment was unable to determine the Julia version.

I tried installing the official Julia binaries from julialang.org/downloads and added them to %PATH% (%LOCALAPPDATA%\Programs\Julia-1.6.4\bin), and now the Julia segment works fine.

I was confused by the fact that Oh My Posh can find the julia executable installed by the official method but not the one installed through the Microsoft Store. Both versions are in %PATH%, and both of them runs fine for me on the command line. Then, I read Oh My Posh's code and found that the Go function exec.LookPath causes the issue.

I inspected the Julia executable at %USERPROFILE%\AppData\Local\Microsoft\WindowsApps and found that it's zero 0 bytes in size. However, this file works fine when executed from the command line; I think it is some kind of weird symlink. exec.LookPath attempts to follow the link and perform a stat system call (os.Stat) on it (source code) but fails in the process.

I'm not sure how much difficult would it be to implement a way to look for the Julia executable without using exec.LookPath, but I think it would solve the issue.

Theme

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "final_space": false,
  "osc99": false,
  "console_title": false,
  "blocks": [
    {
      "type": "prompt",
      "alignment": "left",
      "horizontal_offset": 0,
      "vertical_offset": 0,
      "segments": [
        {
          "type": "path",
          "style": "plain",
          "invert_powerline": false,
          "foreground": "cyan",
          "properties": {
            "prefix": " ",
            "style": "folder"
          }
        },
        {
          "type": "git",
          "style": "plain",
          "invert_powerline": false,
          "foreground": "#ff94df",
          "properties": {
            "branch_icon": "<#ff94df><b> </b></>",
            "fetch_stash_count": true,
            "prefix": "<#ffffff>on</> ",
            "template": "{{ .HEAD }}{{ if gt .StashCount 0 }} \uF692 {{ .StashCount }}{{ end }}"
          }
        },
        {
          "type": "julia",
          "style": "plain",
          "invert_powerline": false,
          "foreground": "#ffffff",
          "properties": {
            "missing_command_text": "error",
            "display_version": true,
            "display_error": true,
            "display_mode": "always",
            "home_enabled": true,
            "prefix": "<#ffffff>via</> \uE624 "
          }
        },
        {
          "type": "python",
          "style": "plain",
          "invert_powerline": false,
          "foreground": "#ffffff",
          "properties": {
            "display_mode": "always",
            "prefix": "<#ffffff>via</> \uE235 "
          }
        },
        {
          "type": "text",
          "style": "plain",
          "foreground": "lightGreen",
          "properties": {
            "prefix": "",
            "text": "\u276F"
          }
        }
      ]
    }
  ]
}

What OS are you seeing the problem on?

Windows

Which shell are you using?

powershell

Log output

Version: 6.8.0

Segments:

ConsoleTitle(false) -   0 ms -
path(true)    -   0 ms -  ~
git(false)    -   3 ms -
julia(true)   -   8 ms - via  error
python(true)  - 314 ms - via  3.7.10
text(true)    -   0 ms - ❯

Run duration: 327.3493ms

Logs:

2021/11/21 00:23:57 debug: getenv
C:\Users\casas\AppData\Local
2021/11/21 00:23:57 getenv duration: 0s, args: LOCALAPPDATA
2021/11/21 00:23:57 getCachePath duration: 606.5µs, args:
2021/11/21 00:23:57 getArgs duration: 0s, args:
2021/11/21 00:23:57 getArgs duration: 0s, args:
2021/11/21 00:23:57 getShellName duration: 11.7424ms, args:
2021/11/21 00:23:57 isRunningAsRoot duration: 0s, args:
2021/11/21 00:23:57 getcwd duration: 0s, args:
2021/11/21 00:23:57 getPathSeperator duration: 0s, args:
2021/11/21 00:23:57 getPathSeperator duration: 0s, args:
2021/11/21 00:23:57 getShellName duration: 0s, args:
2021/11/21 00:23:57 getCurrentUser duration: 0s, args:
2021/11/21 00:23:57 getHostName duration: 0s, args:
2021/11/21 00:23:57 getcwd duration: 0s, args:
2021/11/21 00:23:57 getcwd duration: 0s, args:
2021/11/21 00:23:57 getArgs duration: 0s, args:
2021/11/21 00:23:57 getRuntimeGOOS duration: 0s, args:
2021/11/21 00:23:57 getRuntimeGOOS duration: 0s, args:
2021/11/21 00:23:57 getPathSeperator duration: 0s, args:
2021/11/21 00:23:57 getPathSeperator duration: 0s, args:
2021/11/21 00:23:57 getPathSeperator duration: 0s, args:
2021/11/21 00:23:57 getRuntimeGOOS duration: 0s, args:
2021/11/21 00:23:57 getcwd duration: 0s, args:
2021/11/21 00:23:57 getRuntimeGOOS duration: 0s, args:
2021/11/21 00:23:57 hasCommand duration: 3.4461ms, args: git.exe
2021/11/21 00:23:57 getcwd duration: 0s, args:
2021/11/21 00:23:57 error: hasParentFilePath
CreateFile C:\.git: The system cannot find the file specified.
2021/11/21 00:23:57 hasParentFilePath duration: 0s, args: .git
2021/11/21 00:23:57 getcwd duration: 0s, args:
2021/11/21 00:23:57 getcwd duration: 0s, args:
2021/11/21 00:23:57 error: hasCommand
exec: "julia": executable file not found in %PATH%
2021/11/21 00:23:57 hasCommand duration: 8.0505ms, args: julia
2021/11/21 00:23:57 getcwd duration: 0s, args:
2021/11/21 00:23:57 getcwd duration: 0s, args:
2021/11/21 00:23:57 debug: getenv

2021/11/21 00:23:57 getenv duration: 0s, args: VIRTUAL_ENV
2021/11/21 00:23:57 debug: getenv

2021/11/21 00:23:57 getenv duration: 0s, args: CONDA_ENV_PATH
2021/11/21 00:23:57 debug: getenv

2021/11/21 00:23:57 getenv duration: 0s, args: CONDA_DEFAULT_ENV
2021/11/21 00:23:57 debug: getenv

2021/11/21 00:23:57 getenv duration: 0s, args: PYENV_VERSION
2021/11/21 00:23:57 hasCommand duration: 0s, args: python
2021/11/21 00:23:58 debug: runCommand
Python 3.7.10
2021/11/21 00:23:58 runCommand duration: 313.2373ms, args: python --version
2021/11/21 00:23:58 getcwd duration: 0s, args:
2021/11/21 00:23:58 isRunningAsRoot duration: 132.9µs, args:
2021/11/21 00:23:58 getcwd duration: 0s, args:
2021/11/21 00:23:58 getPathSeperator duration: 0s, args:
2021/11/21 00:23:58 getPathSeperator duration: 0s, args:
2021/11/21 00:23:58 getShellName duration: 0s, args:
2021/11/21 00:23:58 getCurrentUser duration: 0s, args:
2021/11/21 00:23:58 getHostName duration: 135.4µs, args:
lnu commented 2 years ago

Here's the error message returned when trying to locate the exe file: image

Have to check why Stat is not working in that scenario.

dact221 commented 2 years ago

I found that the file julia.exe at %USERPROFILE%\AppData\Local\Microsoft\WindowsApps is an NTFS reparse point. Using the fsutil tool I got the target file:

C:\Program Files\WindowsApps\JuliaComputingInc.Julia_1.2.16.0_x64__b0ra4bp6jsp6c\Julia\julialauncher.exe

I hope it helps.

image

dact221 commented 2 years ago

This issue is already reported on the golang repo: https://github.com/golang/go/issues/42919

I wonder if it is possible to find an OhMyPosh-side workaround.

JanDeDobbeleer commented 2 years ago

If it's lookpath that fails, we won't be able to work around that. @lnu were you able to see which call fails?

lnu commented 2 years ago

image

image

JanDeDobbeleer commented 2 years ago

@lnu that means we can't fix this as LookPath is also used when running a command.

lnu commented 2 years ago

@dact221 metioned this opened golang issue: golang/go#42919
And yes that will be too much investment for platform specific bug of go itself

JanDeDobbeleer commented 2 years ago

Closing this in favour of tracking golang/go#42919

github-actions[bot] commented 7 months ago

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues. If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.