Spaces:
Running
Running
Explicitly use UTF-8 encoding.
Browse files
lynxkite-app/src/lynxkite_app/crdt.py
CHANGED
@@ -99,7 +99,7 @@ class CodeWebsocketServer(WorkspaceWebsocketServer):
|
|
99 |
pass
|
100 |
if len(text) == 0:
|
101 |
if os.path.exists(name):
|
102 |
-
with open(name) as f:
|
103 |
text += f.read()
|
104 |
room = pycrdt_websocket.YRoom(
|
105 |
ystore=ystore, ydoc=ydoc, exception_handler=ws_exception_handler
|
@@ -279,9 +279,9 @@ async def execute(name: str, ws_crdt: pycrdt.Map, ws_pyd: workspace.Workspace, d
|
|
279 |
|
280 |
|
281 |
async def code_changed(name: str, changes: pycrdt.TextEvent, text: pycrdt.Text):
|
282 |
-
|
283 |
-
with open(name, "w") as f:
|
284 |
-
f.write(
|
285 |
|
286 |
|
287 |
@contextlib.asynccontextmanager
|
|
|
99 |
pass
|
100 |
if len(text) == 0:
|
101 |
if os.path.exists(name):
|
102 |
+
with open(name, encoding="utf-8") as f:
|
103 |
text += f.read()
|
104 |
room = pycrdt_websocket.YRoom(
|
105 |
ystore=ystore, ydoc=ydoc, exception_handler=ws_exception_handler
|
|
|
279 |
|
280 |
|
281 |
async def code_changed(name: str, changes: pycrdt.TextEvent, text: pycrdt.Text):
|
282 |
+
text = text.strip() + "\n"
|
283 |
+
with open(name, "w", encoding="utf-8") as f:
|
284 |
+
f.write(text)
|
285 |
|
286 |
|
287 |
@contextlib.asynccontextmanager
|
lynxkite-core/src/lynxkite/core/ops.py
CHANGED
@@ -366,7 +366,6 @@ def load_user_scripts(workspace: str):
|
|
366 |
path = cwd / workspace
|
367 |
assert path.is_relative_to(cwd), "Provided workspace path is invalid"
|
368 |
for p in path.parents:
|
369 |
-
print("checking user scripts in", p)
|
370 |
req = p / "requirements.txt"
|
371 |
if req.exists():
|
372 |
try:
|
|
|
366 |
path = cwd / workspace
|
367 |
assert path.is_relative_to(cwd), "Provided workspace path is invalid"
|
368 |
for p in path.parents:
|
|
|
369 |
req = p / "requirements.txt"
|
370 |
if req.exists():
|
371 |
try:
|
lynxkite-core/src/lynxkite/core/workspace.py
CHANGED
@@ -111,7 +111,9 @@ def save(ws: Workspace, path: str):
|
|
111 |
if dirname:
|
112 |
os.makedirs(dirname, exist_ok=True)
|
113 |
# Create temp file in the same directory to make sure it's on the same filesystem.
|
114 |
-
with tempfile.NamedTemporaryFile(
|
|
|
|
|
115 |
temp_name = f.name
|
116 |
f.write(j)
|
117 |
os.replace(temp_name, path)
|
@@ -128,7 +130,7 @@ def load(path: str) -> Workspace:
|
|
128 |
Returns:
|
129 |
Workspace: The loaded workspace object, with updated metadata.
|
130 |
"""
|
131 |
-
with open(path) as f:
|
132 |
j = f.read()
|
133 |
ws = Workspace.model_validate_json(j)
|
134 |
# Metadata is added after loading. This way code changes take effect on old boxes too.
|
|
|
111 |
if dirname:
|
112 |
os.makedirs(dirname, exist_ok=True)
|
113 |
# Create temp file in the same directory to make sure it's on the same filesystem.
|
114 |
+
with tempfile.NamedTemporaryFile(
|
115 |
+
"w", encoding="utf-8", prefix=f".{basename}.", dir=dirname, delete=False
|
116 |
+
) as f:
|
117 |
temp_name = f.name
|
118 |
f.write(j)
|
119 |
os.replace(temp_name, path)
|
|
|
130 |
Returns:
|
131 |
Workspace: The loaded workspace object, with updated metadata.
|
132 |
"""
|
133 |
+
with open(path, encoding="utf-8") as f:
|
134 |
j = f.read()
|
135 |
ws = Workspace.model_validate_json(j)
|
136 |
# Metadata is added after loading. This way code changes take effect on old boxes too.
|