django-settings-file


Namedjango-settings-file JSON
Version 2.10.1 PyPI version JSON
download
home_pagehttps://github.com/adamchainz/django-settings-file
SummaryLet Django use settings from an arbitrary Python file instead of an importable module
upload_time2022-12-07 01:38:41
maintainer
docs_urlNone
authorAdam Johnson
requires_python>=3.7
licenseMIT
keywords django
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ====================
django-settings-file
====================

.. image:: https://img.shields.io/github/workflow/status/adamchainz/django-settings-file/CI/main?style=for-the-badge
   :target: https://github.com/adamchainz/django-settings-file/actions?workflow=CI

.. image:: https://img.shields.io/pypi/v/django-settings-file.svg?style=for-the-badge
   :target: https://pypi.org/project/django-settings-file/

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge
   :target: https://github.com/psf/black

.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=for-the-badge
   :target: https://github.com/pre-commit/pre-commit
   :alt: pre-commit

Unmaintained (2022-12-07)
-------------------------

I stopped maintaining this package as it has never been popular.
If you want to use the functionality I recommend copying the small amount of code into your project.

----

Let Django use settings from an arbitrary Python file instead of an importable module.

As per `James Pic's idea posted on the django-developers mailing list
<https://groups.google.com/forum/#!msg/django-developers/mzkwaGQtpOk/LZkxLUMwBQAJ>`_.

Requirements
------------

Python 3.7 to 3.11 supported.

Django 3.2 to 4.1 supported.

----

**Want to work smarter and faster?**
Check out my book `Boost Your Django DX <https://adamchainz.gumroad.com/l/byddx>`__ which covers many ways to improve your development experience.

----

Usage
-----

1. Install with ``python -m pip install django-settings-file``.

2. Edit your ``manage.py`` and ``wsgi.py`` to swap out Django's default logic for setting ``DJANGO_SETTINGS_MODULE`` to
   instead do:

   .. code-block:: python

       import django_settings_file

       django_settings_file.setup()

3. Add ``os.environ.setdefault('DJANGO_SETTINGS_FILE', '/path/to/default.py')`` before the ``setup()`` call, unless you
   can be sure ``DJANGO_SETTINGS_FILE`` will always be defined in your environment. You might need to figure out the
   path relative to your ``manage.py`` with some ``os.path`` manipulation.

4. Run it! If ``DJANGO_SETTINGS_MODULE`` is defined, it will raise a ``DjangoSettingsFileError`` with a message about
   how only ``DJANGO_SETTINGS_FILE`` is allowed now. If ``DJANGO_SETTINGS_FILE`` is not defined, it will also fail with
   a ``DjangoSettingsFileError`` with a message about defining it. Otherwise Django should start with the settings!

How it works
------------

``django-settings-file`` imports the contents of the specified file using the import machinery available on your Python
version (different logic for 2 and 3) and copies it contents into its own module, which Django sees as the settings
file defined via the traditional ``DJANGO_SETTINGS_MODULE``. Nothing about Django is really touched, it's just a
hacky module.

Caveats
-------

* If the Python file defined by ``DJANGO_SETTINGS_FILE`` tries to do any imports, the directory the file is in will not
  be on ``PYTHONPATH``, so the author of the settings file might get some surprises.
* Additionally, you might experience other problems from loading a file whilst it's not on ``PYTHONPATH``.
* If you want your settings file to extend another one, it will probably find it easiest to ``import`` the base one
  from a location on ``PYTHONPATH``, otherwise it too will have to do use the same import 'hacks' to load the default
  settings.
* File paths are not portable between operating systems, so you may need logic to support both Unix and Windows at
  once.
* File paths are not portable between ``.py`` and ``.pyc`` files. In most cases this means a ``.pyc`` file will not be
  used for settings since it can't be guaranteed to be there, slightly slowing down import time.
* ``DJANGO_SETTINGS_MODULE`` and ``DJANGO_SETTINGS_FILE`` can't both be used by the same project, since the module is
  required for the file-based logic. You might be able to allow them both with extra logic, pull requests accepted.
* ``¯\_(ツ)_/¯`` - this is kind of unknown territory, this library has not been tested in any real project, just with
  the example project in the test folder.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/adamchainz/django-settings-file",
    "name": "django-settings-file",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "Django",
    "author": "Adam Johnson",
    "author_email": "me@adamj.eu",
    "download_url": "https://files.pythonhosted.org/packages/3f/37/aecaa3d2b2a8eda0296118486c8ce752858f22a55761b151e9bc328af403/django-settings-file-2.10.1.tar.gz",
    "platform": null,
    "description": "====================\ndjango-settings-file\n====================\n\n.. image:: https://img.shields.io/github/workflow/status/adamchainz/django-settings-file/CI/main?style=for-the-badge\n   :target: https://github.com/adamchainz/django-settings-file/actions?workflow=CI\n\n.. image:: https://img.shields.io/pypi/v/django-settings-file.svg?style=for-the-badge\n   :target: https://pypi.org/project/django-settings-file/\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge\n   :target: https://github.com/psf/black\n\n.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=for-the-badge\n   :target: https://github.com/pre-commit/pre-commit\n   :alt: pre-commit\n\nUnmaintained (2022-12-07)\n-------------------------\n\nI stopped maintaining this package as it has never been popular.\nIf you want to use the functionality I recommend copying the small amount of code into your project.\n\n----\n\nLet Django use settings from an arbitrary Python file instead of an importable module.\n\nAs per `James Pic's idea posted on the django-developers mailing list\n<https://groups.google.com/forum/#!msg/django-developers/mzkwaGQtpOk/LZkxLUMwBQAJ>`_.\n\nRequirements\n------------\n\nPython 3.7 to 3.11 supported.\n\nDjango 3.2 to 4.1 supported.\n\n----\n\n**Want to work smarter and faster?**\nCheck out my book `Boost Your Django DX <https://adamchainz.gumroad.com/l/byddx>`__ which covers many ways to improve your development experience.\n\n----\n\nUsage\n-----\n\n1. Install with ``python -m pip install django-settings-file``.\n\n2. Edit your ``manage.py`` and ``wsgi.py`` to swap out Django's default logic for setting ``DJANGO_SETTINGS_MODULE`` to\n   instead do:\n\n   .. code-block:: python\n\n       import django_settings_file\n\n       django_settings_file.setup()\n\n3. Add ``os.environ.setdefault('DJANGO_SETTINGS_FILE', '/path/to/default.py')`` before the ``setup()`` call, unless you\n   can be sure ``DJANGO_SETTINGS_FILE`` will always be defined in your environment. You might need to figure out the\n   path relative to your ``manage.py`` with some ``os.path`` manipulation.\n\n4. Run it! If ``DJANGO_SETTINGS_MODULE`` is defined, it will raise a ``DjangoSettingsFileError`` with a message about\n   how only ``DJANGO_SETTINGS_FILE`` is allowed now. If ``DJANGO_SETTINGS_FILE`` is not defined, it will also fail with\n   a ``DjangoSettingsFileError`` with a message about defining it. Otherwise Django should start with the settings!\n\nHow it works\n------------\n\n``django-settings-file`` imports the contents of the specified file using the import machinery available on your Python\nversion (different logic for 2 and 3) and copies it contents into its own module, which Django sees as the settings\nfile defined via the traditional ``DJANGO_SETTINGS_MODULE``. Nothing about Django is really touched, it's just a\nhacky module.\n\nCaveats\n-------\n\n* If the Python file defined by ``DJANGO_SETTINGS_FILE`` tries to do any imports, the directory the file is in will not\n  be on ``PYTHONPATH``, so the author of the settings file might get some surprises.\n* Additionally, you might experience other problems from loading a file whilst it's not on ``PYTHONPATH``.\n* If you want your settings file to extend another one, it will probably find it easiest to ``import`` the base one\n  from a location on ``PYTHONPATH``, otherwise it too will have to do use the same import 'hacks' to load the default\n  settings.\n* File paths are not portable between operating systems, so you may need logic to support both Unix and Windows at\n  once.\n* File paths are not portable between ``.py`` and ``.pyc`` files. In most cases this means a ``.pyc`` file will not be\n  used for settings since it can't be guaranteed to be there, slightly slowing down import time.\n* ``DJANGO_SETTINGS_MODULE`` and ``DJANGO_SETTINGS_FILE`` can't both be used by the same project, since the module is\n  required for the file-based logic. You might be able to allow them both with extra logic, pull requests accepted.\n* ``\u00af\\_(\u30c4)_/\u00af`` - this is kind of unknown territory, this library has not been tested in any real project, just with\n  the example project in the test folder.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Let Django use settings from an arbitrary Python file instead of an importable module",
    "version": "2.10.1",
    "split_keywords": [
        "django"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "a3ca95e11d8c2a764daf7f75ecb15f66",
                "sha256": "312695f5c14e542dbe79842562437c448c5c6aa0f4478dfd12cee2e5283df996"
            },
            "downloads": -1,
            "filename": "django_settings_file-2.10.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a3ca95e11d8c2a764daf7f75ecb15f66",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5181,
            "upload_time": "2022-12-07T01:38:39",
            "upload_time_iso_8601": "2022-12-07T01:38:39.753175Z",
            "url": "https://files.pythonhosted.org/packages/0f/95/235e79c5c29ff30db4c4d5f76062416bd6c41ca8074b9775c9ebe8d5d8a0/django_settings_file-2.10.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "aa011ab648bdfd73e93b98bce02f3c49",
                "sha256": "608d43cc6017b3cec81270d8014f5eebe400239188fdb81499d922edf9ff47d4"
            },
            "downloads": -1,
            "filename": "django-settings-file-2.10.1.tar.gz",
            "has_sig": false,
            "md5_digest": "aa011ab648bdfd73e93b98bce02f3c49",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5719,
            "upload_time": "2022-12-07T01:38:41",
            "upload_time_iso_8601": "2022-12-07T01:38:41.668512Z",
            "url": "https://files.pythonhosted.org/packages/3f/37/aecaa3d2b2a8eda0296118486c8ce752858f22a55761b151e9bc328af403/django-settings-file-2.10.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-07 01:38:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "adamchainz",
    "github_project": "django-settings-file",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "django-settings-file"
}
        
Elapsed time: 0.01740s