Skip to content

Commit bdaa099

Browse files
committed
Merge branch 'release/3.0.1'
2 parents 30c7818 + 91c167b commit bdaa099

File tree

8 files changed

+109
-75
lines changed

8 files changed

+109
-75
lines changed

README.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
numpy-stl
22
==============================================================================
33

4+
.. image:: https://github.com/WoLpH/numpy-stl/actions/workflows/main.yml/badge.svg?branch=master
5+
:alt: numpy-stl test status
6+
:target: https://github.com/WoLpH/numpy-stl/actions/workflows/main.yml
47

58
.. image:: https://ci.appveyor.com/api/projects/status/cbv7ak2i59wf3lpj?svg=true
69
:alt: numpy-stl test status
710
:target: https://ci.appveyor.com/project/WoLpH/numpy-stl
811

9-
.. image:: https://github.com/WoLpH/numpy-stl/actions/workflows/main.yml/badge.svg
10-
:alt: numpy-stl test status
11-
:target: https://github.com/WoLpH/numpy-stl/actions
12-
1312
.. image:: https://badge.fury.io/py/numpy-stl.svg
1413
:alt: numpy-stl Pypi version
1514
:target: https://pypi.python.org/pypi/numpy-stl
@@ -26,6 +25,13 @@ and easy.
2625
Due to all operations heavily relying on `numpy` this is one of the fastest
2726
STL editing libraries for Python available.
2827

28+
Security contact information
29+
------------------------------------------------------------------------------
30+
31+
To report a security vulnerability, please use the
32+
`Tidelift security contact <https://tidelift.com/security>`_.
33+
Tidelift will coordinate the fix and disclosure.
34+
2935
Issues
3036
------
3137

appveyor.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ image:
33

44
environment:
55
matrix:
6-
- TOXENV: py36
7-
- TOXENV: py37
86
- TOXENV: py38
9-
# Does not work because of str of py.path
10-
# - TOXENV: py39
11-
# - TOXENV: py310
7+
- TOXENV: py39
8+
- TOXENV: py310
129

1310
install:
1411
# Download setup scripts and unzip

stl/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__package_name__ = 'numpy-stl'
22
__import_name__ = 'stl'
3-
__version__ = '3.0.0'
3+
__version__ = '3.0.1'
44
__author__ = 'Rick van Hattem'
55
__author_email__ = '[email protected]'
66
__description__ = ' '.join('''

stl/main.py

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
1-
import sys
2-
import random
31
import argparse
2+
import random
3+
import sys
44

55
from . import stl
66

77

88
def _get_parser(description):
99
parser = argparse.ArgumentParser(description=description)
10-
parser.add_argument('infile', nargs='?', type=argparse.FileType('rb'),
11-
default=sys.stdin, help='STL file to read')
12-
parser.add_argument('outfile', nargs='?', type=argparse.FileType('wb'),
13-
default=sys.stdout, help='STL file to write')
10+
parser.add_argument(
11+
'infile', nargs='?', type=argparse.FileType('rb'),
12+
default=sys.stdin, help='STL file to read'
13+
)
14+
parser.add_argument(
15+
'outfile', nargs='?', type=argparse.FileType('wb'),
16+
default=sys.stdout, help='STL file to write'
17+
)
1418
parser.add_argument('--name', nargs='?', help='Name of the mesh')
1519
parser.add_argument(
1620
'-n', '--use-file-normals', action='store_true',
17-
help='Read the normals from the file instead of recalculating them')
21+
help='Read the normals from the file instead of recalculating them'
22+
)
1823
parser.add_argument(
1924
'-r', '--remove-empty-areas', action='store_true',
2025
help='Remove areas with 0 surface areas to prevent errors during '
21-
'normal calculation')
22-
parser.add_argument('-s', '--disable-speedups', action='store_true',
23-
help='Disable Cython speedups')
26+
'normal calculation'
27+
)
28+
parser.add_argument(
29+
'-s', '--disable-speedups', action='store_true',
30+
help='Disable Cython speedups'
31+
)
2432
return parser
2533

2634

@@ -33,24 +41,37 @@ def _get_name(args):
3341
]
3442

3543
for name in names: # pragma: no branch
36-
if name and isinstance(name, str) and not name.startswith('<'):
44+
if not isinstance(name, str):
45+
continue
46+
elif name.startswith('<'): # pragma: no cover
47+
continue
48+
elif r'\AppData\Local\Temp' in name: # pragma: no cover
49+
# Windows temp file
50+
continue
51+
else:
3752
return name
3853

3954

4055
def main():
4156
parser = _get_parser('Convert STL files from ascii to binary and back')
42-
parser.add_argument('-a', '--ascii', action='store_true',
43-
help='Write ASCII file (default is binary)')
44-
parser.add_argument('-b', '--binary', action='store_true',
45-
help='Force binary file (for TTYs)')
57+
parser.add_argument(
58+
'-a', '--ascii', action='store_true',
59+
help='Write ASCII file (default is binary)'
60+
)
61+
parser.add_argument(
62+
'-b', '--binary', action='store_true',
63+
help='Force binary file (for TTYs)'
64+
)
4665

4766
args = parser.parse_args()
4867
name = _get_name(args)
49-
stl_file = stl.StlMesh(filename=name,
50-
fh=args.infile,
51-
calculate_normals=False,
52-
remove_empty_areas=args.remove_empty_areas,
53-
speedups=not args.disable_speedups)
68+
stl_file = stl.StlMesh(
69+
filename=name,
70+
fh=args.infile,
71+
calculate_normals=False,
72+
remove_empty_areas=args.remove_empty_areas,
73+
speedups=not args.disable_speedups
74+
)
5475

5576
if args.binary:
5677
mode = stl.BINARY
@@ -59,30 +80,39 @@ def main():
5980
else:
6081
mode = stl.AUTOMATIC
6182

62-
stl_file.save(name, args.outfile, mode=mode,
63-
update_normals=not args.use_file_normals)
83+
stl_file.save(
84+
name, args.outfile, mode=mode,
85+
update_normals=not args.use_file_normals
86+
)
6487

6588

6689
def to_ascii():
6790
parser = _get_parser('Convert STL files to ASCII (text) format')
6891
args = parser.parse_args()
6992
name = _get_name(args)
70-
stl_file = stl.StlMesh(filename=name, fh=args.infile,
71-
calculate_normals=False,
72-
remove_empty_areas=args.remove_empty_areas,
73-
speedups=not args.disable_speedups)
74-
stl_file.save(name, args.outfile, mode=stl.ASCII,
75-
update_normals=not args.use_file_normals)
93+
stl_file = stl.StlMesh(
94+
filename=name, fh=args.infile,
95+
calculate_normals=False,
96+
remove_empty_areas=args.remove_empty_areas,
97+
speedups=not args.disable_speedups
98+
)
99+
stl_file.save(
100+
name, args.outfile, mode=stl.ASCII,
101+
update_normals=not args.use_file_normals
102+
)
76103

77104

78105
def to_binary():
79106
parser = _get_parser('Convert STL files to binary format')
80107
args = parser.parse_args()
81108
name = _get_name(args)
82-
stl_file = stl.StlMesh(filename=name, fh=args.infile,
83-
calculate_normals=False,
84-
remove_empty_areas=args.remove_empty_areas,
85-
speedups=not args.disable_speedups)
86-
stl_file.save(name, args.outfile, mode=stl.BINARY,
87-
update_normals=not args.use_file_normals)
88-
109+
stl_file = stl.StlMesh(
110+
filename=name, fh=args.infile,
111+
calculate_normals=False,
112+
remove_empty_areas=args.remove_empty_areas,
113+
speedups=not args.disable_speedups
114+
)
115+
stl_file.save(
116+
name, args.outfile, mode=stl.BINARY,
117+
update_normals=not args.use_file_normals
118+
)

tests/conftest.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import py
1+
import pathlib
2+
23
import pytest
34

45

@@ -9,35 +10,35 @@ def pytest_generate_tests(metafunc):
910

1011

1112
@pytest.fixture(scope='session')
12-
def cwd():
13-
return py.path.local(__file__).dirpath()
13+
def cwd() -> pathlib.Path:
14+
return pathlib.Path(__file__).parent
1415

1516

1617
@pytest.fixture(scope='session')
17-
def ascii_path(cwd):
18-
return cwd.join('stl_ascii')
18+
def ascii_path(cwd) -> pathlib.Path:
19+
return cwd / 'stl_ascii'
1920

2021

2122
@pytest.fixture(scope='session')
22-
def binary_path(cwd):
23-
return cwd.join('stl_binary')
23+
def binary_path(cwd) -> pathlib.Path:
24+
return cwd / 'stl_binary'
2425

2526

2627
@pytest.fixture(scope='session')
27-
def three_mf_path(cwd):
28-
return cwd.join('3mf')
28+
def three_mf_path(cwd) -> pathlib.Path:
29+
return cwd / '3mf'
2930

3031

3132
@pytest.fixture(scope='session', params=['ascii', 'binary'])
32-
def binary_ascii_path(request, ascii_path, binary_path):
33+
def binary_ascii_path(request, ascii_path, binary_path) -> pathlib.Path:
3334
return ascii_path if request.param == 'ascii' else binary_path
3435

3536

3637
@pytest.fixture(scope='session')
37-
def ascii_file(ascii_path):
38-
return str(ascii_path.join('HalfDonut.stl'))
38+
def ascii_file(ascii_path) -> str:
39+
return str(ascii_path / 'HalfDonut.stl')
3940

4041

4142
@pytest.fixture(scope='session')
42-
def binary_file(binary_path):
43-
return str(binary_path.join('HalfDonut.stl'))
43+
def binary_file(binary_path) -> str:
44+
return str(binary_path / 'HalfDonut.stl')

tests/test_convert.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
# import os
1+
import py.path
22
import pytest
33
import tempfile
44

55
from stl import stl
66

77

88
def _test_conversion(from_, to, mode, speedups):
9+
# For some reason the test fails when using pathlib instead of py.path
10+
from_ = py.path.local(from_)
11+
to = py.path.local(to)
912

1013
for name in from_.listdir():
1114
source_file = from_.join(name)

tests/test_meshProperties.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_mass_properties_for_half_donut(binary_ascii_path, speedups):
1818
One checks the results obtained with stl
1919
with the ones obtained with meshlab
2020
'''
21-
filename = binary_ascii_path.join('HalfDonut.stl')
21+
filename = binary_ascii_path/'HalfDonut.stl'
2222
mesh = stl.StlMesh(str(filename), speedups=speedups)
2323
volume, cog, inertia = mesh.get_mass_properties()
2424
assert close([volume], [2.343149])
@@ -35,7 +35,7 @@ def test_mass_properties_for_moon(binary_ascii_path, speedups):
3535
One checks the results obtained with stl
3636
with the ones obtained with meshlab
3737
'''
38-
filename = binary_ascii_path.join('Moon.stl')
38+
filename = binary_ascii_path/'Moon.stl'
3939
mesh = stl.StlMesh(str(filename), speedups=speedups)
4040
volume, cog, inertia = mesh.get_mass_properties()
4141
assert close([volume], [0.888723])
@@ -54,7 +54,7 @@ def test_mass_properties_for_star(binary_ascii_path, filename, speedups):
5454
One checks the results obtained with stl
5555
with the ones obtained with meshlab
5656
'''
57-
filename = binary_ascii_path.join(filename)
57+
filename = binary_ascii_path/filename
5858
if not filename.exists():
5959
pytest.skip('STL file does not exist')
6060
mesh = stl.StlMesh(str(filename), speedups=speedups)
@@ -74,7 +74,7 @@ def test_mass_properties_for_half_donut_with_density(
7474
One checks the results obtained with stl
7575
with the ones obtained with meshlab
7676
'''
77-
filename = binary_ascii_path.join('HalfDonut.stl')
77+
filename = binary_ascii_path/'HalfDonut.stl'
7878
mesh = stl.StlMesh(str(filename), speedups=speedups)
7979
volume, mass, cog, inertia = mesh.get_mass_properties_with_density(1.23)
8080

tests/test_multiple.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
import pytest
44

55
from stl import mesh
6-
from stl.utils import b
76

8-
_STL_FILE = '''
7+
_STL_FILE = b'''
98
solid test.stl
109
facet normal -0.014565 0.073223 -0.002897
1110
outer loop
@@ -16,12 +15,10 @@
1615
endfacet
1716
endsolid test.stl
1817
'''
19-
# This is split because the pycharm autoformatter breaks the tests otherwise
20-
_STL_FILE = b(_STL_FILE.lstrip())
2118

2219

2320
def test_single_stl(tmpdir, speedups):
24-
tmp_file = tmpdir.join('tmp.stl')
21+
tmp_file = tmpdir / 'tmp.stl'
2522
with tmp_file.open('wb+') as fh:
2623
fh.write(_STL_FILE)
2724
fh.seek(0)
@@ -32,7 +29,7 @@ def test_single_stl(tmpdir, speedups):
3229

3330

3431
def test_multiple_stl(tmpdir, speedups):
35-
tmp_file = tmpdir.join('tmp.stl')
32+
tmp_file = tmpdir / 'tmp.stl'
3633
with tmp_file.open('wb+') as fh:
3734
for _ in range(10):
3835
fh.write(_STL_FILE)
@@ -48,7 +45,7 @@ def test_multiple_stl(tmpdir, speedups):
4845

4946

5047
def test_single_stl_file(tmpdir, speedups):
51-
tmp_file = tmpdir.join('tmp.stl')
48+
tmp_file = tmpdir / 'tmp.stl'
5249
with tmp_file.open('wb+') as fh:
5350
fh.write(_STL_FILE)
5451
fh.seek(0)
@@ -59,7 +56,7 @@ def test_single_stl_file(tmpdir, speedups):
5956

6057

6158
def test_multiple_stl_file(tmpdir, speedups):
62-
tmp_file = tmpdir.join('tmp.stl')
59+
tmp_file = tmpdir / 'tmp.stl'
6360
with tmp_file.open('wb+') as fh:
6461
for _ in range(10):
6562
fh.write(_STL_FILE)
@@ -76,7 +73,7 @@ def test_multiple_stl_file(tmpdir, speedups):
7673

7774

7875
def test_multiple_stl_files(tmpdir, speedups):
79-
tmp_file = tmpdir.join('tmp.stl')
76+
tmp_file = tmpdir / 'tmp.stl'
8077
with tmp_file.open('wb+') as fh:
8178
fh.write(_STL_FILE)
8279
fh.seek(0)
@@ -88,13 +85,13 @@ def test_multiple_stl_files(tmpdir, speedups):
8885

8986

9087
def test_3mf_file(three_mf_path):
91-
for m in mesh.Mesh.from_3mf_file(three_mf_path.join('Moon.3mf')):
88+
for m in mesh.Mesh.from_3mf_file(three_mf_path / 'Moon.3mf'):
9289
print(m)
9390

9491

9592
def test_3mf_missing_file(three_mf_path):
9693
with pytest.raises(FileNotFoundError):
97-
for m in mesh.Mesh.from_3mf_file(three_mf_path.join('some_file.3mf')):
94+
for m in mesh.Mesh.from_3mf_file(three_mf_path / 'some_file.3mf'):
9895
print(m)
9996

10097

0 commit comments

Comments
 (0)