Skip to content

Conversation

GoToLoop
Copy link
Contributor

@GoToLoop GoToLoop commented Sep 16, 2025

This is the "thonnycontrib/backend/py5_imported_mode_backend.py" cleanup.

However, after some testings, I've concluded this file can be deleted and it won't change the plugin's behavior!

Basically, this file adds 'from py5 import *\n' to a py5mode sketch.
But it seems like library py5 is somehow already doing that!

Therefore, my advice is to fully delete this "backend" folder from this plugin project!

#89

@hx2A
Copy link
Collaborator

hx2A commented Sep 17, 2025

There's no need to prepend the user's code with from py5 import * because the run sketch utility does that for you. Did you test it with this removed? If it is fine without it, we should get rid of it.

Also, I'd rather not merge this until after the next release. I don't want to merge non-critical things until we test the release and push it to pypi.

@GoToLoop
Copy link
Contributor Author

GoToLoop commented Sep 17, 2025

Also, I'd rather not merge this until after the next release.

As I have already stated, these pull requests belong to ongoing type hint fix refactoring batches.

They're not supposed to be merged right now.

Did you test it with this removed?

Yup! File renamed, removed, purposefully typing wrong Python syntax to crash the file, etc.

For all those experimental cases, p5mode plugin kept working normally w/ no apparent changes on its behavior!

Seems like we don't need a Thonny backend hack anymore. :D

@hx2A
Copy link
Collaborator

hx2A commented Sep 17, 2025

Also, I'd rather not merge this until after the next release.

As I have already stated, these pull requests belong to ongoing type hint fix refactoring batches.

Yes, and this PR is appreciated and is helpful. We also need to test the latest release candidate. Once we do a test of the release candidate on each OS we can do a release. I was hoping you and @villares could do the testing here since both of you use the plugin much more than I do. When you and @villares let me know the release candidate works fine on each OS we will be ready.

Seems like we don't need a Thonny backend hack anymore. :D

I'm fine with removing it but am reminded of Chesterton's Fence. Why was that code added in the first place? I feel like we are missing something.

@GoToLoop
Copy link
Contributor Author

GoToLoop commented Sep 17, 2025

Why was that code added in the first place?

https://github.com/py5coding/thonny-py5mode/blob/0.4.6-alpha/thonnycontrib/backend/py5_imported_mode_backend.py#L32-L34

    prefix = 'from py5 import *\n'
    cmd['source'] = prefix + cmd['source']
    cmd['row'] += 1

From the excerpt above, I believe it's just a hack to add 'from py5 import *\n' at the top of a sketch.

But given run_sketch() already does that, we should get rid of this backend; given it hacks class MainCPythonBackend for all Thonny addons!

@GoToLoop
Copy link
Contributor Author

GoToLoop commented Sep 17, 2025

I was hoping you and @villares could do the testing here

Well, I'm testing on my Arch-based Linux distro Garuda. 🐧
@villares can test on Windows. And some times, he has access to MacOS.

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