Closed Jojain closed 3 years ago
I had some strange behavior doing more of an automatic monkey-patch with the first draft of the repo, but only after the plugin was installed via pip from the repo. I was using __init__.py
though and so that was probably most of the problem. I've also heard several times from the community that "explicit is always better than implicit." That was in regards to the CQGI interface, so it's not an apples to apples comparison, but that is what was on my mind when I created the register function. At that point, the user is acknowledging that "yes, I'm ok with the plugin changing CadQuery's behavior".
With that said, if we're going to remove the register function call and can make automatic patching work consistently, now is the time to do it before we get a bunch of community contributions.
To be honest I don't know much about class extension, so if what I proposed isn't working consistently then register function is nice. About the user acknowlegment I would assume that since cadquery-plugins aims to be the official plugins list it would be implied by the import call of the plugin that you accept the behavior changes. But in the end I don't really have problem with the register function, it was more out of curiosity, thanks !
It might be somewhat annoying if you have more plugins. @jmwright do you have more info on the issue?
It might be somewhat annoying if you have more plugins. @jmwright do you have more info on the issue?
Do you mean it will be annoying if you have more plugins that have to be registered manually?
When I was auto-patching into Workplane using __init__.py
, it worked fine locally, but I got a make_cubes does not exist in Workplane
error after the plugin was installed via pip. I'm pretty sure that it's because the __init__.py
of each module is evaluated in an order that we don't control. If the one you're monkey-patching in isn't in the correct order, the patch doesn't work. I'll try what @Jojain suggested tomorrow by simply placing the patch statement at the end of the module being imported and do some testing to make sure it works consistently.
@Jojain I refactored the plugin structure and docs in #8 to do as you have suggested, removing the need for the register
function. The readme now tells users to be sure to import cadquery first.
@Jojain Why did you reopen? Is there something that still needs to be addressed?
No it's alright I missclicked
I was asking myself why we need to define a register function in our plugins ? Putting the code of the function at the end of the module would link directly the plugins to the Workplane class (but we would need to be sure the plugin import is place after the cadquery import)
Is there another reason to use the register function that I don't see ?