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 #168: avoid creating duplicate link for addon #172

Merged
merged 49 commits into from
Aug 17, 2024

Conversation

Mateusz-Grzelinski
Copy link
Collaborator

@Mateusz-Grzelinski Mateusz-Grzelinski commented Jul 25, 2024

In this PR:

  • allow user to develop addon even it is placed in directories like (without creating duplicate addon link):
    • \4.2\scripts\addons -> default dir for addons
    • \4.2\extensions\blender_org -> directory indicated by bpy.context.preferences.extensions.repos (list of directories)
  • use python3.7 syntax for compability
  • ensured (basic) compability with blender 2.80
  • remove duplicate links to development (VSCode) directory
  • remove broken links in addon and extension dir

Squash merge when ready. Please squash merge after #174 - it fixes one more issue with 2.80 compability

About tests:

  • they are mostly for me, just nice to have. if you look closesly they are missing many asserts and many errors will slip through when tesing on real blender instance.
  • should be cross platform, but tested only on windows
  • the tests run outside of blender. bpy and addon_utils are not necessary for tests
  • how to run:
pip install pytest
cd pythonFile
$env:PYTHONPATH="./include" # powershell
pytest -s .\tests 

I could not figure out how to run tests with VS code UI. Works fine with pycharm UI when you mark include directory as source directory.

todo:

  • fix tests

Corner cases (for documentation):

  • junctions and hard links are difficult to manage
    • python behaves completely differently when touching junction in different python versions!
  • link to extension is already present in different repository - remove the link
  • link to addon is already present in addon directory but has different name - remove the link
  • You are developing extension in addons directory (legacy addon not supported) - make a link
  • You are developing addon in extensions directory (no extension support) - make a link
    • why would you do that to me...
  • extension has legacy bl_info defined (supportes both legacy and new addon systems) - prefer extension for >4.2, otherwise addon
  • extension has legacy bl_info defined (supportes both legacy and new addon systems) BUT user is developing addon in addon directory - treat as addon - do not make a link.

@Mateusz-Grzelinski
Copy link
Collaborator Author

The change should be working now.
I tried adding some basic tests, but I did something wrong, because

  • if you run tests one by one they work
  • if you run the whole file the tests fail - the patch bleeds into other functions. I have no idea how to fix it.

Note: I have basic experience with tests.

pip install pytest
cd pythonFile
$env:PYTHONPATH="./include" # powershell
pytest -s .\tests\blender_vscode\test_load_addons.py::TestIsInAnyAddonDirectory::test_is_in_any_addon_directory # ok
pytest -s .\tests  # 1 ok 5 fail

@Mateusz-Grzelinski
Copy link
Collaborator Author

Mateusz-Grzelinski commented Jul 28, 2024

I think I fixed the tests, but i need to sleep on it.

  • rooky mistake: patch calls where they are made
  • confusing patching behaviour: you can not patch the attributes in same path in two places (probably)
  • removing modules works differently than I anticipated
  • mocking global variables is hard
  • fixed python 3.7 compability (blender 2.90)

Those tests are just prototypes that helped me find 2 more errors in my code. I am not sure if this is the right way to test (very complicated test for little code)

The tests are prepared to run outside of blender, and without fake-bpy-module

@Mateusz-Grzelinski
Copy link
Collaborator Author

Mateusz-Grzelinski commented Jul 29, 2024

  • found even more issues (and fixed them)
  • made a super-duper long test. The test is not that complicated but the patching is complicated.

Ehh, enother long evening.

@Mateusz-Grzelinski
Copy link
Collaborator Author

Mateusz-Grzelinski commented Jul 30, 2024

I am pretty sure this patch works as expected. Final test was done by adding addon and extension to both

  • \4.2\scripts\addons
  • \4.2\extensions\blender_org

as seen on screeshot, all looks ok.
image

The policy violation was fixed in 445778f

I verified that tests work even if fake-bpy-module is installed.

@Mateusz-Grzelinski Mateusz-Grzelinski marked this pull request as ready for review July 30, 2024 16:01
Copy link
Owner

@JacquesLucke JacquesLucke left a comment

Choose a reason for hiding this comment

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

Would be good if you could update the initial PR description to be a bit more comprehensive.

A few words about how to run the tests would be good too. Also looks like they work on linux only (it's ok, but would be good to be more explicit about it)?

pythonFiles/tests/blender_vscode/.gitignore Outdated Show resolved Hide resolved
@Mateusz-Grzelinski Mateusz-Grzelinski marked this pull request as draft July 30, 2024 18:11
@Mateusz-Grzelinski
Copy link
Collaborator Author

Mateusz-Grzelinski commented Jul 30, 2024

ugh, breaks older blender. Totally forgot about that. I need to fight the persmission denied error when pip installing and check with blender 2.8 - i think this is the oldest one we support.

Hey, but I am developing this PR on windows, tests should work... Oh, I named the path in Linux style. It does not matter, it works on windows

@Mateusz-Grzelinski
Copy link
Collaborator Author

fixed compability with bledner 2.80. Please squash merge after #174 - it fixes one more issue with 2.80 compability

@Mateusz-Grzelinski Mateusz-Grzelinski marked this pull request as ready for review July 31, 2024 19:24
@Mateusz-Grzelinski
Copy link
Collaborator Author

there are problems with python 3.7 and dealing with junctions in windows. They are not recognized correctly and give different errors than python 3.12

@Mateusz-Grzelinski Mateusz-Grzelinski added this to the 0.0.22 milestone Aug 12, 2024
- Windows only: You upgraded Blender version and imported old setting. Now links became real directories.
- Path is a real directory with the same name as addon (removing might cause data loss!)"""
)
raise e
Copy link
Collaborator Author

@Mateusz-Grzelinski Mateusz-Grzelinski Aug 12, 2024

Choose a reason for hiding this comment

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

technically, there is no need to "panic" here, we can still load other addons, but there is no indication that linking failed and bledner needs to be restarted anyways...

@Mateusz-Grzelinski
Copy link
Collaborator Author

This became very involving change, hopefully this is last iteration and I will merge it on the weekend.
Before release Linux needs some testing.

# Conflicts:
#	CHANGELOG.md
#	pythonFiles/include/blender_vscode/__init__.py
#	pythonFiles/include/blender_vscode/installation.py
It is not critical functionality, it is ok to ignore errors
@Mateusz-Grzelinski
Copy link
Collaborator Author

tested on ubuntu 22.04 snap installed blender 4.2. Works fine.
Merging.

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