Skip to content

Commit 8a8b996

Browse files
authored
Remove path dependency (#1987)
* Remove path dependency * Update vis screenshot test * Use conda-forge for sphinx theme * Revert use conda-forge for sphinx theme * Remove Python 3.8 pytest workaround * Remove path from conda meta.yaml
1 parent 9265c13 commit 8a8b996

File tree

8 files changed

+53
-36
lines changed

8 files changed

+53
-36
lines changed

cadquery/occ_impl/importers/assembly.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import cast
2-
from path import Path
2+
from pathlib import Path
33

44
from OCP.TopoDS import TopoDS_Shape
55
from OCP.TCollection import TCollection_ExtendedString
@@ -175,7 +175,8 @@ def importXbf(assy: AssemblyProtocol, path: str):
175175
app = TDocStd_Application()
176176
BinXCAFDrivers.DefineFormat_s(app)
177177

178-
dirname, fname = Path(path).absolute().splitpath()
178+
p = Path(path).absolute()
179+
dirname, fname = str(p.parent), p.name
179180
doc = cast(
180181
TDocStd_Document,
181182
app.Retrieve(
@@ -204,7 +205,8 @@ def importXml(assy: AssemblyProtocol, path: str):
204205
app = TDocStd_Application()
205206
XmlXCAFDrivers.DefineFormat_s(app)
206207

207-
dirname, fname = Path(path).absolute().splitpath()
208+
p = Path(path).absolute()
209+
dirname, fname = str(p.parent), p.name
208210
doc = cast(
209211
TDocStd_Document,
210212
app.Retrieve(

environment.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ dependencies:
1616
- ezdxf>=1.3.0
1717
- typing_extensions
1818
- nlopt
19-
- path
2019
- casadi
2120
- runtype
2221
- multimethod >=1.11,<2.0

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"nlopt>=2.9.0,<3.0",
3333
"runtype",
3434
"casadi",
35-
"path",
3635
"trame",
3736
"trame-vtk",
3837
"trame-components",

tests/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import pytest
2+
import os
3+
from contextlib import contextmanager
24

35

46
def pytest_addoption(parser):
@@ -20,3 +22,17 @@ def pytest_collection_modifyitems(config, items):
2022
for item in items:
2123
if "gui" in item.keywords:
2224
item.add_marker(skip_gui)
25+
26+
27+
@pytest.fixture
28+
def cwd():
29+
@contextmanager
30+
def _cwd(path):
31+
oldpwd = os.getcwd()
32+
os.chdir(path)
33+
try:
34+
yield
35+
finally:
36+
os.chdir(oldpwd)
37+
38+
return _cwd

tests/test_assembly.py

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from itertools import product
44
from math import degrees
55
import copy
6-
from path import Path
6+
from pathlib import Path
77
from pathlib import PurePath
88
import re
99
from pytest import approx
@@ -41,7 +41,7 @@
4141

4242
@pytest.fixture(scope="function")
4343
def tmpdir(tmp_path_factory):
44-
return Path(tmp_path_factory.mktemp("assembly"))
44+
return tmp_path_factory.mktemp("assembly")
4545

4646

4747
@pytest.fixture
@@ -557,18 +557,6 @@ def find_node(node_list, name_path):
557557
:param name_path: list of node names (corresponding to path)
558558
"""
559559

560-
def purepath_is_relative_to(p0, p1):
561-
"""Alternative to PurePath.is_relative_to for Python 3.8
562-
PurePath.is_relative_to is new in Python 3.9
563-
"""
564-
try:
565-
if p0.relative_to(p1):
566-
is_relative_to = True
567-
except ValueError:
568-
is_relative_to = False
569-
570-
return is_relative_to
571-
572560
def get_nodes(node_list, name, parents):
573561
if parents:
574562
nodes = []
@@ -577,8 +565,7 @@ def get_nodes(node_list, name, parents):
577565
[
578566
p
579567
for p in node_list
580-
# if p["path"].is_relative_to(parent["path"])
581-
if purepath_is_relative_to(p["path"], parent["path"])
568+
if p["path"].is_relative_to(parent["path"])
582569
and len(p["path"].relative_to(parent["path"]).parents) == 1
583570
and re.fullmatch(name, p["name"])
584571
and p not in nodes
@@ -1376,18 +1363,18 @@ def test_save(extension, args, nested_assy, nested_assy_sphere):
13761363
("stl", ("STL",), {}),
13771364
],
13781365
)
1379-
def test_export(extension, args, kwargs, tmpdir, nested_assy):
1366+
def test_export(extension, args, kwargs, tmpdir, nested_assy, cwd):
13801367

13811368
filename = "nested." + extension
13821369

1383-
with tmpdir:
1370+
with cwd(tmpdir):
13841371
nested_assy.export(filename, *args, **kwargs)
13851372
assert os.path.exists(filename)
13861373

13871374

1388-
def test_export_vtkjs(tmpdir, nested_assy):
1375+
def test_export_vtkjs(tmpdir, nested_assy, cwd):
13891376

1390-
with tmpdir:
1377+
with cwd(tmpdir):
13911378
nested_assy.export("nested.vtkjs")
13921379
assert os.path.exists("nested.vtkjs.zip")
13931380

@@ -1553,7 +1540,7 @@ def test_colors_assy0(assy_fixture, request, tmpdir, kind):
15531540
"""
15541541

15551542
assy = request.getfixturevalue(assy_fixture)
1556-
stepfile = (Path(tmpdir) / assy_fixture).with_suffix(f".{kind}")
1543+
stepfile = str((Path(tmpdir) / assy_fixture).with_suffix(f".{kind}"))
15571544
assy.export(stepfile)
15581545

15591546
assy_i = assy.load(stepfile)
@@ -1585,7 +1572,7 @@ def test_colors_assy1(assy_fixture, request, tmpdir, kind):
15851572
"""
15861573

15871574
assy = request.getfixturevalue(assy_fixture)
1588-
stepfile = (Path(tmpdir) / assy_fixture).with_suffix(f".{kind}")
1575+
stepfile = str((Path(tmpdir) / assy_fixture).with_suffix(f".{kind}"))
15891576
assy.export(stepfile)
15901577

15911578
assy_i = assy.load(stepfile)

tests/test_examples.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from glob import glob
44
from itertools import chain, count
55

6-
from path import Path
6+
from pathlib import Path
77

88
from docutils.parsers.rst import directives
99
from docutils.core import publish_doctree
@@ -14,6 +14,11 @@
1414
from cadquery.cq_directive import cq_directive
1515

1616

17+
@pytest.fixture(scope="session")
18+
def tmpdir(tmp_path_factory):
19+
return tmp_path_factory.mktemp("examples")
20+
21+
1722
def find_examples(pattern="examples/*.py", path=Path("examples")):
1823

1924
for p in glob(pattern):
@@ -56,10 +61,11 @@ def run(self):
5661
@pytest.mark.parametrize(
5762
"code, path", chain(find_examples(), find_examples_in_docs()), ids=count(0)
5863
)
59-
def test_example(code, path):
64+
def test_example(code, path, tmpdir, cwd):
6065

6166
# build
62-
with path:
67+
with cwd(tmpdir):
68+
# tmpdir is for future use; currently there are no examples that export files
6369
res = cqgi.parse(code).build()
6470

6571
assert res.exception is None

tests/test_exporters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# core modules
55
import os
66
import io
7-
from path import Path
7+
from pathlib import Path
88
import re
99
import sys
1010
import math

tests/test_vis.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
from vtkmodules.vtkRenderingAnnotation import vtkAnnotatedCubeActor
1818
from vtkmodules.vtkIOImage import vtkPNGWriter
1919

20-
from pytest import fixture, raises
21-
from path import Path
20+
from pytest import fixture, raises, mark
21+
import os
22+
from pathlib import Path
2223

2324
from typing import List
2425

2526

2627
@fixture(scope="module")
2728
def tmpdir(tmp_path_factory):
28-
return Path(tmp_path_factory.mktemp("screenshots"))
29+
return tmp_path_factory.mktemp("screenshots")
2930

3031

3132
@fixture
@@ -138,11 +139,18 @@ def test_show(wp, assy, sk, patch_vtk):
138139
show(vtkAxesActor(), [vtkAnnotatedCubeActor()])
139140

140141

141-
def test_screenshot(wp, tmpdir, patch_vtk):
142+
def test_screenshot(wp, patch_vtk):
142143

143144
# smoke test for now
144-
with tmpdir:
145+
show(wp, interact=False, screenshot="img.png", trihedron=False, gradient=False)
146+
147+
148+
@mark.skip(reason="running only smoke test for now")
149+
def test_screenshot_no_patch(wp, tmpdir, cwd):
150+
151+
with cwd(tmpdir):
145152
show(wp, interact=False, screenshot="img.png", trihedron=False, gradient=False)
153+
assert (Path(tmpdir) / "img.png").exists()
146154

147155

148156
def test_ctrlPts():

0 commit comments

Comments
 (0)