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

Remove link to addon directory at exit of blender - take 2 #184

Draft
wants to merge 64 commits into
base: master
Choose a base branch
from

Conversation

Mateusz-Grzelinski
Copy link
Collaborator

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

Design is complete. No breaking changes will be introduced in this PR.

Remove addon link at the blender exit. This is implemented as new feature with setting blender.addon.keepAddonInstalled.

In this PR implemented:

  • Disable "Load Previous settings" Blender feature during VS code session. Blender breaks when trying to copy link from previous version
  • Windows only: disable addon uninstallation if addon is link because if will cause data loss on Windows :
  • Add option to make addon link/junction temporary blender.addon.keepAddonInstalled. If false addon will be available only during debug session
  • Send notification if linking addon failed
  • Update readme
  • multiple blender instances might use the same addon (for example you start blender twice). Do not remove the directory when another blender instance still needs it!

Relevant: #49

Pros:

  • Having the link temporary will fix issues that pop up in ugly corner cases in various places:
    • uninstalling addon from blender might lead to data loss
    • importing data from previous blender converts junction (link) into directory what leads to permission error when trying to install addon

Cons:

  • changes what users are used to. we can also prompt user to choose.
  • removing junctions and directories in python is a mess!!! Different python versions handle junctions dramatically differently.

Design 1 - link only when debugging - used in this PR

  • temporary link to addon dir is made only for VS code session - proposed in Remove link to addon directory at exit of blender #55 but not merged, so
    • add new setting to go back to previous behaviour - simple
    • or create a command "Blender: Install addons" that links/installs addons permamently - might be complicated - addons can have different ways of installation.

Design 2 - modify addon directory - unused

  • breaking change
  • modify VS code startup to use separate addon BLENDER_USER_SCRIPTS and dir BLENDER_SYSTEM_EXTENSIONS
    • might conflict with user settings

Design 3

Modfiy blender preferences to recognise addon location via bpy.context.preferences.filepaths.script_directories
Cons:

- Capitalize global variables
- Add type hints
Fresh installation of blender is not going to have directory created.
…o-cherry-pick

# Conflicts:
#	pythonFiles/include/blender_vscode/__init__.py
#	pythonFiles/include/blender_vscode/load_addons.py
- you are developing extension in addons directory
- extension has legacy bl_info defined
- do not create a link
- prevent from various errors from old links
- during blender version upgrade links are copied what breaks them and required manual fix
# Conflicts:
#	pythonFiles/include/blender_vscode/load_addons.py
# Conflicts:
#	pythonFiles/include/blender_vscode/load_addons.py
#	pythonFiles/tests/blender_vscode/test_load_addons.py
…ink-on-exit

# Conflicts:
#	CHANGELOG.md
#	README.md
#	pythonFiles/include/blender_vscode/__init__.py
#	pythonFiles/include/blender_vscode/communication.py
#	pythonFiles/include/blender_vscode/installation.py
#	pythonFiles/include/blender_vscode/load_addons.py
#	pythonFiles/include/blender_vscode/operators/addon_update.py
#	pythonFiles/tests/blender_vscode/test_load_addons.py
#	src/blender_executable.ts
# Conflicts:
#	pythonFiles/include/blender_vscode/communication.py
#	pythonFiles/include/blender_vscode/environment.py
#	pythonFiles/include/blender_vscode/load_addons.py
#	pythonFiles/include/blender_vscode/operators/addon_update.py
This is non-destructive operation, files are not deleted.
@Mateusz-Grzelinski Mateusz-Grzelinski marked this pull request as ready for review September 4, 2024 21:31
from typing import Optional, Union


def resolve_link(path: Union[str, os.PathLike]) -> Optional[str]:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

handling juction is an absolute disaster due to python changes 3.7 -> 3.11. In worst case scenario use cmd call.

@JacquesLucke
Copy link
Owner

I'm not sure about this yet. I think this needs a better problem description before jumping to a solution.

Some notes:

  • If Blender crashes, the addon link won't be removed and leads to an unexpected change.
  • Is it expected that the addon is also available in Blender when not starting from vscode? In this case, we would have to figure out how to "overwrite" the normally installed addon with the version that is in development.
  • Instead of trying to figure out how to remove links, maybe there is a way to make the addon available in Blender without having to create a link in the first place?

@Mateusz-Grzelinski
Copy link
Collaborator Author

Mateusz-Grzelinski commented Sep 5, 2024

If Blender crashes

Yes, blender panic will leave the link. But that is true for any solution, unless we implement server side cleanup. Hm, maybe I will implement it, seems easy enough.

Note: python exceptions do a proper cleanup. Only the panic with blender.crash.txt will leave the link.

Is it expected that the addon is also available in Blender when not starting from vscode?

Currently you do not have a choice. Right now your addon is permamently linked and available also outside of VS code session. Using new setting blender.addon.keepAddonInstalled now you have a choice.

In this case, we would have to figure out how to "overwrite" the normally installed addon with the version that is in development.

This is impossible to design without any flaws.
I found only Design 1 and 2 in description of this PR. I also added design 3, which could potentially work... I did not find only more sensible options for us.

Current behavior: blender will fail to start (because link can not be created, directory already exists). I recently improved the error message: https://github.com/JacquesLucke/blender_vscode/blob/master/pythonFiles/include/blender_vscode/load_addons.py#L41

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.

2 participants