MCPcopy Create free account
hub / github.com/dagger/dagger / Context

Class Context

sdk/python/codegen/src/codegen/generator.py:111–154  ·  view source on GitHub ↗

Shared state during execution.

Source from the content-addressed store, hash-verified

109
110@dataclass
111class Context:
112 """Shared state during execution."""
113
114 schema: GraphQLSchema = field(default_factory=GraphQLSchema)
115 """GraphQL schema."""
116
117 schema_version: str = ""
118 """Effective schema compatibility version."""
119
120 ids: frozenset[IDName] = field(default_factory=frozenset)
121 """Set of ID scalar names."""
122
123 defined: set[str] = field(default_factory=set)
124 """Types that have already been defined."""
125
126 remaining: set[str] = field(default_factory=set)
127 """Remaining type names that haven't been defined yet."""
128
129 @property
130 def legacy_sdk_compat(self) -> bool:
131 """Generate the pre-v0.21 ID/load helper source facade."""
132 return legacy_sdk_compat(self.schema_version)
133
134 def process_type(self, name: str):
135 # This is only needed to keep track of remaining types because
136 # of forward references.
137 self.remaining.remove(name)
138 self.defined.add(name)
139
140 def render_types(self, s: str) -> str:
141 """Render type names as forward references if they haven't been defined yet."""
142 if not self.remaining:
143 return s
144
145 # Add quotes to names that haven't been defined yet (forward references).
146 # Need to fix optionals because `"File" | None` is not a valid annotation.
147 # The whole annotation needs to be quoted (`"File | None"`).
148 s = re.sub(rf"\b({'|'.join(self.remaining)})\b", r'"\1"', s).replace(
149 '" | None',
150 ' | None"',
151 )
152 return re.sub(
153 rf'list\["({"|".join(self.remaining)})"\] \| None', r'"list[\1] | None"', s
154 )
155
156
157_H = TypeVar("_H", bound=GraphQLNamedType)

Callers 3

ctxFunction · 0.90
generateFunction · 0.70

Calls

no outgoing calls

Tested by 2

ctxFunction · 0.72