Skip to content

Commit

Permalink
More fixes for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
openvmp committed Jan 13, 2024
1 parent dd517f4 commit 45e45a1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 38 deletions.
4 changes: 3 additions & 1 deletion partcad/src/partcad/runtime_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pathlib
import subprocess
import sys

import threading

from . import runtime

Expand All @@ -23,6 +23,8 @@ def __init__(self, ctx, sandbox, version=None):
super().__init__(ctx, "python-" + sandbox + "-" + version)
self.version = version

self.lock = threading.Lock()

def run(self, cmd, stdin=""):
p = subprocess.Popen(
cmd,
Expand Down
76 changes: 39 additions & 37 deletions partcad/src/partcad/runtime_python_conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,44 @@ class CondaPythonRuntime(runtime_python.PythonRuntime):
def __init__(self, ctx, version=None):
super().__init__(ctx, "conda", version)

if not self.initialized:
self.conda_path = shutil.which("conda")
if self.conda_path is None:
raise Exception(
"ERROR: PartCAD is configured to use conda, but conda is missing"
)

try:
os.makedirs(self.path)
subprocess.run(
[
self.conda_path,
"create",
"-y",
"-p",
self.path,
"python=%s" % version,
]
)
subprocess.run(["conda", "install", "-y", "-p", self.path, "pip"])
self.initialized = True
except Exception as e:
shutil.rmtree(self.path)
raise e
self.conda_path = shutil.which("conda")

def run(self, cmd, stdin=""):
return super().run(
[
self.conda_path,
"run",
"--no-capture-output",
"-p",
self.path,
# "python", # Trust conda to set the link correctly
"python%s" % self.version, # This doesn't work on Windows
]
+ cmd,
stdin,
)
with self.lock:
if not self.initialized:
if self.conda_path is None:
raise Exception(
"ERROR: PartCAD is configured to use conda, but conda is missing"
)

try:
os.makedirs(self.path)
subprocess.run(
[
self.conda_path,
"create",
"-y",
"-p",
self.path,
"python=%s" % self.version,
]
)
subprocess.run(["conda", "install", "-y", "-p", self.path, "pip"])
self.initialized = True
except Exception as e:
shutil.rmtree(self.path)
raise e

return super().run(
[
self.conda_path,
"run",
"--no-capture-output",
"-p",
self.path,
"python",
# "python%s" % self.version, # This doesn't work on Windows
]
+ cmd,
stdin,
)

0 comments on commit 45e45a1

Please sign in to comment.