Comments (6)
see my edited answer
from mkautodoc.
hi @cw-intellineers @tomchristie
where would you call django.setup()?
because I have DJANGO_SETTINGS_MODULE filled but if:
- I don't put django.setup(), I have the error "django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet."
- i put django.setup() [I've not found any other "entrypoint" who can be customized for mkdocs] I get some weird error on circular imports on django-extensions field
ImportError: cannot import name 'CreationDateTimeField' from partially initialized module 'django_extensions.db.fields' (most likely due to a circular import)
Can you help me? I'm lost.
Thanks
from mkautodoc.
I guess you’d need to set the DJANGO_SETTINGS_MODULE environment variable, before running mkdocs?
from mkautodoc.
Okay, apparently I was stupid and while debugging changed my .env file...stupid me...
Thanks for the help.
from mkautodoc.
🤷♂️ Sorry I don’t know - not something I’m really able to help with.
from mkautodoc.
So … I came across this, and ended up with a workaround I'm so ashamed of I'm starting to be proud of it.
I created a file in docs/django_settings.py, which contains the settings I want to initialize with, as well as a call to django.setup() after said settings, and a dummy variable I called setup
:
import os
import sys
docs_dir, _ = os.path.split(__file__)
sys.path.append(os.path.dirname(docs_dir))
SECRET_KEY = "."
INSTALLED_APPS = ["…"]
setup = None
import django # noqa
from django.apps import apps # noqa
from django.conf import settings # noqa
if not apps.ready and not settings.configured:
django.setup()
I'm setting DJANGO_SETTINGS_MODULE
to docs.settings, which in theory should be enough, but it actually isn't: Depending on the piece of code that is being autodoc'd, the import cycle can sometimes erroneously detect a circular import and raise an ImportError due to partially initialized module. One such example would be:
- Document
::: library.module.SomeClass
- From library.module, import a django setting
- django.setup() is called, which goes through importing every
INSTALLED_APP
's models.py - From
library.models
, importlibrary.module
- We're now in a circular import (even though we really aren't)
So to fix that, django.setup() would have to be called as the first thing autodoc does, so that we don't cycle back to the code that called the setting; usually that is done in the entrypoint. But autodoc doesn't have an entrypoint… soooo, I made one by adding the following code to my index.md:
<style type="text/css">
/* Hide the hack signature from the index. */
.autodoc { display: none; }
</style>
::: docs.django_settings.setup
Now as one of the first things autodoc does (as part of the first document it processes), mkautodoc will import the docs.django_settings module, which will trigger django.setup() and avoid breakage later on.
from mkautodoc.
Related Issues (18)
- Support module documentation HOT 5
- Table rendering HOT 19
- TOC from rendered docs?
- Docstrings aren't rendered at all HOT 1
- :members: : select all, except the one specified HOT 2
- Feature: Format using Sphinx docstring format HOT 2
- Mock imports HOT 1
- Support for different docstring styles? HOT 1
- Which docstring style is supported? HOT 1
- Docstring format supported ? HOT 2
- mkautodoc does not support trio library
- Incompatible with prettier. HOT 1
- Please clarify copyright and licence HOT 2
- Incompatible with markdown >=3.4
- Failed to load extension 'mkautodoc' HOT 1
- Question: must docstrings be written in markdown? HOT 1
- Support references HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mkautodoc.