Create a "filename" suitable for a function being generated.
(func_name)
| 180 | |
| 181 | # Based on https://github.com/python-attrs/attrs/blob/32fb12789e5cba4b2e71c09e47196b10763ddd7d/src/attr/_make.py#L1863 # noqa: E501 |
| 182 | def _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 | |
| 206 | def _get_code_dir(): |
no test coverage detected