Repository navigation
Faster startup: ezdxf and vtk imported on use #2097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kimstik
wants to merge
7
commits into
CadQuery:master
Choose a base branch
from
kimstik:dxf_vtk
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+144
−32
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
21df307
Import ezdxf on use
87ca6f5
Import vtk on use
1c4d0e9
Import ezdxf and vtk in the top-level modules
e820516
Drop the lazy dxf attribute of importers
1a2ae70
Test the lazy names of exporters in process
02a0aa3
Exclude type checking imports from coverage
cf8c62f
Deprecate the exporters in cadquery.assembly
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,5 @@ omit = | |
| exclude_lines = | ||
| # Ignore stub body | ||
| \.\.\. | ||
| # Ignore imports for type checking only | ||
| if TYPE_CHECKING: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| from typing import Union, Literal | ||
|
|
||
| UnitLiterals = Literal["MM", "CM", "M", "KM", "INCH", "FT", "MI", "UM", "NM"] | ||
| STEPExportModeLiterals = Literal["default", "fused"] | ||
| Real = Union[int, float] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import os | ||
| import subprocess | ||
| import sys | ||
|
|
||
| import pytest | ||
|
|
||
| import cadquery | ||
| from cadquery.occ_impl import exporters | ||
| from cadquery.occ_impl.exporters import assembly, dxf, vtk | ||
|
|
||
|
|
||
| def test_import_does_not_load_ezdxf_or_vtk(): | ||
| # a fresh interpreter: this process has ezdxf and vtk loaded by other tests | ||
| code = ( | ||
| "import sys, cadquery as cq;" | ||
| "print({m.split('.')[0] for m in sys.modules} & {'ezdxf', 'vtkmodules'});" | ||
| # the submodules stay reachable through the packages | ||
| "cq.exporters.assembly.ExportModes, cq.exporters.dxf, cq.exporters.vtk;" | ||
| "print('ok')" | ||
| ) | ||
| # run next to the package under test; only stdout is checked, since the | ||
| # interpreter may crash on exit on Windows (#1911) | ||
| out = subprocess.run( | ||
| [sys.executable, "-u", "-c", code], | ||
| cwd=os.path.dirname(os.path.dirname(cadquery.__file__)), | ||
| capture_output=True, | ||
| text=True, | ||
| ) | ||
|
|
||
| assert out.stdout.split() == ["set()", "ok"], out.stdout + out.stderr | ||
|
|
||
|
|
||
| def test_exporters_lazy_names(): | ||
| # the submodules are attributes here already, so ask __getattr__ directly | ||
| assert exporters.__getattr__("dxf") is dxf | ||
| assert exporters.__getattr__("vtk") is vtk | ||
| assert exporters.__getattr__("assembly") is assembly | ||
|
|
||
| assert exporters.exportDXF is dxf.exportDXF | ||
| assert exporters.exportDXFProjection is dxf.exportDXFProjection | ||
| assert exporters.DxfDocument is dxf.DxfDocument | ||
| assert exporters.exportVTP is vtk.exportVTP | ||
|
|
||
| with pytest.raises(AttributeError): | ||
| exporters.nonexistent | ||
|
|
||
|
|
||
| def test_assembly_exporters_deprecated(): | ||
| for name in ( | ||
| "exportAssembly", | ||
| "exportCAF", | ||
| "exportVTKJS", | ||
| "exportVRML", | ||
| "exportGLTF", | ||
| ): | ||
| with pytest.deprecated_call(): | ||
| assert getattr(cadquery.assembly, name) is getattr(assembly, name) | ||
|
|
||
| with pytest.raises(AttributeError): | ||
| cadquery.assembly.nonexistent |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.