Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions polyapi/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,20 +503,20 @@ def add_function_file(
# Read current __init__.py content if it exists
init_content = ""
if os.path.exists(init_path):
with open(init_path, "r") as f:
with open(init_path, "r", encoding='utf-8') as f:
init_content = f.read()

# Prepare new content to append to __init__.py
new_init_content = init_content + f"\n\nfrom . import {func_namespace}\n\n{func_str}"

# Use temporary files for atomic writes
# Write to __init__.py atomically
with tempfile.NamedTemporaryFile(mode="w", delete=False, dir=full_path, suffix=".tmp") as temp_init:
with tempfile.NamedTemporaryFile(mode="w", delete=False, dir=full_path, suffix=".tmp", encoding='utf-8') as temp_init:
temp_init.write(new_init_content)
temp_init_path = temp_init.name

# Write to function file atomically
with tempfile.NamedTemporaryFile(mode="w", delete=False, dir=full_path, suffix=".tmp") as temp_func:
with tempfile.NamedTemporaryFile(mode="w", delete=False, dir=full_path, suffix=".tmp", encoding='utf-8') as temp_func:
temp_func.write(func_type_defs)
temp_func_path = temp_func.name

Expand Down
4 changes: 2 additions & 2 deletions polyapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def init_the_init(full_path: str, code_imports: Optional[str] = None) -> None:
if not os.path.exists(init_path):
if code_imports is None:
code_imports = CODE_IMPORTS
with open(init_path, "w") as f:
with open(init_path, "w", encoding='utf-8') as f:
f.write(code_imports)


Expand All @@ -33,7 +33,7 @@ def add_import_to_init(full_path: str, next: str, code_imports: Optional[str] =
init_the_init(full_path, code_imports=code_imports)

init_path = os.path.join(full_path, "__init__.py")
with open(init_path, "a+") as f:
with open(init_path, "a+", encoding='utf-8') as f:
import_stmt = "from . import {}\n".format(next)
f.seek(0)
lines = f.readlines()
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"]

[project]
name = "polyapi-python"
version = "0.3.9"
version = "0.3.10.dev1"
description = "The Python Client for PolyAPI, the IPaaS by Developers for Developers"
authors = [{ name = "Dan Fellin", email = "dan@polyapi.io" }]
dependencies = [
Expand Down