Moo-Ack-Productions / bpy-build

A build sytem to make building Blender addons 10 times easier
BSD 3-Clause "New" or "Revised" License
5 stars 2 forks source link

Proposal: Rewriting in Rust #5

Closed StandingPadAnimations closed 9 months ago

StandingPadAnimations commented 1 year ago

As it stands, bpy-build's code is pretty... horrifying, and Python's standard library for file operations and CLI tools is not the best. Also, bpy-build is written to depend on Python 3.7 (since Blender 2.8 uses Python 3.7), which limits what we can do. In addition, I'm not the biggest fan on how Python libraries in general depend on very "dictionary-like" syntax. I also have a hard time understanding the code, and I wrote bpy-build.

Proposal: rewriting bpy-build in Rust. The reason for Rust is because Rust libraries are much better to deal with, and the build system is really easy (just cargo build). Rewriting in Rust would have the following benefits:

The main disadvantages however would be:

For now I'll make a separate branch with the Rust rewrite, and let developers use it optionally, until we decide further on whether or not to fully replace bpy-build.

TheDuckCow commented 1 year ago

Just copying over my comments from discord - apologies if this comes across wrong, I'm just trying to be direct:

As-is, I'm not really supportive of this move. I suppose you could argue there is little harm in building the system for us to later try and compare between the two, but as it stands I don't think the upsides are worth it (and would be wasted time, that could be put towards actual user-facing problems). Responding to the Pro's above:

The Pro arguments above are all pretty subjective in my mind:

More readable code

Less headaches from Python libraries

Independence from Python version

The clap crate in Rust can generate tab completions, improving the CLI experience

Performance (though minor in this case)

Easily maintainability

As for the Cons, agree there - even if github actions works, it's still a whole lot of extra complexity and steps to maintain and manage for something that could just be a simpler solution. Remember, the original idea was actually to use make commands, but they were just barely not convenient enough to work with. I feel this would be swinging way too far in the other direction.

In the end, this is meant to build the addon in a cross compile way. Aside from some minor initial development fixes we are making around relative pathing, it basically does what we need and with minor to modest effort, can be extended to do more as needed in the future. But rewriting in rust seems like it would be a large amount of effort that would be better spent elsewhere, and an equal if not outsized ongoing effort to maintain that make this not worth the benefits it would provide.

I'm happy to discuss further, but wanted to be candid with how I feel about it at this stage.

StandingPadAnimations commented 1 year ago

I'll clarify on the reasons why I'd prefer a Rust version, but I have some proposals to improve the development experience of the Python bpy-build should we decide against a Rust version.

Clarification on Rust

Performance overhead isn't the issue with libraries, the main headaches with libraries in Python are:

In addition, bpy-build uses the standard library for most operations, only using external dependencies for the following:

  • Nice, but feels quite minor - and I suppose it depends on the CLI? (unless are we talking about being having to enter an interactive rust environment? I would find that rather annoying and would end up writing wrapper scripts anyways to build).

The current way bpy-build does CLI arguments is docopt (the cli parsing option I liked the most at the time), which has issues:

Bpy-build in my opinion requires a rewrite regardless (despite being extremely new software), even if we decide not to go with Rust, as it's already extemely verbose. Looking for the issue related to Zip file structure for instance took multiple weeks on my end due to certain confusing aspects related to shutil, and I haven't seen much better libraries for zipping files. In my opinion, the effort needed to debug a Python bpy-build (one bound to Python 3.7 as the minimum version) would be far greater then writing and maintaining a Rust version.

Python

All that being said, if we decide to not go ahead with a Rust version, I feel the following would need to be done with bpy-build to make it less of a headache to develop:

Edit: Clize might be a good replacement for docopt

StandingPadAnimations commented 1 year ago

Here's the timeline for the rewrite (either Rust or Python, that'll still be open for discussion)

StandingPadAnimations commented 1 year ago

Alright based on how quiet this thread is, I'll start a Python rewrite, with Python 3.9 as the base

StandingPadAnimations commented 1 year ago

Alright I've pushed a base commit for all rewrites and added a Mypy config, with the following config:

Is it stricter then what most developers are used to? Yes Would it prevent errors related to dynamic typing and make bpy-build more reliable? Also yes

I'll be making a contributer guide later this week

TheDuckCow commented 1 year ago

Any changes that would yield differences for the MCprep repo? Or are these just incremental updates/rules.

Asking as, we've not even fully rolled out the current build version for MCprep, so if you're rewriting already (not that I think that's the best use of time..), should we just already adopt the new way before pushing others like zNight to get used to the current system?

StandingPadAnimations commented 1 year ago

The rewrite will impact configuration (YAML to TOML is planned, though now I'm playing around with YAML format improvements, particurally with during-build actions), but otherwise share the same CLI interface, so transitioning will be very minimal for the average developer.

(not that I think that's the best use of time..)

I'm not really a big fan of how verbose things have gotten, among other issues (especially with configuration), hence why this rewrite.

TheDuckCow commented 1 year ago

Ok, I can certainly appreciate that and definitely support trying to reduce complexity. Thanks for taking it on and I'll be happy to review whenever something is ready (just be aware I may take a couple days at any given point to get to a code review, I sometimes need to take a break from code reviews after doing them all day!)