django-settings-diff
A very simple tool to help diff two Django settings modules.
Motivation
Let’s say that you have done some significant refactoring to your settings module. For example, you have gone from a single settings file to a modular approach, where there is no longer a single settings.py. You want to make sure that your settings are effectively exactly the same as before, though! Of course you can’t rely on simple file diffing, since there is no longer a single settings.py.
There are some non-intuitive things to account for, which django-settings-diff handles for you:
Even with a single settings.py, there is a (potentially) significant difference between simply importing the file and the “final” settings that are used by Django (see https://docs.djangoproject.com/en/2.1/topics/settings/#using-settings-in-python-code). That is, we want to compare the actual settings at runtime!
The settings object cannot be naively treated as a dict – it is similar, but different enough to prevent easy diffing (the native settings object thwarts both pprint and deepdiff).
So, it isn’t doing anything crazy, but it removes some overhead.
Installation
Install from pip (recommended):
$ pip install django-settings-diff
Or, install straight from the repo:
$ git clone https://github.com/GreenBankObservatory/django-settings-diff $ pip install django-settings-diff
Note that this will install a wrapper script for you: diffsettings
Entry Points
Use the wrapper script (recommended):
$ diffsettings -h
Call the module:
$ python -m django_settings_diff -h
Import as library:
$ python >>> from django_settings_diff import diffsettings >>> help(diffsettings)
Usage
There are two standard usage patterns.
You should first ensure that you have saved two versions of your settings. For this example we will use myapp/settings_old.py and myapp/settings_new.py.
Alternatively, you could use the same DJANGO_SETTINGS_MODULE for both dumps, but swap the settings file itself in between. This is useful in repositories that rely on the settings file being a specific name, for example.
#1: Compare Python objects directly
This uses deepdiff internally to perform the diff.
Dump Settings
Pickle the settings modules to disk:
$ DJANGO_SETTINGS_MODULE=myapp.settings_old diffsettings --dump old_settings.pkl $ DJANGO_SETTINGS_MODULE=myapp.settings_new diffsettings --dump new_settings.pkl
Diff Settings
Now we can diff the two settings objects:
$ diffsettings old_settings.pkl new_settings.pkl
See the documentation for deepdiff for help deciphering the output.
#2: Compare via external diff tool
In this method the settings are dumped as text files and then compared using a standard diff tool.
Dump Settings
Dump the settings modules to disk (internally this uses pprint to print the settings object):
$ DJANGO_SETTINGS_MODULE=myapp.settings_old diffsettings --dump old_settings.txt $ DJANGO_SETTINGS_MODULE=myapp.settings_new diffsettings --dump new_settings.txt
Diff Settings
Then, use your favorite diff tool to compare these. This should work quite well, since the object hierarchy has been broken up line by line.
For example:
$ tkdiff {old,new}_settings.txt
Metadata
Release files for django-settings-diff 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_settings_diff-0.2.2.tar.gz | 4.9 kB | Without provenance | Details for django_settings_diff-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_settings_diff-0.2.2-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for django_settings_diff-0.2.2-py2.py3-none-any.whl |
Total release size: 10.5 kB
Release files / django_settings_diff-0.2.2.tar.gz
| Download URL | django_settings_diff-0.2.2.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
314025c7aa6cfc67896829107203e81269c6b6baec5ba44d79e2fa8226a357f3
|
|
BLAKE2b-256 checksum How to use checksums |
472b09f77b887622c8737de48f1e441a95ba05603d130f53bda8f3833f260363
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.9 CPython/3.8.2 Linux/4.15.0-106-generic
|
Release files / django_settings_diff-0.2.2-py2.py3-none-any.whl
| Download URL | django_settings_diff-0.2.2-py2.py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
9b72ffaffca4967b159956a933a31c777a37a6d1bf1d2180fcb193c82737a8b5
|
|
BLAKE2b-256 checksum How to use checksums |
d8979d07cd23a7a400c238533c30f9c48db5fe23e1b212485d214508acda7937
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.9 CPython/3.8.2 Linux/4.15.0-106-generic
|
Security for django-settings-diff 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.