MCPcopy Create free account
hub / github.com/apache/fory / _generate_filename

Function _generate_filename

python/pyfory/codegen.py:182–203  ·  view source on GitHub ↗

Create a "filename" suitable for a function being generated.

(func_name)

Source from the content-addressed store, hash-verified

180
181# Based on https://github.com/python-attrs/attrs/blob/32fb12789e5cba4b2e71c09e47196b10763ddd7d/src/attr/_make.py#L1863 # noqa: E501
182def _generate_filename(func_name):
183 """
184 Create a "filename" suitable for a function being generated.
185 """
186 # Sanitize the function name for filename
187 sanitized_name = _sanitize_function_name(func_name)
188 unique_id = uuid.uuid4()
189 extra = "0"
190 count = 1
191
192 while True:
193 filename = f"fory_generated_{sanitized_name}_{extra}.py"
194 # To handle concurrency we essentially "reserve" our spot in
195 # the linecache with a dummy line. The caller can then
196 # set this value correctly.
197 cache_line = (1, None, [str(unique_id)], filename)
198 if linecache.cache.setdefault(filename, cache_line) == cache_line:
199 return filename
200
201 # Looks like this spot is taken. Try again.
202 count += 1
203 extra = "{0}".format(count)
204
205
206def _get_code_dir():

Callers 1

compile_functionFunction · 0.85

Calls 3

_sanitize_function_nameFunction · 0.85
setdefaultMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected