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

Internal Refactoring for 3.4.3 #348

Closed
wants to merge 23 commits into from

Conversation

StandingPadAnimations
Copy link
Collaborator

@StandingPadAnimations StandingPadAnimations commented Oct 16, 2022

List of Deprecated Features Planned for MCprep 3.4.3

State: Alpha, changes are not final

conf.dev -> conf.env.dev_build

from .conf import env
env.dev_build

conf.v -> conf.env.verbose

from .conf import env
env.verbose

conf.vv -> conf.env.very_verbose

from .conf import env
env.very_verbose

conf.data -> conf.env.data

from .conf import env
env.data

conf.json_data -> conf.env.json_data

from .conf import env
env.json_data

conf.json_path -> conf.env.json_path

from .conf import env
env.json_path

conf.use_icons -> conf.env.use_icons

from .conf import env
env.use_icons

conf.preview_collections -> conf.env.preview_collections

from .conf import env
env.preview_collections

conf.icons_init() -> conf.env.icons_init()

from .conf import env
env.icons_init()

conf.loaded_all_spawners -> conf.env.loaded_all_spawners

from .conf import env
env.loaded_all_spawners

conf.skin_list -> conf.env.skin_list

from .conf import env
env.skin_list 

conf.rig_categories -> conf.env.rig_categories

from .conf import env
env.rig_categories 

conf.entity_list -> conf.env.entity_list

from .conf import env
env.entity_list

conf.material_sync_cache -> conf.env.material_sync_cache

from .conf import env
env.material_sync_cache

conf.register() ->conf.MCprepEnv.__init__(self)

# conf.py
env = MCprepEnv()

conf.log(statement, vv_only=False) -> conf.env.log(self, statement, vv_only=False)

from .conf import env
env.log("Debug statement!")

@StandingPadAnimations StandingPadAnimations added this to the v3.4.2 milestone Oct 16, 2022
@TheDuckCow
Copy link
Member

Realize this is still in review, but calling out now that I'd prefer the name lower-case ENV instead of uppercase; uppercase is generally referred to treat something as a constant, but env is something that will be mutable (verbose can be turned off and on for instance), so will ask you to turn it into lowercase when you can.

Holding off on further review in the meantime - thanks for getting a head start here!

@StandingPadAnimations
Copy link
Collaborator Author

Realize this is still in review, but calling out now that I'd prefer the name lower-case ENV instead of uppercase; uppercase is generally referred to treat something as a constant, but env is something that will be mutable (verbose can be turned off and on for instance), so will ask you to turn it into lowercase when you can.

Sure thing, maybe something like mcprep_env since env is typically used for .env files.

One interesting thing I might add to MCprepEnv is checking the version of Blender the user is using at initialization. This would make the bv28() and bv30() functions obsolete in favor of some variables that are set when Blender loads MCprep (minBV() would still have a use for arbitrary versions of Blender that aren't 2.8 or 3.0). Since MCprepEnv is a class, there's a whole load of interesting stuff that can be done with it.

@TheDuckCow
Copy link
Member

Yup that makes sense to have those vars initialized in __init__; we can do a number of interesting things indeed, though we want to make sure that it stays lightweight.

As for the name of the variable instance, I'd like a convention for naming that is short and easy to use in the other classes. mcprep_env feels a bit long, I feel like we could use env since it's not used anywhere else. We don't have any env files at the moment, and even if we did, it would be read and parse by the MCprepEnv class anyways, so it feels accurate enough that you would call the instance overall as env anyhow.

@StandingPadAnimations
Copy link
Collaborator Author

Sorry for the lack of updates, hopefully I'll be able to get some changes done by late December/early January. I'll be busy for the next couple of weeks

@StandingPadAnimations
Copy link
Collaborator Author

Alright, @TheDuckCow, I've renamed ENV to env. Hopefully by the end of this week I can get some more progress done on this

@StandingPadAnimations
Copy link
Collaborator Author

StandingPadAnimations commented Jan 14, 2023

As mentioned here, I won't be working on MCprep anymore, so this PR will just be left in this state.

I believe this will eventually get done in the future, either by the open source community or myself (if I decide to come back), but who knows

@TheDuckCow TheDuckCow modified the milestones: v3.4.2, v3.4.3 Jan 30, 2023
@StandingPadAnimations
Copy link
Collaborator Author

StandingPadAnimations commented Feb 14, 2023

Ok, so I don't know if I'll reopen this, but I'm curious about whether we'll use type annotations (which are supported in Blender 2.8 and above), since it would give the following benefits:

  • Better completions in IDES
  • More info for static analyzers, which MCprep would massively benefit from
  • Tells developers what arguments a function can take and return
  • etc

Alternatively we could add type annotations at a later date (not preferable, but better late then never) or figure out a way to use it in older versions of Blender (perhaps with the futures module?)

@StandingPadAnimations StandingPadAnimations changed the title Internal Refactoring for 3.4.2 Internal Refactoring for 3.5.0 Mar 16, 2023
@StandingPadAnimations
Copy link
Collaborator Author

I think now I'll be working on this. I'll look into porting the use of OS to Pathlib (for file operations) since it's more readable and concise

@StandingPadAnimations
Copy link
Collaborator Author

Though now I got to sign all of these commits for verification purposes. Not too annoying though since it's not merged

@StandingPadAnimations
Copy link
Collaborator Author

Alright with #399 (and this PR is for MCprep 3.5), I think it's now safe to deprecate the use of os for filepaths and file operations, as well as add type annotations to the env class

@StandingPadAnimations
Copy link
Collaborator Author

Alright, I'll merge dev with this locally (for updates) ajd get started. I'll be doing the following:

  • Add a deprecation warning function
  • Deprecate 2.7x compatability code
  • Remove 2.7x compatablity code where possible
  • Add type hints to functions and variables

@TheDuckCow just want to know your thoughts

@TheDuckCow
Copy link
Member

Just to be clear, you mean merge dev into this branch just to sync it up right?

I'm ok with this. We can use internal-rewrites as an actual "feature branch". I don't want to merge breaking compatibility into dev yet, as we may have more patch releases between now and 3.5 (we will for sure have at least a 3.5.2, based on your report about mtl conversion errors). But it would be good to get a head start on some of these updates.

I'd start with removing 2.7x compatibility code, anything to do with Blender Internal.

I'm wary about adding type hints everywhere just yet. It will just create more merge conflicts in the future if we annotate every function, whereas if we do this a little closer to the 3.5 release, we'd deal with the state of the code at that time. But this could also be mitigated by diligently re-merging dev into this internal-rewrites feature branch.

@StandingPadAnimations
Copy link
Collaborator Author

Just to be clear, you mean merge dev into this branch just to sync it up right?

Yep

I'd start with removing 2.7x compatibility code, anything to do with Blender Internal.

Sure thing

@StandingPadAnimations
Copy link
Collaborator Author

Alright, went ahead and made a new branch called mcprep-3_5-recore (recore being short for rewritten core, as many parts are being rewritten)

@StandingPadAnimations StandingPadAnimations changed the title Internal Refactoring for 3.5.0 Internal Refactoring for 3.4.3 Mar 19, 2023
@StandingPadAnimations
Copy link
Collaborator Author

So should we move these deprecations to MCprep 3.5?

@TheDuckCow
Copy link
Member

TheDuckCow commented Apr 6, 2023 via email

@TheDuckCow TheDuckCow changed the base branch from dev to milestone-3-5-0 April 6, 2023 16:36
@TheDuckCow
Copy link
Member

I've updated the base since this branch as-is doesn't work in 2.7x (first error is print(f"\"{header}\"")), and this is ok. I'm hopeful we can make 3.5.0 the next release anyways.

Some changes still needed though, errors on startup with I think some remaining ENV variables where the class instance is now named env (which I think is good). e.g.

  File "/Users/patrickcrawford/Library/Application Support/Blender/3.5/scripts/addons/MCprep_addon/mcprep_ui.py", line 934, in draw
    elif env.skin_list and len(ENV.skin_list) <= sind:
NameError: name 'ENV' is not defined. Did you mean: 'env'?

and

Traceback (most recent call last):
  File "/Applications/Blender 3.5/blender.app/Contents/Resources/3.5/scripts/modules/addon_utils.py", line 369, in enable
    mod.register()
  File "/Users/patrickcrawford/Library/Application Support/Blender/3.5/scripts/addons/MCprep_addon/__init__.py", line 64, in register
    load_modules.register(bl_info)
  File "/Users/patrickcrawford/Library/Application Support/Blender/3.5/scripts/addons/MCprep_addon/load_modules.py", line 181, in register
    addon_updater_ops.register(bl_info)
  File "/Users/patrickcrawford/Library/Application Support/Blender/3.5/scripts/addons/MCprep_addon/addon_updater_ops.py", line 1360, in register
    from .conf import ENV
ImportError: cannot import name 'ENV' from 'MCprep_addon.conf' (/Users/patrickcrawford/Library/Application Support/Blender/3.5/scripts/addons/MCprep_addon/conf.py)

And some others.

Once we resolve these, I think it would be good to merge into the newly-assigned feature branch, so that other changes can be reviewed on their own.

@StandingPadAnimations
Copy link
Collaborator Author

StandingPadAnimations commented Apr 6, 2023 via email

@StandingPadAnimations
Copy link
Collaborator Author

Now that there's a milestone branch for 3.5, should we merge this branch?

@TheDuckCow
Copy link
Member

Now that there's a milestone branch for 3.5, should we merge this branch?

Let's fix the couple things mentioned where you missed first, and resolve the conflicts. I'll take one more quick look then, and then yes we can merge into the milestone branch.

I'm honestly not sure how I missed these, but good thing they were
caught. Now MCprep shouldn't be dealing with any errors related to env
now...
While removing the last of the ENVs, I noticed some deprecation warnings
regarding the use of this function, so I've went ahead and removed it.

Since this function calls other deprecated functions as well, what
should have been 1 warning was instead 3. Apologies to anyone who had to
suffer that in their terminal ;-;
In all honesty I doubt we'll get around to actually removing these
functions in 3.5.1, but since we're merging this with the 3.5 feature
branch, I think it's important to warn developers and make them think
about the eventual demise of these functions. Plus there's absolutely no
reason to use deprecated functions for 3.5 when we'll have nice features
like type annotations.

Anyway, hopefully after this commit, we'll merge this with the MCprep
3.5 feature branch *fingers crossed*
@StandingPadAnimations
Copy link
Collaborator Author

Alright, fixed the remaining uses of ENV and also removed the use of conf.load() in load_modules.py (I love the new deprecation warnings I've added). I've also updated the deprecation warning to say 3.5.1 (I'm 50% we'll just push back the removal, but at the very least we should start throwing around deprecation warnings)

@TheDuckCow just need some final checks on this to make sure everything is working as expected

For some reason the spawner was missing the use of env, causing errors.
While this has been fixed, it does illustrate an issue with the current
deprecation system in that deprecated stuff will error out. More
investigation is needed.
This feature was requested by TheDuckCow to make dev builds easier to
create. The idea is that a file is created by the compile scripts, and
MCprep checks for the files existence to determine which flags to
enable. This makes development a lot more convinient and removes the
need for commits that change the dev flag.

This does mean the MCprepEnv class no longer has arguments, but that's
fine. In the future we might be able to read the contents of the file to
give full control over what flags to enable.
Why? It allows us to determine if we're using a dev build or not
-d allows the creation of a dev build, by adding a new file called
mcprep_dev.txt to the outputed build folder.

-f replaces the -fast option and does the fast compile mode.
@StandingPadAnimations
Copy link
Collaborator Author

Alright I've now pushed the dev build feature to compile.sh. Just know that -fast has also now become -f

When running, an error occured due to log requiring the variables
verbose and very_verbose, which do not exist until afterwards. Now it's
been moved to after those variables have been set.
@StandingPadAnimations
Copy link
Collaborator Author

Ok I just realized that we also have #401, which makes this branch a bit weird (#401 is also based off of this). Should we merge this completely with recore or should we merge this with the milestone branch and then merge recore later on?

I'm leaning more towards the latter so that the changes are more incremental, but I want to know everyone's thoughts

@TheDuckCow
Copy link
Member

Ok I just realized that we also have #401, which makes this branch a bit weird (#401 is also based off of this). Should we merge this completely with recore or should we merge this with the milestone branch and then merge recore later on?

I'm leaning more towards the latter so that the changes are more incremental, but I want to know everyone's thoughts

It's not a problem, both can be merged into milestone-3-5-0, in whichever order (both will likely have a couple merge conflicts, so dealers choice which you want to deal with in which order). So I guess the latter of your two options is what I agree with. The sooner we merge this one though, the fewer problems we'll have. If we need to make future fixes, they can be branched off of the milestone-3-5-0 and PR-merged back into the same milesotne-3-5-0

@TheDuckCow TheDuckCow mentioned this pull request Apr 25, 2023
6 tasks
@StandingPadAnimations
Copy link
Collaborator Author

Closing this as this is no longer needed with #401

@StandingPadAnimations StandingPadAnimations deleted the internal-rewrites branch June 18, 2023 19:22
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.

Create env file for dev flag loading
2 participants