Skip to content

Commit f810e94

Browse files
committed
parser: don't recreate __init__.py if it exists in edi directories
1 parent 1d12a39 commit f810e94

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

scripts/generator/pydifact_generator.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,10 +1488,15 @@ class {message_spec.class_name()}(Message):\n
14881488
def write_python_code_to_file(directory: str, filename: str, content: str):
14891489
global last_file_path
14901490
# get path of pydifact.syntax module
1491-
dirname = os.path.join(os.path.dirname(pydifact.syntax.__file__), directory)
1491+
dirname = os.path.join(
1492+
os.path.dirname(pydifact.syntax.__file__), to_identifier(directory)
1493+
)
14921494
os.makedirs(dirname, exist_ok=True)
1493-
with open(os.path.join(dirname, "__init__.py"), "w", encoding="utf-8") as f:
1494-
f.write("")
1495+
# if __init__.py does not exis, create it
1496+
init_file = os.path.join(dirname, "__init__.py")
1497+
if not os.path.exists(init_file):
1498+
with open(init_file, "w", encoding="utf-8") as f:
1499+
f.write("")
14951500
current_file = os.path.join(dirname, filename)
14961501
with open(current_file, "w", encoding="utf-8") as f:
14971502
f.write(content)

0 commit comments

Comments
 (0)