From bb00735a266b8e5cf2ea09b1e188a5ebfca47fc2 Mon Sep 17 00:00:00 2001
From: Valentin Gagarin <valentin.gagarin@tweag.io>
Date: Wed, 2 Apr 2025 10:02:34 +0200
Subject: [PATCH] Revert "POC: render pydantic schema as module in Python"

This reverts commit b9c12db2ed613dd2157060aaba7004fa3b530f14.
---
 panel/src/panel/configuration/to_module.py | 53 ----------------------
 panel/src/panel/tests/test_to_module.py    | 44 ------------------
 2 files changed, 97 deletions(-)
 delete mode 100644 panel/src/panel/configuration/to_module.py
 delete mode 100644 panel/src/panel/tests/test_to_module.py

diff --git a/panel/src/panel/configuration/to_module.py b/panel/src/panel/configuration/to_module.py
deleted file mode 100644
index 36e3c131..00000000
--- a/panel/src/panel/configuration/to_module.py
+++ /dev/null
@@ -1,53 +0,0 @@
-import json
-import textwrap
-
-# TODO(@fricklerhandwerk): mix this in as a method on the Pydantic Schema itself
-def generate_module(schema, service_name):
-    properties = schema.get("properties", {})
-    required = schema.get("required", [])
-
-    options = []
-    for name, prop in properties.items():
-        nix_type = {
-            "string": "types.str",
-            "integer": "types.int",
-            "boolean": "types.bool"
-        }[prop["type"]]
-
-        desc = prop.get("description")
-
-        default = None
-        if name not in required and "default" in prop:
-            to_nix_value = {
-                "string": lambda v: f'"{v}"',
-                "boolean": lambda v: str(v).lower(),
-                "integer": lambda v: str(v),
-                "number": lambda v: str(v)
-            }
-            default = to_nix_value[prop["type"]](prop["default"])
-
-        option = textwrap.dedent(f"""
-            {name} = mkOption {{{f'''
-              description = "{desc}";''' if desc else ''}
-              type = {nix_type};{f'''
-              default = {default};''' if default is not None else ''}
-            }};
-        """)
-
-        options.append(option.strip())
-
-    module = textwrap.dedent(f"""
-        {{ lib, ... }}:
-
-        let
-          cfg = config.services.{service_name};
-          inherit (lib) mkOption types;
-        in
-        {{
-          options.services.{service_name} = {{
-            {textwrap.indent("\n\n".join(options), '            ').strip()}
-          }};
-        }}
-    """)
-
-    return module
diff --git a/panel/src/panel/tests/test_to_module.py b/panel/src/panel/tests/test_to_module.py
deleted file mode 100644
index f3c2ae13..00000000
--- a/panel/src/panel/tests/test_to_module.py
+++ /dev/null
@@ -1,44 +0,0 @@
-from django.test import TestCase
-from pydantic import BaseModel, Field
-import textwrap
-
-from panel.configuration import to_module
-
-
-class ConvertToModule(TestCase):
-    def test_minimal_module(self):
-        class Example(BaseModel):
-            name: str = Field(..., description="Service name")
-            port: int = Field(8080)
-            enable: bool = Field(True, description="Enable service")
-
-        expected = textwrap.dedent("""
-            { lib, ... }:
-
-            let
-              cfg = config.services.myservice;
-              inherit (lib) mkOption types;
-            in
-            {
-              options.services.myservice = {
-                name = mkOption {
-                  description = "Service name";
-                  type = types.str;
-                };
-
-                port = mkOption {
-                  type = types.int;
-                  default = 8080;
-                };
-
-                enable = mkOption {
-                  description = "Enable service";
-                  type = types.bool;
-                  default = true;
-                };
-              };
-            }
-        """)
-
-        actual = to_module.generate_module(Example.schema(), "myservice")
-        self.assertEqual(actual, expected)