Skip to content
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

Not understanding pdoc import behavior #65

Closed
subsetpark opened this issue Aug 31, 2015 · 6 comments

Comments

Projects
None yet
2 participants
@subsetpark
Copy link

commented Aug 31, 2015

Here's a series of pdoc commands in a Django app that puzzle me:

git:develop@site[i]> pdoc my_app/
Module my_app
-----------
git:develop@site[i]> pdoc my_app/apps/
Module apps
-----------
git:develop@site[i]> pdoc my_app/apps/finance/
Module finance
--------------
git:develop@site[i]> pdoc my_app/apps/finance/models/
Traceback (most recent call last):
  File "/Users/zax/envs//my_app-site/bin/pdoc", line 458, in <module>
    module = imp.load_source('__pdoc_file_module__', fp, f)
  File "/Users/zax/mksp/site/my_app/apps/finance/models/__init__.py", line 1, in <module>
    from my_app.apps.finance.models.models_a import ModelA, ModelB, ModelC, ModelD, ModelF
ImportError: No module named my_app.apps.finance.models.models_a

I have an __all__ defined in finance.models.init.py, not that it ever gets there. First it tries to import the models in the first submodule, and fails. I am currently in the correct virtualenvironment; this is my normal development environment and I'm able to run the app, tests, and so on. What am I misunderstanding about how to structure things for pdoc?

@BurntSushi

This comment has been minimized.

Copy link
Contributor

commented Aug 31, 2015

I don't know. There really isn't enough information for me to go on. You'll need to do some debugging as to why your modules aren't visible. e.g., What happens when you run python -c 'import my_app.apps.finance.models.models_a' in your environment?

FYI, I don't know Django.

@subsetpark

This comment has been minimized.

Copy link
Author

commented Aug 31, 2015

It basically complains that the main django init script hasn't been run before trying to import its internals—which is obviously not great, but seems to be farther along than running pdoc from the CLI.

@BurntSushi

This comment has been minimized.

Copy link
Contributor

commented Aug 31, 2015

It basically complains

Can you please show the full output?

main django init script hasn't been run before trying to import its internals

pdoc needs to be able to import your modules in order to provide documentation. This only works if you're writing idiomatic Python (which shouldn't be doing anything on import). I don't know enough about Django to say whether this can be worked around.

@subsetpark

This comment has been minimized.

Copy link
Author

commented Aug 31, 2015

Hm - sorry, not really. It's a little too much commercial code and redacting all the names would make it a bit useless. But it's ok because that's a red herring. It hits a line that requires you to manually export an environment variable called DJANGO_SETTINGS_MODULE (that's what I alluded to above). If you do export that variable, then it imports normally:

git:develop@site[i]> python -c 'import my_app.apps.finance.models.models_a'
git:develop@site[i]>

Meanwhile, pdoc exhibits the same behavior:

git:develop@site[i]> pdoc my_app/apps/finance/models/
Traceback (most recent call last):
  File "/Users/zax/envs//my_app-site/bin/pdoc", line 458, in <module>
    module = imp.load_source('__pdoc_file_module__', fp, f)
  File "/Users/zax/mksp/site/my_app/apps/finance/models/__init__.py", line 1, in <module>
    from my_app.apps.finance.models.models_a import ModelA, ModelB, ModelC, ModelD, ModelF
ImportError: No module named my_app.apps.finance.models.models_a
@BurntSushi

This comment has been minimized.

Copy link
Contributor

commented Aug 31, 2015

I'm not sure. pdoc isn't doing anything special to load modules. It's just using standard Python import functions. The last thing I can think of is that pdoc wasn't installed into your virtualenv and that it's being invoked with a different Python interpreter. Try, for example, python $(which pdoc) while in your virtualenv. Or make sure that pdoc is installed in your virtualenv and that which pdoc reports the correct binary location. (If you don't have which, then use command -V.)

@subsetpark

This comment has been minimized.

Copy link
Author

commented Aug 31, 2015

Yeah, I wondered about that too - unfortunately you can see in the traceback that the version of pdoc being invoked is indeed in the virtualenv with everything else. And in the pdoc executable, the shbang points at the version of python in the virtualenv, too. Oh well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.