You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
It should be easier to extend commands provided by spin #242
NumPy defines a spin build command, which has fallen out of sync from the upstream meson.build command it uses. Reading the click docs, it seems like the pattern NumPy is using with ctx.forward is frowned upon.
I think it would be better if spin provided factories for click commands to make it easier for projects to extend upstream commands without having to effectively re-implement their API.
NumPy would just use the upstream spin.cmds.meson.build command provided by spin, but it needs to add one keyword argument to build, with_scipy_openblas. So it defines a new command with the signature
This is missing both build_dir and gcov as arguments that are in the upstream command. You might think that because NumPy's spin command accepts **kwargs, if someone passed in gcov, then click or spin would just forward the command, but that's not how it works:
goldbaum at Nathans-MBP in ~/Documents/numpy on fix-generic-fancy-index-cast!
± spin build --clean --gcov
Usage: spin build [OPTIONS] [MESON_ARGS]...
Try 'spin build --help' for help.
Error: No such option: --gcov
If you look at the docstring for numpy's build command, you'll also see that it's missing a bunch of stuff that's in spin's spin.cmds.meson.build command.
So to update NumPy's spin build command to match the features provided by upstream, someone is going to need to manually update the build function and docstring in NumPy. Or more likely forget to update it, as has happened, particularly to the docstring.
I also found that I needed to patch NumPy's spin config in order for NumPy to benefit from #241, because without an explicit --prefix override in NumPy, click doesn't pass --prefix to spin's command.
IMO it would be better if spin itself could provide a command factory that accepts some sort of structure that defines a keyword argument and associated docstring, and then spin builds the command function and corresponding docstring as is needed. That would also allow better customization, for example if a built-in argument like --gcov doesn't make sense for some project: a command factory would allow a project to ask the factory to not include --gcov.
changed the title [-]It should be easier to subclass commands provided by spin[/-][+]It should be easier to extend commands provided by spin[/+]on Nov 12, 2024
Since you may want to do pre and postprocessing, before running the existing command, you will likely still need ctx.forward. The docs say you should be careful when using it, but we use it in the correct setting.
So, perhaps the need here is to be able to forward flags, without knowing about them at the time of authorin? I think that can be accomplished by something like:
Yeah I think that would be perfect! I'd love to delete the docstring in numpy's build command and I think this way we'd get updates "for free" whenever spin updates.
Activity
stefanv commentedon Nov 8, 2024
@ngoldbaum Could you expand on the suggestion here? I read the S/O post, but I'm not sure what you mean to highlight there.
We've modified all spin commands to use keyword-only arguments, so you should be "forward compatible" with newer versions of commands.
ngoldbaum commentedon Nov 12, 2024
NumPy would just use the upstream
spin.cmds.meson.buildcommand provided by spin, but it needs to add one keyword argument tobuild,with_scipy_openblas. So it defines a new command with the signatureThis is missing both
build_dirandgcovas arguments that are in the upstream command. You might think that because NumPy's spin command accepts**kwargs, if someone passed ingcov, then click or spin would just forward the command, but that's not how it works:If you look at the docstring for numpy's
buildcommand, you'll also see that it's missing a bunch of stuff that's in spin'sspin.cmds.meson.buildcommand.So to update NumPy's
spin buildcommand to match the features provided by upstream, someone is going to need to manually update thebuildfunction and docstring in NumPy. Or more likely forget to update it, as has happened, particularly to the docstring.I also found that I needed to patch NumPy's spin config in order for NumPy to benefit from #241, because without an explicit
--prefixoverride in NumPy, click doesn't pass--prefixto spin's command.Ultimately, as I understand it, this is because we use
ctx.forward, which thespindocs advise against ("this pattern is generally discouraged"): https://click.palletsprojects.com/en/stable/advanced/#invoking-other-commandsIMO it would be better if spin itself could provide a command factory that accepts some sort of structure that defines a keyword argument and associated docstring, and then spin builds the command function and corresponding docstring as is needed. That would also allow better customization, for example if a built-in argument like
--gcovdoesn't make sense for some project: a command factory would allow a project to ask the factory to not include--gcov.[-]It should be easier to subclass commands provided by spin[/-][+]It should be easier to extend commands provided by spin[/+]stefanv commentedon Nov 12, 2024
Since you may want to do pre and postprocessing, before running the existing command, you will likely still need
ctx.forward. The docs say you should be careful when using it, but we use it in the correct setting.So, perhaps the need here is to be able to forward flags, without knowing about them at the time of authorin? I think that can be accomplished by something like:
Would that cover your use-cases? This way, you can still swallow the
gcovflag if you want.ngoldbaum commentedon Nov 12, 2024
Yeah I think that would be perfect! I'd love to delete the docstring in numpy's
buildcommand and I think this way we'd get updates "for free" whenever spin updates.Add mechanism for extending existing spin commands
Add mechanism for extending existing spin commands
Add mechanism for extending existing spin commands (#248)