Hi Team! This might be more of a Pylance question,...
# ask-metaflow
g
Hi Team! This might be more of a Pylance question, but run into it while using Metaflow Extensions so wanted to ask it here. I'm creating a new Metaflow Extension for our internal company's use. I was able to create the extension and import from metaflow, but Pylance cannot resolve the dependency. Took a glance at how Metaflow adds extensions to the main library, and I believe it has to do with the dependencies not being in the actual module, but rather getting loaded later. While this is not an actual issue, I wanted to ask if anyone has run into this before and if so, how did you solve it? 😢
✅ 1
d
you can generate stubs that are specific for your extension. Once you have everything installed, you should be able to do:
metaflow develop stubs --help
to see available options.
You should have one to install stubs
that hsould then help pylance figure things out
let me know if that works or not. It’s not always straightforward to get everything working properly. IIRC, pylance wasn’t following what my interpretation of the spec was but for most cases it should work.
g
It worked! Thank you for your help! 🙂
d
great!
(note if you distribute your extension internally, you can pre-build the stubs package and distribute that as well; that’s what we do).
thankyou 1
g
Do you have an example of how you package the pre-built stubs together? 🤔 The stubs get stored into the virtual env that I use to run the command, so I'm unsure on how to best package them with the extension
d
we just build the stubs package when releasing (something like this;
${my_python} -c "from metaflow.cmd.develop.stub_generator import StubGenerator; StubGenerator('./metaflow-stubs').write_out()"
That is then used to create a package
my-mf-extension-stubs
and then we have something like this in
my-mf-extension
Copy code
extras_require={
        "stubs": ["my-mf-extension-stubs==%s" % version],
    },
So then you can install
my-mf-extension[stubs]
to get the optional stubs. You could also choose to make it a part of the requirements (and not an
extra_require
)
g
Awesome! Thank you for your help! 🙂