Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _recursive_clean(pkg: quilt3.Package, metadata_reduction_map: Dict[str, bool]):
# For all keys in current package level
for key in pkg:
# If it is a PackageEntry object, we know we have hit a leaf node
if isinstance(pkg[key], quilt3.packages.PackageEntry):
# Reduce the metadata to a single value where it can
cleaned_meta = {}
for meta_k, meta_v in pkg[key].meta.items():
# If the metadata reduction map at the metadata column (or meta_k) can be reduced/ collapsed (True)
# Reduce/ collapse the metadata
# Reminder: this step will make the metadata access for every file of the same file type the same
# format. Example: all files under the key "FOV" will have the same metadata access after this
# function runs. All the metadata access for the same file type across the package, if one file has
# a list of values for the metadata key, "A", we want all files of the same type to all have list of
# values for the metadata key, "A".
# We also can't just use a set here for two reasons, the first is simply that sets are not JSON
# serializable. "But you can just cast to a set then back to a list!!!". The second reason is that
# because a file can have multiple list of values in it's metadata, if we cast to a set, one list
# may be reduced to two items while another, different metadata list of values may be reduced to
# a single item. Which leads to the problem of matching up metadata to metadata for the same file.
# The example to use here is looking at an FOV files metadata: