Skip to content

Commit

Permalink
Troubleshooting
Browse files Browse the repository at this point in the history
  • Loading branch information
openvmp committed Nov 4, 2024
1 parent 0e35e02 commit 020166a
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-13] # macos-latest has an issue with nlopt
# os: ["ubuntu-latest", "windows-latest", "macos-latest"]
python-version: ["3.10", "3.11", "3.12", "3.13"]
python-version: ["3.10", "3.11", "3.12"]
# exclude:
# # False negatives on Windows for pytest result evaluation
# - os: "windows-latest"
Expand Down
19 changes: 14 additions & 5 deletions partcad/src/partcad/runtime_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ def get_async_lock(self):
def once(self):
pass

async def once_async(self):
pass

async def run(self, cmd, stdin="", cwd=None):
await self.once_async()
return await self.run_onced(cmd, stdin=stdin, cwd=cwd)

async def run_onced(self, cmd, stdin="", cwd=None):
pc_logging.debug("Running: %s", cmd)
p = await asyncio.create_subprocess_exec(
# cmd,
Expand Down Expand Up @@ -78,7 +85,7 @@ async def run(self, cmd, stdin="", cwd=None):
return stdout, stderr

async def ensure(self, python_package):
self.once()
await self.once_async()

# TODO(clairbee): expire the guard file after a certain time

Expand All @@ -94,11 +101,13 @@ async def ensure(self, python_package):
with pc_logging.Action(
"PipInst", self.version, python_package
):
await self.run(["-m", "pip", "install", python_package])
await self.run_locked(
["-m", "pip", "install", python_package]
)
pathlib.Path(guard_path).touch()

async def prepare_for_package(self, project):
self.once()
await self.once_async()

# TODO(clairbee): expire the guard file after a certain time

Expand All @@ -118,7 +127,7 @@ async def prepare_for_package(self, project):
with pc_logging.Action(
"PipReqs", self.version, project.name
):
await self.run(
await self.run_locked(
[
"-m",
"pip",
Expand All @@ -135,7 +144,7 @@ async def prepare_for_package(self, project):
await self.ensure(req)

async def prepare_for_shape(self, config):
self.once()
await self.once_async()

# Install dependencies of this part
if "pythonRequirements" in config:
Expand Down
112 changes: 57 additions & 55 deletions partcad/src/partcad/runtime_python_conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,67 +48,69 @@ def __init__(self, ctx, version=None):

def once(self):
with self.lock:
if not self.initialized:
with pc_logging.Action("Conda", "create", self.version):
if self.conda_path is None:
raise Exception(
"ERROR: PartCAD is configured to use conda, but conda is missing"
)
self.once_locked()

try:
os.makedirs(self.path)
async def once_async(self):
with self.lock:
async with self.get_async_lock():
self.once_locked()

def once_locked(self):
if not self.initialized:
with pc_logging.Action("Conda", "create", self.version):
if self.conda_path is None:
raise Exception(
"ERROR: PartCAD is configured to use conda, but conda is missing"
)

# Install new conda environment with the preferred Python version
p = subprocess.Popen(
[
self.conda_path,
"create",
"-y",
"-q",
"--json",
"-p",
self.path,
"python=%s" % self.version,
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
_, stderr = p.communicate()
if not stderr is None and stderr != b"":
pc_logging.error(
"conda env install error: %s" % stderr
)
try:
os.makedirs(self.path)

# Install pip into the newly created conda environment
p = subprocess.Popen(
[
self.conda_path,
"install",
"-y",
"-q",
"--json",
"-p",
self.path,
"pip",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
_, stderr = p.communicate()
if not stderr is None and stderr != b"":
pc_logging.error(
"conda pip install error: %s" % stderr
)
# Install new conda environment with the preferred Python version
p = subprocess.Popen(
[
self.conda_path,
"create",
"-y",
"-q",
"--json",
"-p",
self.path,
"python=%s" % self.version,
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
_, stderr = p.communicate()
if not stderr is None and stderr != b"":
pc_logging.error("conda env install error: %s" % stderr)

self.initialized = True
except Exception as e:
shutil.rmtree(self.path)
raise e
# Install pip into the newly created conda environment
p = subprocess.Popen(
[
self.conda_path,
"install",
"-y",
"-q",
"--json",
"-p",
self.path,
"pip",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
_, stderr = p.communicate()
if not stderr is None and stderr != b"":
pc_logging.error("conda pip install error: %s" % stderr)

async def run(self, cmd, stdin="", cwd=None):
self.once()
self.initialized = True
except Exception as e:
shutil.rmtree(self.path)
raise e

return await super().run(
async def run_onced(self, cmd, stdin="", cwd=None):
return await super().run_onced(
[
self.conda_path,
"run",
Expand Down
4 changes: 2 additions & 2 deletions partcad/src/partcad/runtime_python_none.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def __init__(self, ctx, version=None):
os.makedirs(self.path)
self.initialized = True

async def run(self, cmd, stdin="", cwd=None):
return await super().run(
async def run_onced(self, cmd, stdin="", cwd=None):
return await super().run_onced(
[self.exec_name] + cmd,
stdin,
cwd=cwd,
Expand Down
4 changes: 2 additions & 2 deletions partcad/src/partcad/runtime_python_pypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def __init__(self, ctx, version=None):
shutil.rmtree(self.path)
raise e

async def run(self, cmd, stdin="", cwd=None):
return await super().run(
async def run_onced(self, cmd, stdin="", cwd=None):
return await super().run_onced(
["conda", "run", "--no-capture-output", "-p", self.path, "pypy"]
+ cmd,
stdin,
Expand Down
8 changes: 1 addition & 7 deletions partcad/src/partcad/wrappers/wrapper_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from OCP.STEPControl import STEPControl_Reader
import OCP.IFSelect
from OCP.TopoDS import Shape

sys.path.append(os.path.dirname(__file__))
import wrapper_common
Expand All @@ -33,15 +32,10 @@ def process(path, request):
for i in range(reader.NbShapes()):
occ_shapes.append(reader.Shape(i + 1))

# Make sure that we extract all the solids
solids = []
for shape in occ_shapes:
solids.append(Shape.cast(shape))

return {
"success": True,
"exception": None,
"shape": solids,
"shape": occ_shapes,
}


Expand Down

0 comments on commit 020166a

Please sign in to comment.