Sfoglia il codice sorgente

fix: use NamedTemporaryFile

Sam Jaffe 1 mese fa
parent
commit
10e46b981e
2 ha cambiato i file con 4 aggiunte e 4 eliminazioni
  1. 2 2
      src/cipy/action.py
  2. 2 2
      src/cipy/runner.py

+ 2 - 2
src/cipy/action.py

@@ -117,8 +117,8 @@ class Script(Action):
     @cipy.runner.ipc
     @cipy.runner.preamble(extra=[("CYAN", lambda s: s._lines)])
     def run(self, context: Context) -> Status:
-        with tempfile.TemporaryFile(mode="w+", suffix=self.shell.extension()) as script:
-            script.write(self.script)
+        with tempfile.NamedTemporaryFile(suffix=self.shell.extension()) as script:
+            script.write(self.script.encode("utf-8"))
             try:
                 subprocess.run(self.shell.command(script.name), check=True)
                 return Status.SUCCESS

+ 2 - 2
src/cipy/runner.py

@@ -58,8 +58,8 @@ def ipc(func: Run[Action]) -> Run[Action]:
     def wrapper(self: Action, context: Context) -> Status:
         inputs = {f"INPUT_{k}": v for k, v in self.inputs}
         with (
-            tempfile.TemporaryFile(mode="w+") as output,
-            tempfile.TemporaryFile(mode="w+") as envfile,
+            tempfile.NamedTemporaryFile() as output,
+            tempfile.NamedTemporaryFile() as envfile,
             environ(CI_OUTPUT=output.name, CI_ENVIRON=envfile.name, **inputs),
         ):
             rval = func(self, context)