-
Notifications
You must be signed in to change notification settings - Fork 170
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
Custom module import behavior (support for Django) #28
Comments
Ugh, modules that raise errors at import time :) Yeah, I think we need some way to inject this kind of setup. I'm not sure about wrapping every call to We could just add a config method called something like |
Makes sense, yeah. Opened a PR based on your comment. |
Fixed with merge of #29. |
Using
I get stuck at Instead, what is working is simply having this as my
|
Looks like the PR that added monkeytype autoimports monkeytype_config.py, so |
Thanks for the report, and sorry for the confusion! I've updated the ReadTheDocs config so the default version of the docs is the last tagged release, instead of the last commit. And I'll make a new release today with |
Version 17.12.3 is released, with |
Running monkeytype against a file with Django models or dependencies on Django apps gives me a series of errors.
First, just
monkeytype apply package.app.models
:Second,
DJANGO_SETTINGS_MODULE=config.settings.local monkeytype apply package.app.models
:Third, adding
to the top of package.app.models:
What has worked for me is patching
monkeytype/cli.py
andmonkeytype/util.py
to addObviously this isn't suitable as-is because it breaks monkeytype on non-Django codebases. However, it did give me the idea to have an
ModuleImporter
(name WIP) context manager that returnsimportlib.import_module(module)
but may also perform pre-/post-import actions. It would work similarly to TypeRewriter: the default implementation could justimport_module
, but a DjangoModuleImporter could calldjango.setup()
, and the specific ModuleImporter could be configured in settings.Thoughts? Happy to submit a PR for this if you think it's the right direction.
The text was updated successfully, but these errors were encountered: