Skip to content

Use python module dynamic imports for getting app modules #7

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

Merged
merged 2 commits into from
Apr 21, 2015

Conversation

georgebrightinteractive
Copy link
Contributor

Using get_app requires apps to have a models module even though this is not required anymore

Fixes #6

Using get_app requires apps to have a models module even though this is not required anymore

Fixes #6
dirname = os.path.dirname(module.__file__)
ret.extend(get_coverage_files_in_directory(dirname, ignore_dirs, ignore_files))
if app_label in settings.INSTALLED_APPS:
module = __import__(app_label, fromlist=[''])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.python.org/2/library/functions.html#__import__ recommends against using __import__ in everyday Python programming in favour of importlib.import_module().

If you do need to use it (not sure if importlib.import_module() is available in Python 2.6) then it might make sense to pass globals(), locals(), [], -1) to it like the examples in the above link do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the __import__call to include globals() and locals(). You will probably see that I'm not using the [] in the call. That's because in case of dotted imports, using [] instead of [''] returns the base module.

PS. Not using importlib since it's py2.7 and over

georgebrightinteractive added a commit that referenced this pull request Apr 21, 2015
Use python module dynamic imports for getting app modules
@georgebrightinteractive georgebrightinteractive merged commit 144988a into master Apr 21, 2015
@georgebrightinteractive georgebrightinteractive deleted the issue6.no_model_apps branch April 21, 2015 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test extras coverage doesn't work for apps with no models
2 participants