def customize_fields()

in antlir/compiler/items/mount.py [0:0]


    def customize_fields(cls, kwargs) -> None:
        layer_opts = kwargs.pop("layer_opts", None)
        target = kwargs.pop("target")
        cfg = kwargs.pop("mount_config")
        assert (target is None) ^ (
            cfg is None
        ), f"Exactly one of `target` or `mount_config` must be set in {kwargs}"
        if cfg is not None:
            cfg = cfg.copy()  # We must not mutate our input!
        else:
            with open(Path(target) / "mountconfig.json") as f:
                cfg = json.load(f)

        default_mountpoint = cfg.pop("default_mountpoint", None)
        if kwargs.get("mountpoint") is None:  # Missing or None => use default
            kwargs["mountpoint"] = default_mountpoint
            if kwargs["mountpoint"] is None:
                raise AssertionError(f"MountItem {kwargs} lacks mountpoint")
        coerce_path_field_normal_relative(kwargs, "mountpoint")

        kwargs["is_directory"] = cfg.pop("is_directory")

        kwargs["build_source"] = BuildSource(**cfg.pop("build_source"))
        if kwargs["build_source"].type == "host" and not (
            kwargs["from_target"] in layer_opts.allowed_host_mount_targets
            or kwargs["from_target"].startswith(antlir_dep("compiler/test"))
        ):
            raise AssertionError(
                "Host mounts cause containers to be non-hermetic and "
                "fragile, so they must be located under one of "
                f"{layer_opts.allowed_host_mount_targets} "
                "to enable close review by the owners of `antlir`."
            )

        # This is supposed to be the run-time equivalent of `build_source`,
        # but for us it's just an opaque JSON blob that the runtime wants.
        # Hack: We serialize this back to JSON since the compiler expects
        # items to be hashable, and the source WILL contain dicts.
        runtime_source = cfg.pop("runtime_source", None)
        # Future: once runtime_source grows a schema, use it here?
        if runtime_source and runtime_source.get("type") == "host":
            raise AssertionError(
                f"Only `build_source` may specify host mounts: {kwargs}"
            )
        kwargs["runtime_source"] = json.dumps(runtime_source, sort_keys=True)

        kwargs["layer_publisher"] = json.dumps(
            cfg.pop("layer_publisher", None), sort_keys=True
        )

        assert cfg == {}, f"Unparsed fields in {kwargs} mount_config: {cfg}"