Skip to content

Commit 440e390

Browse files
committed
Merge branch 'release/2.14.0'
2 parents f13669d + 4a04edf commit 440e390

File tree

12 files changed

+259
-96
lines changed

12 files changed

+259
-96
lines changed

.github/stale.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Number of days of inactivity before an issue becomes stale
2-
daysUntilStale: 60
2+
daysUntilStale: 30
33
# Number of days of inactivity before a stale issue is closed
44
daysUntilClose: 7
55
# Issues with these labels will never be considered stale

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ cache:
1010
env:
1111
- TOX_ENV=docs
1212
- TOX_ENV=flake8
13-
- TOX_ENV=py27-nix
14-
- TOX_ENV=py34-nix
15-
- TOX_ENV=py35-nix
16-
# - TOX_ENV=py36-nix
13+
- TOX_ENV=py36-nix
1714
- TOX_ENV=py37-nix
1815
- TOX_ENV=py38-nix
1916
- TOX_ENV=py39-nix

README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ numpy-stl
22
==============================================================================
33

44

5+
.. image:: https://ci.appveyor.com/api/projects/status/cbv7ak2i59wf3lpj?svg=true
6+
:alt: numpy-stl test status
7+
:target: https://ci.appveyor.com/project/WoLpH/numpy-stl
8+
59
.. image:: https://travis-ci.org/WoLpH/numpy-stl.svg?branch=master
610
:alt: numpy-stl test status
711
:target: https://travis-ci.org/WoLpH/numpy-stl
@@ -406,3 +410,8 @@ Combining multiple STL files
406410
407411
combined.save('combined.stl', mode=stl.Mode.ASCII) # save as ASCII
408412
413+
Known limitations
414+
------------------------------------------------------------------------------
415+
416+
- When speedups are enabled the STL name is automatically converted to
417+
lowercase.

appveyor.yml

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,14 @@ environment:
44
# See: http://stackoverflow.com/a/13751649/163740
55
# CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_env.cmd"
66

7+
global:
8+
PYTHON: "C:\\Python38-x64\\python.exe"
79
matrix:
8-
- PYTHON: "C:\\Python27"
9-
PYTHON_VERSION: "2.7"
10-
PYTHON_ARCH: "32"
11-
TOXENV: py27-windows-32
12-
13-
- PYTHON: "C:\\Python27-x64"
14-
PYTHON_VERSION: "2.7"
15-
PYTHON_ARCH: "64"
16-
TOXENV: py27-windows-64
17-
18-
- PYTHON: "C:\\Python34"
19-
PYTHON_VERSION: "3.4"
20-
PYTHON_ARCH: "32"
21-
TOXENV: py34-windows-32
22-
23-
- PYTHON: "C:\\Python34-x64"
24-
PYTHON_VERSION: "3.4"
25-
PYTHON_ARCH: "64"
26-
TOXENV: py34-windows-64
27-
DISTUTILS_USE_SDK: "1"
28-
29-
- PYTHON: "C:\\Python35"
30-
PYTHON_VERSION: "3.5"
31-
PYTHON_ARCH: "32"
32-
TOXENV: py35-windows-32
33-
34-
- PYTHON: "C:\\Python35-x64"
35-
PYTHON_VERSION: "3.5"
36-
PYTHON_ARCH: "64"
37-
TOXENV: py35-windows-64
10+
- TOXENV: py36
11+
- TOXENV: py37
12+
- TOXENV: py38
13+
# not yet available on appveyor
14+
# - TOXENV: py39
3815

3916
install:
4017
# Download setup scripts and unzip
@@ -51,13 +28,20 @@ install:
5128
# - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
5229

5330
# Check that we have the expected version and architecture for Python
54-
- "python --version"
55-
- "python -c \"import struct; print(struct.calcsize('P') * 8)\""
31+
- "%PYTHON% --version"
32+
- "%PYTHON% -c \"import struct; print(struct.calcsize('P') * 8)\""
5633

5734
build: false # Not a C# project, build stuff at the test step instead.
5835

5936
before_test:
60-
- build.cmd %PYTHON%\\python.exe -m pip install tox numpy cython"
37+
- "%PYTHON% -m pip install tox numpy cython wheel"
6138

6239
test_script:
63-
- build.cmd %PYTHON%\\python.exe -m tox -e %TOXENV%"
40+
- "%PYTHON% -m tox -e %TOXENV%"
41+
42+
after_test:
43+
- "%PYTHON% setup.py sdist bdist_wheel"
44+
- ps: "ls dist"
45+
46+
artifacts:
47+
- path: dist\*

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__ = '2.13.1'
3+
__version__ = '2.14.0'
44
__author__ = 'Rick van Hattem'
55
__author_email__ = '[email protected]'
66
__description__ = ' '.join('''

stl/stl.py

Lines changed: 63 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -65,32 +65,34 @@ def load(cls, fh, mode=AUTOMATIC, speedups=True):
6565
if isinstance(header, str): # pragma: no branch
6666
header = b(header)
6767

68-
name = ''
69-
70-
if mode in (AUTOMATIC, ASCII) and header[:5].lower() == b('solid'):
71-
try:
72-
name, data = cls._load_ascii(
73-
fh, header, speedups=speedups)
74-
except RuntimeError as exception:
75-
# Disable fallbacks in ASCII mode
76-
if mode is ASCII:
77-
raise
78-
79-
(recoverable, e) = exception.args
80-
# If we didn't read beyond the header the stream is still
81-
# readable through the binary reader
82-
if recoverable:
83-
name, data = cls._load_binary(fh, header, check_size=False)
84-
else:
85-
# Apparently we've read beyond the header. Let's try
86-
# seeking :)
87-
# Note that this fails when reading from stdin, we can't
88-
# recover from that.
89-
fh.seek(HEADER_SIZE)
90-
91-
# Since we know this is a seekable file now and we're not
92-
# 100% certain it's binary, check the size while reading
93-
name, data = cls._load_binary(fh, header, check_size=True)
68+
if mode is AUTOMATIC:
69+
if header.lstrip().lower().startswith(b'solid'):
70+
try:
71+
name, data = cls._load_ascii(
72+
fh, header, speedups=speedups)
73+
except RuntimeError as exception:
74+
(recoverable, e) = exception.args
75+
# If we didn't read beyond the header the stream is still
76+
# readable through the binary reader
77+
if recoverable:
78+
name, data = cls._load_binary(fh, header,
79+
check_size=False)
80+
else:
81+
# Apparently we've read beyond the header. Let's try
82+
# seeking :)
83+
# Note that this fails when reading from stdin, we
84+
# can't recover from that.
85+
fh.seek(HEADER_SIZE)
86+
87+
# Since we know this is a seekable file now and we're
88+
# not 100% certain it's binary, check the size while
89+
# reading
90+
name, data = cls._load_binary(fh, header,
91+
check_size=True)
92+
else:
93+
name, data = cls._load_binary(fh, header)
94+
elif mode is ASCII:
95+
name, data = cls._load_ascii(fh, header, speedups=speedups)
9496
else:
9597
name, data = cls._load_binary(fh, header)
9698

@@ -231,6 +233,7 @@ def _load_ascii(cls, fh, header, speedups=True):
231233
else:
232234
iterator = cls._ascii_reader(fh, header)
233235
name = next(iterator)
236+
print('got name', name)
234237
return name, numpy.fromiter(iterator, dtype=cls.dtype)
235238

236239
def save(self, filename, fh=None, mode=AUTOMATIC, update_normals=True):
@@ -249,8 +252,17 @@ def save(self, filename, fh=None, mode=AUTOMATIC, update_normals=True):
249252
self.update_normals()
250253

251254
if mode is AUTOMATIC:
252-
if fh and os.isatty(fh.fileno()): # pragma: no cover
253-
write = self._write_ascii
255+
# Try to determine if the file is a TTY.
256+
if fh:
257+
try:
258+
if os.isatty(fh.fileno()): # pragma: no cover
259+
write = self._write_ascii
260+
else:
261+
write = self._write_binary
262+
except IOError:
263+
# If TTY checking fails then it's an io.BytesIO() (or one
264+
# of its siblings from io). Assume binary.
265+
write = self._write_binary
254266
else:
255267
write = self._write_binary
256268
elif mode is BINARY:
@@ -260,6 +272,13 @@ def save(self, filename, fh=None, mode=AUTOMATIC, update_normals=True):
260272
else:
261273
raise ValueError('Mode %r is invalid' % mode)
262274

275+
if isinstance(fh, io.TextIOBase):
276+
# Provide a more helpful error if the user mistakenly
277+
# assumes ASCII files should be text files.
278+
raise TypeError(
279+
"File handles should be in binary mode - even when"
280+
" writing an ASCII STL.")
281+
263282
name = os.path.split(filename)[-1]
264283
try:
265284
if fh:
@@ -271,7 +290,13 @@ def save(self, filename, fh=None, mode=AUTOMATIC, update_normals=True):
271290
pass
272291

273292
def _write_ascii(self, fh, name):
274-
if _speedups and self.speedups: # pragma: no cover
293+
try:
294+
fh.fileno()
295+
speedups = self.speedups
296+
except io.UnsupportedOperation:
297+
speedups = False
298+
299+
if _speedups and speedups: # pragma: no cover
275300
_speedups.ascii_write(fh, b(name), self.data)
276301
else:
277302
def p(s, file):
@@ -315,8 +340,16 @@ def _write_binary(self, fh, name):
315340

316341
fh.write(header)
317342
fh.write(packed)
318-
self.data.tofile(fh)
319343

344+
if isinstance(fh, io.BufferedWriter):
345+
# Write to a true file.
346+
self.data.tofile(fh)
347+
else:
348+
# Write to a pseudo buffer.
349+
fh.write(self.data.data)
350+
351+
# In theory this should no longer be possible but I'll leave it here
352+
# anyway...
320353
if self.data.size: # pragma: no cover
321354
assert fh.tell() > 84, (
322355
'numpy silently refused to write our file. Note that writing '
@@ -403,4 +436,3 @@ def from_files(cls, filenames, calculate_normals=True, mode=Mode.AUTOMATIC,
403436

404437

405438
StlMesh = BaseStl.from_file
406-

tests/stl_ascii/Cube.stl

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
solid PRO2STL version 1.0
2+
facet normal -1 0 0
3+
outer loop
4+
vertex 0 2 2
5+
vertex 0 2 0
6+
vertex 0 0 0
7+
endloop
8+
endfacet
9+
facet normal -1 0 0
10+
outer loop
11+
vertex 0 0 0
12+
vertex 0 0 2
13+
vertex 0 2 2
14+
endloop
15+
endfacet
16+
facet normal 0 1 -0
17+
outer loop
18+
vertex 2 2 2
19+
vertex 2 2 0
20+
vertex 0 2 0
21+
endloop
22+
endfacet
23+
facet normal -0 1 0
24+
outer loop
25+
vertex 0 2 0
26+
vertex 0 2 2
27+
vertex 2 2 2
28+
endloop
29+
endfacet
30+
facet normal 1 0 0
31+
outer loop
32+
vertex 2 0 2
33+
vertex 2 0 0
34+
vertex 2 2 0
35+
endloop
36+
endfacet
37+
facet normal 1 0 0
38+
outer loop
39+
vertex 2 2 0
40+
vertex 2 2 2
41+
vertex 2 0 2
42+
endloop
43+
endfacet
44+
facet normal 0 -1 0
45+
outer loop
46+
vertex 0 0 2
47+
vertex 0 0 0
48+
vertex 2 0 0
49+
endloop
50+
endfacet
51+
facet normal -0 -1 -0
52+
outer loop
53+
vertex 2 0 0
54+
vertex 2 0 2
55+
vertex 0 0 2
56+
endloop
57+
endfacet
58+
facet normal -0 0 1
59+
outer loop
60+
vertex 2 2 2
61+
vertex 0 2 2
62+
vertex 0 0 2
63+
endloop
64+
endfacet
65+
facet normal 0 -0 1
66+
outer loop
67+
vertex 0 0 2
68+
vertex 2 0 2
69+
vertex 2 2 2
70+
endloop
71+
endfacet
72+
facet normal 0 0 -1
73+
outer loop
74+
vertex 2 0 0
75+
vertex 0 0 0
76+
vertex 0 2 0
77+
endloop
78+
endfacet
79+
facet normal -0 -0 -1
80+
outer loop
81+
vertex 0 2 0
82+
vertex 2 2 0
83+
vertex 2 0 0
84+
endloop
85+
endfacet
86+
endsolid PRO2STL version 1.0

tests/stl_binary/Cube.stl

684 Bytes
Binary file not shown.
684 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)