We are using DeepDiff for comparing two YAML files and then wanted to exclude certain paths for comparison
- File1 dataset
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp1
labels:
app: myapp
env: prod
customer: A
- File2 dataset
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp2
labels:
app: myapp
env: dev
customer: B
My code i tried, but the exclude_paths are not working as intended
from deepdiff import DeepDiff
# Unfortunately the exclude_paths is forced on us from a separate team in below format
exclude_paths = ["metadata.labels.env", "metadata.labels.annotation"]
print(DeepDiff(test1, test2, ignore_order=True, exclude_paths=exclude_paths))
Unfortunately the exclude_paths is forced on us from a separate team in a text file and we convert that to a list
with open(args.exeception_list) as f:
exp = f.read().splitlines()
which makes into below format
exclude_paths = ["metadata.labels.env", "metadata.labels.annotation"]
If i change the exclude_paths to below format it works
exclude_paths = ["['metadata']['labels']['env']", "['metadata']['labels']['annotation']"]
I couldn't find an easy way to convert dot notation to 'square bracket & single quote' format.
Any better approaches rather than converting the metadata.labels.env to ['metadata']['labels']['env'] in a convoluted manner? thanks in advance