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

MCprep 3.5 Rewritten Core #401

Merged
merged 47 commits into from May 10, 2023
Merged

Conversation

StandingPadAnimations
Copy link
Collaborator

@StandingPadAnimations StandingPadAnimations commented Mar 19, 2023

Alright, this is a new branch tracking deprecations and migrating 2.7x style code to 2.8. The term "Rewritten Core" I think acts as a nice theme for this migration, as it requires going into parts of MCprep that have long been forgotten about.

Faq (for anyone that stumbles apon this)

  • Q: Will this have any performance improvements?
    • A: No, any performance improvements will be negligible at most
  • Q: When's the earliest I can use this?
    • A: As of writing, we can't say. When this does go into public testing (likely as version 3.4.99 for obvious reasons), we'll create a GitHub discussion for bug reports and testing
  • Q: Why are you removing 2.7x support?
  • Q: Can I contribute code?
    • A: Sure, but you should have a good understanding of bpy and Git
  • Q: I'm a 2.7x user, what does this mean for me?
    • A: This means you will have to either stick with the MCprep 3.4 series, or upgrade. I've talked with 2.7x users who've moved to modern versions of Blender, and according to them, as long as you choose the 2.7x keybinds, migrating is pretty painless

Plans

  • Migrate PropertyGroups to use annotations
  • Remove Blender Internal support
  • Add annotations to common functions
  • Replace use of os with pathlib for file operations
  • Start using dataclasses when it makes sense
  • Start using f-strings for readability

Deprecations

util.make_annotations(cls) and util.bv28()

Dropped as 2.7x support will also be dropped. Just use type annotations for properties instead of the old 2.7x syntax and don't target 2.7x when writing code.

Docstrings for type info

Made redundent by type annotations. Docstrings are nice for explaining what each return value means, but type info should be done with type annotations.

Note that type annotations must be Python 3.7 compatible for maximum support. Also we won't be removing all docstring-based type information from older code, just from the functions that gain annotations.

StandingPad and others added 19 commits October 16, 2022 16:56
As we're dropping 2.7x support, this is no longer needed. Most of the
compatability functions will remain though since they're more readable.
Replaced some instances of os.path with the Path object from pathlib for
readability. Also added type annotations to MCprepEnv as we're moving
towards that. This also means MCprep will not work at all in Blender
2.7x due to the use of new syntax.

This will be the first in a long process of modernizing MCprep's code
with 2.8 style code. Blender 2.7x users may not be happy, but it's for
the better. If anything, 6 years worth of 2.7x support was a mistake (in
my opinion), as it limited what we could do and opened MCprep to even
more bugs (like in Blender 2.93 with make_annotations, which ironically
now is deprecated).
Replaced the old = syntax with the new : syntax. This also removes the
need for make_annotations, hence why they're removed.
As we're removing 2.7x support, it makes sense to remove Blender
Internal compatability as the engine is not present in Blender 2.8 and
above. Even UPBGE (a fork of the Blender game engine that's still
maintained) uses EEVEE, so there's no reason to continue supporting
Blender Internal.
The bang at the top meant Linux users couldn't run the test suite. This
changes now allows Linux users to run tests
@StandingPadAnimations StandingPadAnimations linked an issue Mar 19, 2023 that may be closed by this pull request
@StandingPadAnimations
Copy link
Collaborator Author

Btw @TheDuckCow, what errors did you get when testing? I can't run the test suite on my laptop (due to some OSX specific parts of the testing code)

@StandingPadAnimations
Copy link
Collaborator Author

StandingPadAnimations commented Mar 19, 2023

I think for this branch I'll also start simplifying the code. For example, the following function:

def matprep_cycles(
	mat, passes, use_reflections, use_principled, only_solid, pack_format, use_emission_nodes)

Could be adjusted as:

@dataclass
class PrepOptions:
	passes: dict[str]
	use_reflections: bool
	use_principled: bool
	only_solid: bool
	pack_format: str 
	use_emission_nodes: bool

def matprep_cycles(mat, options: PrepOptions)

Deprecation warning function was moved in MCprepEnv since it made more
sense to put it there
Originally matprep_cycles used to take multiple arguments, each one
representing a seperate option. This was annoying as it meant the
function has an unfathomable amount of arguments to keep track of.

This has been replaced with a dataclass (called PrepOptions) that keeps
track of all the options selected by the user. Not only does it make it
slightly easier for developers, it also gives the following benefits:
	- More info on what types the different options are
	- Better organization

Previously we couldn't do this due to 2.7x support, hence this being in
mcprep-3_5-recore.
@StandingPadAnimations StandingPadAnimations changed the base branch from dev to internal-rewrites March 19, 2023 22:20
@StandingPadAnimations
Copy link
Collaborator Author

Yeah I think we should do that. It would also give developers the benefit of the new changes.

Just one problem: the addon updater is complaining a lot:

Traceback (most recent call last):
  File "/home/mahid/.config/blender/3.5/scripts/addons/MCprep_addon/mcprep_ui.py", line 687, in draw
    addon_updater_ops.check_for_update_background()
  File "/home/mahid/.config/blender/3.5/scripts/addons/MCprep_addon/addon_updater_ops.py", line 816, in check_for_update_background
    updater.set_check_interval(enabled=settings.auto_check_update,
  File "/home/mahid/.config/blender/3.5/scripts/addons/MCprep_addon/addon_updater.py", line 558, in set_check_interval
    raise ValueError("Enable must be a boolean value")
ValueError: Enable must be a boolean value
Traceback (most recent call last):
  File "/home/mahid/.config/blender/3.5/scripts/addons/MCprep_addon/mcprep_ui.py", line 1623, in draw
    addon_updater_ops.check_for_update_background()
  File "/home/mahid/.config/blender/3.5/scripts/addons/MCprep_addon/addon_updater_ops.py", line 816, in check_for_update_background
    updater.set_check_interval(enabled=settings.auto_check_update,
  File "/home/mahid/.config/blender/3.5/scripts/addons/MCprep_addon/addon_updater.py", line 558, in set_check_interval
    raise ValueError("Enable must be a boolean value")
ValueError: Enable must be a boolean value
Traceback (most recent call last):
  File "/home/mahid/.config/blender/3.5/scripts/addons/MCprep_addon/mcprep_ui.py", line 687, in draw
    addon_updater_ops.check_for_update_background()
  File "/home/mahid/.config/blender/3.5/scripts/addons/MCprep_addon/addon_updater_ops.py", line 816, in check_for_update_background
    updater.set_check_interval(enabled=settings.auto_check_update,
  File "/home/mahid/.config/blender/3.5/scripts/addons/MCprep_addon/addon_updater.py", line 558, in set_check_interval
    raise ValueError("Enable must be a boolean value")
ValueError: Enable must be a boolean value
Traceback (most recent call last):
  File "/home/mahid/.config/blender/3.5/scripts/addons/MCprep_addon/mcprep_ui.py", line 1623, in draw
    addon_updater_ops.check_for_update_background()
  File "/home/mahid/.config/blender/3.5/scripts/addons/MCprep_addon/addon_updater_ops.py", line 816, in check_for_update_background
    updater.set_check_interval(enabled=settings.auto_check_update,
  File "/home/mahid/.config/blender/3.5/scripts/addons/MCprep_addon/addon_updater.py", line 558, in set_check_interval
    raise ValueError("Enable must be a boolean value")
ValueError: Enable must be a boolean value

@TheDuckCow
Copy link
Member

@StandingPadAnimations Can you try first merging the base milestone branch into this to resolve issues? Then should be quick to resolve anything else like if something got messed up with updater preferences (I have no other reports spearately that there's anything wrong in blender 3.5 and the updater).

git checkout milestone-3-5-0
git pull
git checkout mcprep-3_5-recore
git merge milestone-3-5-0 
# and now resolve conflicts :D  personally a fan of sublime merge, but lots of
# tools out there, or command line. Just be sure to live test afterwards!

If you needed, I could also help out with this step. But the conflicts cover changes you made, so I feel you're a better judge of how to do the merge. Then I can swoop in to fix whatever with the updater here.

@StandingPadAnimations
Copy link
Collaborator Author

Just one problem: the world panel is not appearing D:

No errors in the console as far as I can tell, nor any UI changes that would suggest an issue.

Anyway do you also want me to close the internal-rewrites PR since this branch also includes those changes?

Additionally removes all usage of the make_annotations workaround,
this commit does not affect the updater code in any way (which is
treated as a library). Preferences now draw, but mcprep scene props
are not currently registering, breaking most of the addon. Pre-existing
before this commit.
Copy link
Member

@TheDuckCow TheDuckCow left a comment

Choose a reason for hiding this comment

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

Given this PR is blocked on this now, @StandingPadAnimations we'll want to prioritize getting this ready and merged.

I've made a commit which adds what I believe are the remaining annotations, so we are fully moving to that and dropping the make_annotations workaround. Preferences initially wasn't working, now it is. However, something is still causing the bpy.types.Scene.mcprep_props to fail or otherwise not actually register, as I am getting UI draw errors saying:

Traceback (most recent call last):
  File "/Users/patrickcrawford/Library/Application Support/Blender/3.5/scripts/addons/MCprep_addon/mcprep_ui.py", line 908, in draw
    scn_props = context.scene.mcprep_props
AttributeError: 'Scene' object has no attribute 'mcprep_props'

I think this still may be annotation related - I recall errors regarding that were typically quite cryptic and misleading (I don't see any registration errors).

I'll keep debugging too and see what I can find, but feel free to try to beat me to it.

MCprep scene props still not registering, so still unable to run
automated tests.
MCprep scene props still not registering, so still unable to run
automated tests.
With this change, the UI now draws where needed. Many unit tests are
still failing.
@TheDuckCow
Copy link
Member

Alright, now we're in better shape. All UI seems to draw, though many of the unit tests are still failing, something we'll need to look into. Some live testing didn't show anything terribly off, could just be test code needs updating.

@StandingPadAnimations let me know once you do some testing on this branch yourself (after doing a git pull), and see if it's looking good for you aside from these unit tests. If so, I'd say we can merge and then I can tackle the unit test fixing separately.

Failed tests:
	spawn_mob: lender.app/Contents/Resources/3.5/scripts/modules/bpy/ops.py:113\n \n 
	spawn_mob_linked: lender.app/Contents/Resources/3.5/scripts/modules/bpy/ops.py:113\n \n 
	change_skin: lender.app/Contents/Resources/3.5/scripts/modules/bpy/ops.py:113\n \n 
	import_jmc2obj: "][mapping_set]\n TypeError: 'NoneType' object is not subscriptable\n 
	import_mineways_separated: "][mapping_set]\n TypeError: 'NoneType' object is not subscriptable\n 
	import_mineways_combined: "][mapping_set]\n TypeError: 'NoneType' object is not subscriptable\n 
	item_spawner: lender.app/Contents/Resources/3.5/scripts/modules/bpy/ops.py:113\n \n 
	item_spawner_resize: lender.app/Contents/Resources/3.5/scripts/modules/bpy/ops.py:113\n \n 
	geonode_effect_spawner: lender.app/Contents/Resources/3.5/scripts/modules/bpy/ops.py:113\n \n 
	particle_area_effect_spawner: lender.app/Contents/Resources/3.5/scripts/modules/bpy/ops.py:113\n \n 
	collection_effect_spawner: lender.app/Contents/Resources/3.5/scripts/modules/bpy/ops.py:113\n \n 
	img_sequence_effect_spawner: lender.app/Contents/Resources/3.5/scripts/modules/bpy/ops.py:113\n \n 
	load_material: lender.app/Contents/Resources/3.5/scripts/modules/bpy/ops.py:113\n \n 

@TheDuckCow
Copy link
Member

Anyway do you also want me to close the internal-rewrites PR since this branch also includes those changes?

If that's indeed the case, those changes are fully here, then sure you can close that PR.

@TheDuckCow TheDuckCow marked this pull request as ready for review May 3, 2023 06:33
Why? Poetry means we can easily define Python version, dependencies,
etc. without having to force developers to do everything by hand
(provided they want to use Poetry, it's fine if they don't c:).

The reason I'm doing it now is due to an upgrade on Arch Linux from
Python 3.10 to Python 3.11, breaking all virtual environments. Poetry is
useful especially on Linux where using the system Python tends to be an
annoyence.

The options I chose are based on MCprep 3.5, which mean the following:
- Blender 2.8 bpy
- Python 3.7 (as that's what 2.8 uses)

These are not set in stone, but I think those are reasonable for MCprep
@StandingPadAnimations
Copy link
Collaborator Author

@TheDuckCow I've added a pyproject.toml file for Poetry (mainly to make my life easier when Python updates on Linux, that's an absolute nightmare). Let me know if anything needs to be changed.

It's just for the development environment, not runtime

The MC part was not capitalized
@StandingPadAnimations
Copy link
Collaborator Author

let me know once you do some testing on this branch yourself (after doing a git pull), and see if it's looking good for you aside from these unit tests.

Beyond the deprecation warnings regarding the use of bv28(), I think we're in good shape. I'll start working on those deprecation warnings

@StandingPadAnimations
Copy link
Collaborator Author

Ahh yes:

factor_width = 0.3
if util.bv28():
    factor_width = 0.3

By removing all of the `bv28()` calls, we've gotten rid of all
deprecation warnings at startup and exit, which is awesome. Now we can
actually start live testing to find even more deprecation warnings
without having to deal with the insane output for the UI.
@StandingPadAnimations
Copy link
Collaborator Author

I've removed all deprecation warnings at startup and exit, which means now we can now start improving and testing the codebase (and live test to find more use of deprecated functions at the same time)

I think we can now perform the first merge with the milestone branch

Previouly Linux didn't have file population for the MCprep compile
scripts, so I've went ahead and added it to make our lives easier,
especially after that time an MCprep build script made a folder called ~
that ended in my home directory being wiped
The compile scripts had some small errors (like a missing exit after cd)
but also 2 big errors: SC2308 and SC2115

https://www.shellcheck.net/wiki/SC2308
https://www.shellcheck.net/wiki/SC2115

SC2308 was due to the use of `expr substr` when checking to see if the
OS in use was Linux. According to the shellcheck wiki, this is not
portable and as such shouldn't be used. This was replaced with a pipe
expression that passes to `cut -c 1-5`

SC2115 is due to an `rm -rf "$i/$NAME/" statement, which if the variable
is not set or null, a person's system can be massively messed up. Here's
a case where due to this exact issue, the Steam client ended up deleting
everything on the root directory owned by the user:
ValveSoftware/steam-for-linux#3671

While it's great that these issues were caught ahead of time, these
should have never been in MCprep's build scripts. We already know that
MCprep's build scripts can create folders named ~, causing their own
headaches (like I dealt with a while back). We seriously need to start
enforcing shellcheck for MCprep's build scripts.
@StandingPadAnimations
Copy link
Collaborator Author

Pushed some fixes for compile.sh, including 2 big errors caught by shellcheck. Read eccda95 for more info.

Tldr: We were using some syntax that if done wrong could have done some serious damage to a user's system (on Linux)

compile.sh already has a rocky history with doing some pretty bad things (case in point, this moment from January recorded on the MCprep server, which I finally fixed today), so we absolutely need to start linting shell scripts. https://github.com/koalaman/shellcheck is an amazing tool and would immediately start catching more errors. In addition, I think we need to start writing more cross platform scripts (I can't run the test suite due to OS X specific things in the script files)

@TheDuckCow
Copy link
Member

@StandingPadAnimations

Pushed some fixes for compile.sh, including 2 big errors caught by shellcheck. Read eccda95 for more info.

Tldr: We were using some syntax that if done wrong could have done some serious damage to a user's system (on Linux)

Great to have these fixes - but let's try to not expand the scope of this PR any more than it already has. It would be better to merge this into milestone-3-5-0 as soon as we are ready with no further changes (outside of fixes to what this branch already changes) as soon as possible.

Even changes like the pyproject.toml I want to think about more, but it's now wrapped up in all these other changes here (I'm ok with going with it though since it's dev side only, it's just an example). A good goal moving forward is small PRs (ie like 100 lines of code) that address one explainable net change (composed of one or more commits that make that single change a reality), and then you can have one PR chained on top of another if there's dependencies of one change on a prior and you don't want to wait for the first PR to be merged.

So, let's do no more new changes on this branch. I need to spot check the recent changes/additions to see if anything needs addressing, and then based on my approval, let's merge, and create new branches PRs off of newly updated milestone-3-5-0.

Copy link
Member

@TheDuckCow TheDuckCow left a comment

Choose a reason for hiding this comment

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

Largely approving, left a couple comments. Still feel the bash + poetry could be better suited in their own branches, but for simplicity, I'm ok if we have it here and just going forward make dedicated PRs.

@@ -915,7 +893,7 @@ class MCPREP_PT_world_tools(bpy.types.Panel):
"""World settings and tools"""
bl_label = "World Tools"
bl_space_type = 'VIEW_3D'
bl_region_type = 'TOOLS' if not util.bv28() else 'UI'
bl_region_type = 'UI'
Copy link
Member

Choose a reason for hiding this comment

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

Nit on extra space at end of line. Not that there aren't more egregious code style issues pre-existing 😆

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm considering adding https://github.com/akaihola/darker in a later PR so that we can gradually add better formatting, so hopefully this will be resolved in the future

@@ -1713,7 +1688,7 @@ class MCPREP_PT_mob_spawner(bpy.types.Panel):
bl_label = "Mob spawner"
bl_parent_id = "MCPREP_PT_spawn"
bl_space_type = "VIEW_3D"
bl_region_type = 'TOOLS' if not util.bv28() else 'UI'
bl_region_type = 'UI'
Copy link
Member

Choose a reason for hiding this comment

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

(same here)

MCprep_addon/mcprep_ui.py Show resolved Hide resolved
@@ -0,0 +1,18 @@
# This file is automatically @generated by Poetry 1.4.2 and should not be changed by hand.
Copy link
Member

Choose a reason for hiding this comment

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

What's the consequence of this file if, for example, you were to step away and I didn't update this with future updates? Will this file need to change with releases, or is it expected to remain mostly static? Would these hashes be universal, or system specific to you?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

According to the poetry documentation, the hashes are based on the dependencies. It's automatically handled by poetry

@StandingPadAnimations
Copy link
Collaborator Author

Ight, hopefully I'll merge this later today

@StandingPadAnimations StandingPadAnimations merged commit 1c08384 into milestone-3-5-0 May 10, 2023
@StandingPadAnimations StandingPadAnimations deleted the mcprep-3_5-recore branch May 10, 2023 14:39
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.

Dropping 2.7x support in MCprep 3.5
2 participants