We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Make fal scripts __name__ == '__main__'
**Context**
When users test scripts they will normally have a 

```py
if __name__ == '__main__':
  main()
```

and the `main()` function will be where the whole script lives.

When a script is associated with a model, it is executed "directly". So it could be considered the "__main__" script.

**Describe alternatives you've considered**
Going for the dbt interface of offering a function.

```py
# for models
def model():
  pass
```

```py
# for hooks/after/before scripts
def hook():
  pass


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/fal/fal_script.py`
Content:
```
1 import os
2 import json
3 from typing import Dict, Any, List, Optional, Union
4 from pathlib import Path
5 from functools import partial
6 from dataclasses import dataclass
7 from deprecation import deprecated
8 
9 from faldbt.parse import normalize_path
10 from faldbt.project import DbtModel, FalDbt
11 import faldbt.lib as lib
12 
13 from dbt.contracts.results import RunStatus
14 from dbt.config.runtime import RuntimeConfig
15 from dbt.logger import GLOBAL_LOGGER as logger
16 
17 if lib.DBT_VCURRENT.compare(lib.DBT_V1) >= 0:
18     from dbt.contracts.graph.parsed import ColumnInfo
19 else:
20     from faldbt.cp.contracts.graph.parsed import ColumnInfo
21 
22 
23 @dataclass
24 class CurrentModel:
25     name: str
26     alias: str
27     status: RunStatus
28     columns: Dict[str, ColumnInfo]
29     tests: List[Any]
30     meta: Dict[Any, Any]
31 
32 
33 @dataclass
34 class CurrentTest:
35     name: str
36     model_name: str
37     column: str
38     status: str
39 
40     @property
41     @deprecated(details="Use 'model_name' instead")
42     def modelname(self):
43         return self.model_name
44 
45 
46 @dataclass
47 class ContextConfig:
48     target_path: Path
49 
50     def __init__(self, config: RuntimeConfig):
51         self.target_path = Path(
52             os.path.realpath(os.path.join(config.project_root, config.target_path))
53         )
54 
55 
56 @dataclass
57 class Context:
58     current_model: Union[CurrentModel, None]
59     config: ContextConfig
60 
61 
62 @dataclass(frozen=True, init=False)
63 class FalScript:
64     model: Optional[DbtModel]
65     path: Path
66     _faldbt: FalDbt
67 
68     def __init__(self, faldbt: FalDbt, model: Optional[DbtModel], path: str):
69         # Necessary because of frozen=True
70         object.__setattr__(self, "model", model)
71         object.__setattr__(self, "path", normalize_path(faldbt.scripts_dir, path))
72         object.__setattr__(self, "_faldbt", faldbt)
73 
74     @classmethod
75     def model_script(cls, faldbt: FalDbt, model: DbtModel):
76         script = FalScript(faldbt, model, "")
77         # HACK: Set the script path specially for this case
78         object.__setattr__(script, "path", model.python_model)
79         return script
80 
81     def exec(self, faldbt: FalDbt):
82         """
83         Executes the script
84         """
85         # Enable local imports
86         try:
87             source_code = python_from_file(self.path)
88             program = compile(source_code, self.path, "exec")
89 
90             exec_globals = {
91                 "context": self._build_script_context(),
92                 "ref": faldbt.ref,
93                 "source": faldbt.source,
94                 "write_to_source": faldbt.write_to_source,
95                 "write_to_firestore": faldbt.write_to_firestore,
96                 "list_models": faldbt.list_models,
97                 "list_models_ids": faldbt.list_models_ids,
98                 "list_sources": faldbt.list_sources,
99                 "list_features": faldbt.list_features,
100                 "el": faldbt.el,
101             }
102 
103             if self.model is not None:
104                 # Hard-wire the model
105                 exec_globals["write_to_model"] = partial(
106                     faldbt.write_to_model, target_1=self.model.name, target_2=None
107                 )
108 
109             exec(program, exec_globals)
110         finally:
111             pass
112 
113     @property
114     def id(self):
115         # TODO: maybe `self.path - project_dir`, to show only relevant path
116         return f"({self.model_name},{self.path})"
117 
118     @property
119     def is_global(self):
120         return self.model is None
121 
122     @property
123     def model_name(self):
124         return "<GLOBAL>" if self.is_global else self.model.name  # type: ignore
125 
126     def _build_script_context(self):
127         context_config = ContextConfig(self._faldbt._config)
128         if self.is_global:
129             return Context(current_model=None, config=context_config)
130 
131         model: DbtModel = self.model  # type: ignore
132 
133         meta = model.meta
134         _del_key(meta, self._faldbt.keyword)
135 
136         tests = _process_tests(model.tests)
137 
138         current_model = CurrentModel(
139             name=model.name,
140             alias=model.alias,
141             status=model.status,
142             columns=model.columns,
143             tests=tests,
144             meta=meta,
145         )
146 
147         return Context(current_model=current_model, config=context_config)
148 
149 
150 def _del_key(dict: Dict[str, Any], key: str):
151     try:
152         del dict[key]
153     except KeyError:
154         pass
155 
156 
157 def _process_tests(tests: List[Any]):
158     return list(
159         map(
160             lambda test: CurrentTest(
161                 name=test.name,
162                 column=test.column,
163                 status=test.status,
164                 model_name=test.model,
165             ),
166             tests,
167         )
168     )
169 
170 
171 def python_from_file(path: Path) -> str:
172     with open(path) as file:
173         raw_source_code = file.read()
174         if path.suffix == ".ipynb":
175             raw_source_code = _process_ipynb(raw_source_code)
176     return raw_source_code
177 
178 
179 def _process_ipynb(raw_source_code: str) -> str:
180     def strip_magic(source: List[str]) -> List[str]:
181         NOTEBOOK_LIB = "faldbt.magics"
182         return [item for item in source if item[0] != "%" and NOTEBOOK_LIB not in item]
183 
184     ipynb_struct = json.loads(raw_source_code)
185 
186     script_list = []
187     for cell in ipynb_struct["cells"]:
188         if cell["cell_type"] == "code":
189             source = strip_magic(cell["source"])
190             script_list.append("".join(source))
191 
192     joined_script = "\n #cell \n".join(script_list)
193 
194     logger.debug(f"Joined .ipynb cells to:\n{joined_script}")
195 
196     return joined_script
197
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/fal/fal_script.py b/src/fal/fal_script.py
--- a/src/fal/fal_script.py
+++ b/src/fal/fal_script.py
@@ -88,6 +88,7 @@
             program = compile(source_code, self.path, "exec")
 
             exec_globals = {
+                "__name__": "__main__",
                 "context": self._build_script_context(),
                 "ref": faldbt.ref,
                 "source": faldbt.source,

{"golden_diff": "diff --git a/src/fal/fal_script.py b/src/fal/fal_script.py\n--- a/src/fal/fal_script.py\n+++ b/src/fal/fal_script.py\n@@ -88,6 +88,7 @@\n             program = compile(source_code, self.path, \"exec\")\n \n             exec_globals = {\n+                \"__name__\": \"__main__\",\n                 \"context\": self._build_script_context(),\n                 \"ref\": faldbt.ref,\n                 \"source\": faldbt.source,\n", "issue": "Make fal scripts __name__ == '__main__'\n**Context**\r\nWhen users test scripts they will normally have a \r\n\r\n```py\r\nif __name__ == '__main__':\r\n  main()\r\n```\r\n\r\nand the `main()` function will be where the whole script lives.\r\n\r\nWhen a script is associated with a model, it is executed \"directly\". So it could be considered the \"__main__\" script.\r\n\r\n**Describe alternatives you've considered**\r\nGoing for the dbt interface of offering a function.\r\n\r\n```py\r\n# for models\r\ndef model():\r\n  pass\r\n```\r\n\r\n```py\r\n# for hooks/after/before scripts\r\ndef hook():\r\n  pass\r\n\n", "before_files": [{"content": "import os\nimport json\nfrom typing import Dict, Any, List, Optional, Union\nfrom pathlib import Path\nfrom functools import partial\nfrom dataclasses import dataclass\nfrom deprecation import deprecated\n\nfrom faldbt.parse import normalize_path\nfrom faldbt.project import DbtModel, FalDbt\nimport faldbt.lib as lib\n\nfrom dbt.contracts.results import RunStatus\nfrom dbt.config.runtime import RuntimeConfig\nfrom dbt.logger import GLOBAL_LOGGER as logger\n\nif lib.DBT_VCURRENT.compare(lib.DBT_V1) >= 0:\n    from dbt.contracts.graph.parsed import ColumnInfo\nelse:\n    from faldbt.cp.contracts.graph.parsed import ColumnInfo\n\n\n@dataclass\nclass CurrentModel:\n    name: str\n    alias: str\n    status: RunStatus\n    columns: Dict[str, ColumnInfo]\n    tests: List[Any]\n    meta: Dict[Any, Any]\n\n\n@dataclass\nclass CurrentTest:\n    name: str\n    model_name: str\n    column: str\n    status: str\n\n    @property\n    @deprecated(details=\"Use 'model_name' instead\")\n    def modelname(self):\n        return self.model_name\n\n\n@dataclass\nclass ContextConfig:\n    target_path: Path\n\n    def __init__(self, config: RuntimeConfig):\n        self.target_path = Path(\n            os.path.realpath(os.path.join(config.project_root, config.target_path))\n        )\n\n\n@dataclass\nclass Context:\n    current_model: Union[CurrentModel, None]\n    config: ContextConfig\n\n\n@dataclass(frozen=True, init=False)\nclass FalScript:\n    model: Optional[DbtModel]\n    path: Path\n    _faldbt: FalDbt\n\n    def __init__(self, faldbt: FalDbt, model: Optional[DbtModel], path: str):\n        # Necessary because of frozen=True\n        object.__setattr__(self, \"model\", model)\n        object.__setattr__(self, \"path\", normalize_path(faldbt.scripts_dir, path))\n        object.__setattr__(self, \"_faldbt\", faldbt)\n\n    @classmethod\n    def model_script(cls, faldbt: FalDbt, model: DbtModel):\n        script = FalScript(faldbt, model, \"\")\n        # HACK: Set the script path specially for this case\n        object.__setattr__(script, \"path\", model.python_model)\n        return script\n\n    def exec(self, faldbt: FalDbt):\n        \"\"\"\n        Executes the script\n        \"\"\"\n        # Enable local imports\n        try:\n            source_code = python_from_file(self.path)\n            program = compile(source_code, self.path, \"exec\")\n\n            exec_globals = {\n                \"context\": self._build_script_context(),\n                \"ref\": faldbt.ref,\n                \"source\": faldbt.source,\n                \"write_to_source\": faldbt.write_to_source,\n                \"write_to_firestore\": faldbt.write_to_firestore,\n                \"list_models\": faldbt.list_models,\n                \"list_models_ids\": faldbt.list_models_ids,\n                \"list_sources\": faldbt.list_sources,\n                \"list_features\": faldbt.list_features,\n                \"el\": faldbt.el,\n            }\n\n            if self.model is not None:\n                # Hard-wire the model\n                exec_globals[\"write_to_model\"] = partial(\n                    faldbt.write_to_model, target_1=self.model.name, target_2=None\n                )\n\n            exec(program, exec_globals)\n        finally:\n            pass\n\n    @property\n    def id(self):\n        # TODO: maybe `self.path - project_dir`, to show only relevant path\n        return f\"({self.model_name},{self.path})\"\n\n    @property\n    def is_global(self):\n        return self.model is None\n\n    @property\n    def model_name(self):\n        return \"<GLOBAL>\" if self.is_global else self.model.name  # type: ignore\n\n    def _build_script_context(self):\n        context_config = ContextConfig(self._faldbt._config)\n        if self.is_global:\n            return Context(current_model=None, config=context_config)\n\n        model: DbtModel = self.model  # type: ignore\n\n        meta = model.meta\n        _del_key(meta, self._faldbt.keyword)\n\n        tests = _process_tests(model.tests)\n\n        current_model = CurrentModel(\n            name=model.name,\n            alias=model.alias,\n            status=model.status,\n            columns=model.columns,\n            tests=tests,\n            meta=meta,\n        )\n\n        return Context(current_model=current_model, config=context_config)\n\n\ndef _del_key(dict: Dict[str, Any], key: str):\n    try:\n        del dict[key]\n    except KeyError:\n        pass\n\n\ndef _process_tests(tests: List[Any]):\n    return list(\n        map(\n            lambda test: CurrentTest(\n                name=test.name,\n                column=test.column,\n                status=test.status,\n                model_name=test.model,\n            ),\n            tests,\n        )\n    )\n\n\ndef python_from_file(path: Path) -> str:\n    with open(path) as file:\n        raw_source_code = file.read()\n        if path.suffix == \".ipynb\":\n            raw_source_code = _process_ipynb(raw_source_code)\n    return raw_source_code\n\n\ndef _process_ipynb(raw_source_code: str) -> str:\n    def strip_magic(source: List[str]) -> List[str]:\n        NOTEBOOK_LIB = \"faldbt.magics\"\n        return [item for item in source if item[0] != \"%\" and NOTEBOOK_LIB not in item]\n\n    ipynb_struct = json.loads(raw_source_code)\n\n    script_list = []\n    for cell in ipynb_struct[\"cells\"]:\n        if cell[\"cell_type\"] == \"code\":\n            source = strip_magic(cell[\"source\"])\n            script_list.append(\"\".join(source))\n\n    joined_script = \"\\n #cell \\n\".join(script_list)\n\n    logger.debug(f\"Joined .ipynb cells to:\\n{joined_script}\")\n\n    return joined_script\n", "path": "src/fal/fal_script.py"}], "after_files": [{"content": "import os\nimport json\nfrom typing import Dict, Any, List, Optional, Union\nfrom pathlib import Path\nfrom functools import partial\nfrom dataclasses import dataclass\nfrom deprecation import deprecated\n\nfrom faldbt.parse import normalize_path\nfrom faldbt.project import DbtModel, FalDbt\nimport faldbt.lib as lib\n\nfrom dbt.contracts.results import RunStatus\nfrom dbt.config.runtime import RuntimeConfig\nfrom dbt.logger import GLOBAL_LOGGER as logger\n\nif lib.DBT_VCURRENT.compare(lib.DBT_V1) >= 0:\n    from dbt.contracts.graph.parsed import ColumnInfo\nelse:\n    from faldbt.cp.contracts.graph.parsed import ColumnInfo\n\n\n@dataclass\nclass CurrentModel:\n    name: str\n    alias: str\n    status: RunStatus\n    columns: Dict[str, ColumnInfo]\n    tests: List[Any]\n    meta: Dict[Any, Any]\n\n\n@dataclass\nclass CurrentTest:\n    name: str\n    model_name: str\n    column: str\n    status: str\n\n    @property\n    @deprecated(details=\"Use 'model_name' instead\")\n    def modelname(self):\n        return self.model_name\n\n\n@dataclass\nclass ContextConfig:\n    target_path: Path\n\n    def __init__(self, config: RuntimeConfig):\n        self.target_path = Path(\n            os.path.realpath(os.path.join(config.project_root, config.target_path))\n        )\n\n\n@dataclass\nclass Context:\n    current_model: Union[CurrentModel, None]\n    config: ContextConfig\n\n\n@dataclass(frozen=True, init=False)\nclass FalScript:\n    model: Optional[DbtModel]\n    path: Path\n    _faldbt: FalDbt\n\n    def __init__(self, faldbt: FalDbt, model: Optional[DbtModel], path: str):\n        # Necessary because of frozen=True\n        object.__setattr__(self, \"model\", model)\n        object.__setattr__(self, \"path\", normalize_path(faldbt.scripts_dir, path))\n        object.__setattr__(self, \"_faldbt\", faldbt)\n\n    @classmethod\n    def model_script(cls, faldbt: FalDbt, model: DbtModel):\n        script = FalScript(faldbt, model, \"\")\n        # HACK: Set the script path specially for this case\n        object.__setattr__(script, \"path\", model.python_model)\n        return script\n\n    def exec(self, faldbt: FalDbt):\n        \"\"\"\n        Executes the script\n        \"\"\"\n        # Enable local imports\n        try:\n            source_code = python_from_file(self.path)\n            program = compile(source_code, self.path, \"exec\")\n\n            exec_globals = {\n                \"__name__\": \"__main__\",\n                \"context\": self._build_script_context(),\n                \"ref\": faldbt.ref,\n                \"source\": faldbt.source,\n                \"write_to_source\": faldbt.write_to_source,\n                \"write_to_firestore\": faldbt.write_to_firestore,\n                \"list_models\": faldbt.list_models,\n                \"list_models_ids\": faldbt.list_models_ids,\n                \"list_sources\": faldbt.list_sources,\n                \"list_features\": faldbt.list_features,\n                \"el\": faldbt.el,\n            }\n\n            if self.model is not None:\n                # Hard-wire the model\n                exec_globals[\"write_to_model\"] = partial(\n                    faldbt.write_to_model, target_1=self.model.name, target_2=None\n                )\n\n            exec(program, exec_globals)\n        finally:\n            pass\n\n    @property\n    def id(self):\n        # TODO: maybe `self.path - project_dir`, to show only relevant path\n        return f\"({self.model_name},{self.path})\"\n\n    @property\n    def is_global(self):\n        return self.model is None\n\n    @property\n    def model_name(self):\n        return \"<GLOBAL>\" if self.is_global else self.model.name  # type: ignore\n\n    def _build_script_context(self):\n        context_config = ContextConfig(self._faldbt._config)\n        if self.is_global:\n            return Context(current_model=None, config=context_config)\n\n        model: DbtModel = self.model  # type: ignore\n\n        meta = model.meta\n        _del_key(meta, self._faldbt.keyword)\n\n        tests = _process_tests(model.tests)\n\n        current_model = CurrentModel(\n            name=model.name,\n            alias=model.alias,\n            status=model.status,\n            columns=model.columns,\n            tests=tests,\n            meta=meta,\n        )\n\n        return Context(current_model=current_model, config=context_config)\n\n\ndef _del_key(dict: Dict[str, Any], key: str):\n    try:\n        del dict[key]\n    except KeyError:\n        pass\n\n\ndef _process_tests(tests: List[Any]):\n    return list(\n        map(\n            lambda test: CurrentTest(\n                name=test.name,\n                column=test.column,\n                status=test.status,\n                model_name=test.model,\n            ),\n            tests,\n        )\n    )\n\n\ndef python_from_file(path: Path) -> str:\n    with open(path) as file:\n        raw_source_code = file.read()\n        if path.suffix == \".ipynb\":\n            raw_source_code = _process_ipynb(raw_source_code)\n    return raw_source_code\n\n\ndef _process_ipynb(raw_source_code: str) -> str:\n    def strip_magic(source: List[str]) -> List[str]:\n        NOTEBOOK_LIB = \"faldbt.magics\"\n        return [item for item in source if item[0] != \"%\" and NOTEBOOK_LIB not in item]\n\n    ipynb_struct = json.loads(raw_source_code)\n\n    script_list = []\n    for cell in ipynb_struct[\"cells\"]:\n        if cell[\"cell_type\"] == \"code\":\n            source = strip_magic(cell[\"source\"])\n            script_list.append(\"\".join(source))\n\n    joined_script = \"\\n #cell \\n\".join(script_list)\n\n    logger.debug(f\"Joined .ipynb cells to:\\n{joined_script}\")\n\n    return joined_script\n", "path": "src/fal/fal_script.py"}]}