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

Find default blender executables in system PATH #179

Merged

Conversation

Mateusz-Grzelinski
Copy link
Collaborator

@Mateusz-Grzelinski Mateusz-Grzelinski commented Aug 4, 2024

This PR adds best effort approach to find existing blender installations:

  • look at system env PATH and look for bledner executables
  • And typical windows locations (as they are not added to path.)
  • Prefer paths displayed in user settings
  • blender.exe paths are deduplicated. paths in user settings are preffered.
  • If Blender executable does not exist indicate it in quick pick window

Screeshot: The system installation blender was added to list by this feature.
image

TODOs:

  • listed directories seem to be cached by VScode or system. How does it work and can we rely on this cache?
  • windows deduplicate the same path but with lower/upper case, ex C:\ vs c:\
  • check for "typical install paths" on
    • Windows -
      • program files - done (simple implementation), blender install path can be read from registry (not implemented)
      • steam installation - will not do in this patch, possible but pretty messy to support, see come snippets below
      • store installaion - it might NOT be possible to support. Path %USERPROFILE%\AppData\Local\Microsoft\WindowsApps contains only blender-launcher.exe and C:\Program Files\WindowsApps has no read rights.
    • linux- Apt, snap, flatpack, ~/.bin, /bin, /opt, /usr/bin? Those should be already in path
      • deduplicate hard links
      • deduplicate hard links in this situation: user has in settings /bin/blender and searchBlenderInSystem found /usr/bin/blender
      • snap is part of PATH, it should just work /snap/bin/blender. Snap started running without window top bar on my setup...
    • macOs - help wanted!

Those open TODOs are now blockers, but would be nice to test.

Cons:

  • causes 1seconds slowdown on first run. I assume system is caching stating files.
  • is it going to work in weird cases like blender is on network attached drive?

Snippets for searching blender in steam directories on windows:

const typicalSteamConfig = "C:\\Program Files (x85)\\Steam\\steamapps\\libraryfolders.vdf"
// hkey = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\WOW6431Node\Valve\Steam")
// steam_path = winreg.QueryValueEx(hkey, "InstallPath")
// C:\Users\grzel>reg query HKLM\SOFTWARE\WOW6431Node\Valve\Steam /v InstallPath /t REG_SZ
// HKEY_LOCAL_MACHINE\SOFTWARE\WOW6431Node\Valve\Steam
//     InstallPath    REG_SZ    C:\Program Files (x85)\Steam
// End of search: 0 match(es) found.
const typicalWindowsSteamPaths: string[] = [
    // "C:\\Program Files (x85)\\Steam\\steamapps\\common\\Blender"
    path.join(process.env.ProgramFiles || "C:\\Program Files", "Steam", "steamapps", "common", "Blender", "blender.exe"),
    path.join(process.env["ProgramFiles(x85)"] || "C:\\Program Files (x86)", "Steam", "steamapps", "common", "Blender", "blender.exe"),
]

And typical windows locations as they are not added to path.
@JacquesLucke
Copy link
Owner

Generally looks like a good feature.

@Mateusz-Grzelinski Mateusz-Grzelinski marked this pull request as ready for review August 13, 2024 16:58
@Mateusz-Grzelinski Mateusz-Grzelinski marked this pull request as draft August 13, 2024 18:26
@Mateusz-Grzelinski Mateusz-Grzelinski marked this pull request as ready for review August 14, 2024 13:52
@Mateusz-Grzelinski
Copy link
Collaborator Author

I am happy with the result and I will merge the change on the weekend. Logic for finding blender in windows default paths can be further improved, but I will track this in different issue or PR.

@Mateusz-Grzelinski
Copy link
Collaborator Author

Mateusz-Grzelinski commented Aug 17, 2024

surprise surprise, edge case (ubuntu 22.03, apt installed blender 3.0.1):

It is typical for linux installs to make hard links to install, like here:

> ls -li /bin/blender /usr/bin/blender
6819210 .rwxr-xr-x 86M root 14 lut  2022 /bin/blender
6819210 .rwxr-xr-x 86M root 14 lut  2022 /usr/bin/blender

What shows up as 2 separate instances.
image

  1. it is not obvious how to get target of the hard link
➜  ipython                        
Python 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.26.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import sys,os

In [2]: os.path.islink("/bin/blender")
Out[2]: False

In [3]: os.path.islink("/usr/bin/blender")
Out[3]: False

In [5]: bin = os.stat("/bin/blender")

In [6]: usr = os.stat("/usr/bin/blender")

In [8]: usr.st_nlink
Out[8]: 1

In [10]: usr.st_ino
Out[10]: 6819210

In [11]: usr.st_ino == bin.st_ino
Out[11]: True

TODO:

  • deduplicate linux blender hard links based on inode number

@Mateusz-Grzelinski Mateusz-Grzelinski added the help wanted Extra attention is needed label Aug 17, 2024
@Mateusz-Grzelinski
Copy link
Collaborator Author

I am glad with the current implementation. I will test it once more on linux and merge on the weekend.

@Mateusz-Grzelinski Mateusz-Grzelinski removed the help wanted Extra attention is needed label Aug 24, 2024
@Mateusz-Grzelinski Mateusz-Grzelinski merged commit b8386c1 into JacquesLucke:master Aug 24, 2024
@Mateusz-Grzelinski Mateusz-Grzelinski deleted the default-blender-exe branch August 24, 2024 09:21
@luckychris
Copy link

i am very unhappy with the new update, because before (I am Macbook user) i could choose the blender.app directly from dropdown (for each Blender version, after i started it once), now i have to search for the blender.app every time i wanna start Blender via VSCode. That's a huge worsening. Can't you rollback the old code for mac users, please?

Mateusz-Grzelinski added a commit that referenced this pull request Sep 6, 2024
Mateusz-Grzelinski added a commit that referenced this pull request Sep 6, 2024
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.

3 participants