Package: django-microscope
Author:Keryn KnightVersion:0.1.1Convert aDjangoapp into a standaloneDjangoproject so you can run it
independently as a microservice or what-have-you.Configuration options given torun()are defaults, and may be replaced by
environment variables thanks todjango-environIf your app crosses boundaries into another application via imports, you should
hopefully get warnings. Figuring out how to do that was mostly why I did this. I’d
never encounteredsys.meta_pathbefore.AlternativesIf you’re starting anewapp and want the proper micro experience, you
maybe wantdjango-microinstead. It has magic involved too, but different magic!UsageCreate yourself amanage.pyfile in your app’s folder (eg: where yourviews.py,models.pyare) and do something like this…frommicroscopeimportrunfromdjango.conf.urlsimporturl# or path etc.defurls():frommyapp.viewsimportMyViewreturn[url('^$',MyView.as_view())]application=run(DEBUG=True,ROOT_URLCONF=urls)Running itIt’ll probably work, right?python manage.py [command]should all be OK.
You could probably go even more minimal withdj-cmdso you can dodj rGunicorngunicorn manageandgunicorn manage:applicationshould both work fine,
as shouldDEBUG=0 gunicorn manageto change the setting by env-var.UWSGIWhatever madness of command-line arguments or ini configuration invokes uwsgi for
you probably works; eg:uwsgi--http:8080--wsgi-file`pwd`/manage.py--virtualenv$VIRTUAL_ENVEnvironment variables should be fine?mod_wsgiIt’d probably work, but environment variable substitution for settings won’t work
at all, I don’t think.URL configurationtheROOT_URLCONFhas to be a callable (function or object implementing__call__)
to defer execution of imports related to userland code, which almost certainly
depends on settings having already been configured. It’s also because
your existingurls.pyfor the app may not be where you want the mountpoints
when running it standalone vs as part of a monolith project.You’ll eagerly get anImproperlyConfiguredexception when starting the app, if yourROOT_URLCONFis missing or not-callable.Don’t worry, it’s only called at startup, not on every request!If youdowant to use another file,microscope.urlconf('dotted.path.to.urls')may helpfrommicroscopeimportrun,urlconfapplication=run(ROOT_URLCONF=urlconf('path.to.urls'))TestsLiterally none. If you havehonchoyou can dohoncho-fdemo_project.procfile startto start thedemo_project.py(equivalent ofmanage.py) usingrunserver,gunicornanduwsgion ports8000,8001and8002respectively.The licenseIt’s theFreeBSD. There’s should be aLICENSEfile in the root of the repository, and in any archives.Copyright (c) 2018, Keryn Knight
All rights reserved.Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.Change history for django-microscope0.1.1Initial release