-
Notifications
You must be signed in to change notification settings - Fork 182
feat: Allow setting the working directory for plugin invocation #6409
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
Conversation
👷 Deploy request for meltano pending review.Visit the deploys page to approve it
|
👍 I like the idea, a @aaronsteers curious how you feel about this ? |
root = alternate_cwd_plugin_invoker.project.root | ||
assert alternate_cwd_plugin_invoker.cwd() == root / "path" | ||
assert alternate_cwd_plugin_invoker.cwd(command="relative") == root / "path2" | ||
assert alternate_cwd_plugin_invoker.cwd(command="absolute") == Path("/root") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heads up - we run tests on windows now as well, which are currently failing:
https://github.com/meltano/meltano/runs/7313447720?check_suite_focus=true#step:9:648
_________________________ TestPluginInvoker.test_cwd __________________________
self = <test_plugin_invoker.TestPluginInvoker object at 0x000001DAA9868310>
alternate_cwd_plugin_invoker = <meltano.core.plugin_invoker.PluginInvoker object at 0x000001DAADEFCBB0>
def test_cwd(self, alternate_cwd_plugin_invoker):
root = alternate_cwd_plugin_invoker.project.root
assert alternate_cwd_plugin_invoker.cwd() == root / "path"
assert alternate_cwd_plugin_invoker.cwd(command="relative") == root / "path2"
> assert alternate_cwd_plugin_invoker.cwd(command="absolute") == Path("/root")
E AssertionError: assert WindowsPath('C:/root') == WindowsPath('/root')
E + where WindowsPath('C:/root') = <bound method PluginInvoker.cwd of <meltano.core.plugin_invoker.PluginInvoker object at 0x000001DAADEFCBB0>>(command='absolute')
E + where <bound method PluginInvoker.cwd of <meltano.core.plugin_invoker.PluginInvoker object at 0x000001DAADEFCBB0>> = <meltano.core.plugin_invoker.PluginInvoker object at 0x000001DAADEFCBB0>.cwd
E + and WindowsPath('/root') = Path('/root')
D:\a\meltano\meltano\tests\meltano\core\test_plugin_invoker.py:184: AssertionError
@rabidaudio - Love this direction and I agree the feature can be very helpful. I may want to hold while we settle the spec here but hopefully not leaving you in a holding pattern for long. A few thoughts come to mind:
@pandemicsyn, @rabidaudio, @tayloramurphy, @pandemicsyn - Penny for your thoughts. Thanks! 😄 |
src/meltano/core/plugin/dbt/base.py
Outdated
def cwd( | ||
self, command: Optional[str] = None, env: Optional[dict] = None | ||
) -> Optional[Path]: | ||
return ( | ||
super().cwd(command=command, env=env) or self.plugin_config["project_dir"] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superceding my prior comment about cwd
replacing the project_dir
setting of dbt, I see here that yes, absolutely this appears to replace that functionality - and I like that we're doing it in a generic way for all plugins, which would not require special per-plugin logic internally within Meltano.
Also - Thanks for keeping this backwards compatible. As much as I like the generic approach, we also don't want this to break existing dbt capabilities/behaviors.
I agree, I think I like |
@aaronsteers @rabidaudio I like this proposal and excited about the PR. Responding to AJ's points:
I don't agree that it should auto-register itself in
All that said, I agree with the spec that users should be able to set Question: Would env var expansion in the commands work as well such that: utilities:
- name: dagster
namespace: dagster
pip_url: -e orchestrate
executable: dagster
workdir: orchestrate # also supports variable expansion, e.g. $MELTANO_PROJECT_ROOT/orchestrate although that's redundant
commands:
test:
executable: pytest
workdir: $MELTANO_UTILITY_WORKDIR/tests would evaluate to Perhaps that's a separate, larger issue on if and how commands are dealing with environment variables. |
@tayloramurphy - Thanks! Yeah, sounds like we are agreed on most points. A couple thoughts on the points you raised:
Agreed. 👍 From the diff here, I think we are moving in the right direction, which will helps us towards #6130 because it removes/de-emphasizes the custom dbt behavior in favor of this more generic approach.
To confirm, all I meant here is that if the remote plugin definition (on the hub, for instance) is defining a custom For plugins which do not require a custom
In that case (and if resolution order permits it), dbt's Optional: For extra stability to the plugin developer, we might consider also populating @rabidaudio - No need to tackle everything in the above in a first iteration but I'm curious your thoughts on these points. For my part, the only things I see as strictly required are (1) agreement on the field name ( Have you seen the new process regarding integration tests? Adding this functionality to an existing integration test, or writing a new one would be super helpful. Let us know if you feel comfortable adding yourself or if you'd like assist from a team member on that. |
Ah ok, makes sense 👍
I quite like that! Basically just have it as a default property of every plugin than can be overridden. Nice idea @aaronsteers 😄 |
My thought was doing things like |
I like this too. Two concerns:
|
Codecov Report
@@ Coverage Diff @@
## main #6409 +/- ##
==========================================
+ Coverage 88.97% 89.08% +0.11%
==========================================
Files 276 277 +1
Lines 19559 19753 +194
Branches 1927 1947 +20
==========================================
+ Hits 17402 17597 +195
+ Misses 1829 1826 -3
- Partials 328 330 +2
|
Thanks for calling this out! It's a really good point and based on your points above, I withdraw my suggestion :) - specifically on the basis that the working directory will often need to match the shell directory. For example, if invoking sqlfluff on a specific file in the shell's directory (e.g. I'll think on this a bit more, but per the above, it makes sense to only have an explicit |
@aaronsteers @rabidaudio what's the status on this? Keen to get it in 😄 |
@tayloramurphy AFAIK this ready to go. We may want to add some documentation, not sure where is best for that as it's more for plugin creators than end users. |
@rabidaudio it might be good to update the JSON schema in |
@rabidaudio, @tayloramurphy - It looks like we still need a docs entry and some CI tests are not passing.
@cjohnhanson - If any of the above need assist, would you be able to jump in? |
@cjohnhanson - As discussed, feel free to jump in on the above to get this over the line - as time permits. |
Hey @rabidaudio - I'm going to close this as we're not going to have time to get this over the finish line ourselves. AJ's comment here has a good summary of what it would take to get this over the line. We'd still love to have this in but seeing as it isn't a priority for Cloud we're going to make the tough call to close it for now. |
Hello folks!
I really wanted to set up Dagster with a
test
command that runs pytest on the project:However, despite setting
--rootdir
in thepytest
args, pytest insisted on picking up tests andconftest.py
files from elsewhere in our project, liketransforms/dbt_modules
.I figured it made sense to allow plugins and commands to define a working directory to be invoked in, instead of the current working directory:
This simplified
DbtPlugin
, as it no longer needs a customPluginInvoker
, it just needs to set the cwd to the project directory. This could be further simplified if we defined it in the discovery configuration, but to avoid backward compatibility issues I explicitly implemented the method.This could use some docs, but wanted to get y'alls thoughts first.