Merge pull request #38 from openscad/remove-external-modules

Remove external modules
This commit is contained in:
Chow Loong Jin 2018-09-24 12:15:48 +08:00 committed by GitHub
commit 0209686202
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 56 additions and 38 deletions

3
.gitignore vendored
View file

@ -1 +1,4 @@
*~ *~
*.pyc
.pytest_cache/
__pycache__/

6
.gitmodules vendored
View file

@ -1,6 +0,0 @@
[submodule "SolidPython"]
path = SolidPython
url = https://github.com/SolidCode/SolidPython.git
[submodule "ThingDoc"]
path = ThingDoc
url = https://github.com/SolidCode/ThingDoc.git

View file

@ -1,4 +1,4 @@
OpenSCAD MCAD Library [![](http://stillmaintained.com/elmom/MCAD.png)](http://stillmaintained.com/elmom/MCAD) OpenSCAD MCAD Library
===================== =====================
This library contains components commonly used in designing and moching up This library contains components commonly used in designing and moching up
@ -6,10 +6,10 @@ mechanical designs. It is currently unfinished and you can expect some API
changes, however many things are already working. changes, however many things are already working.
This library was created by various authors as named in the individual This library was created by various authors as named in the individual
files' comments. All the files except those ThingDoc are licensed under files' comments. All the files are licensed under the LGPL 2.1 (see
the LGPL 2.1 (see http://creativecommons.org/licenses/LGPL/2.1/ or the http://creativecommons.org/licenses/LGPL/2.1/ or the included file
included file lgpl-2.1.txt), some of them allow distribution under more lgpl-2.1.txt), some of them allow distribution under more permissive
permissive terms (as described in the files' comments). terms (as described in the files' comments).
## Usage ## ## Usage ##
@ -46,7 +46,7 @@ Currently Provided Tools:
* motors.scad: * motors.scad:
- stepper_motor_mount(nema_standard, slide_distance OPTIONAL, mochup OPTIONAL) - stepper_motor_mount(nema_standard, slide_distance OPTIONAL, mochup OPTIONAL)
Other tools (alpha and beta quality): Tools (alpha and beta quality):
* nuts_and_bolts.scad: for creating metric and imperial bolt/nut holes * nuts_and_bolts.scad: for creating metric and imperial bolt/nut holes
* bearing.scad: standard/custom bearings * bearing.scad: standard/custom bearings
@ -69,11 +69,30 @@ Very generally useful functions and constants:
* shapes.scad: DEPRECATED simple shapes by Catarina Mota * shapes.scad: DEPRECATED simple shapes by Catarina Mota
* polyholes.scad: holes that should come out well when printed * polyholes.scad: holes that should come out well when printed
Other:
* alphabet_block.scad
* bitmap.scad
* letter_necklace.scad
* name_tag.scad
* height_map.scad
* trochoids.scad
* libtriangles.scad
* layouts.scad
* transformations.scad
* 2Dshapes.scad
* gridbeam.scad
* fonts.scad
* unregular_shapes.scad
* metric_fastners.scad
* lego_compatibility.scad
* multiply.scad
* hardware.scad
External utils that generate and and process openscad code: External utils that generate and and process openscad code:
* openscad_testing.py: testing code, see below * openscad_testing.py: testing code, see below
* openscad_utils.py: code for scraping function names etc. * openscad_utils.py: code for scraping function names etc.
* SolidPython: An external Python library for solid cad
## Development ## ## Development ##

@ -1 +0,0 @@
Subproject commit ecf1c0888ad323e2be5b2ec1578773be46b72435

@ -1 +0,0 @@
Subproject commit 54c83e5a41131156cad0ce7e3271433b1035aab1

View file

@ -7,16 +7,20 @@ temppath = py.test.ensuretemp('MCAD')
def pytest_generate_tests(metafunc): def pytest_generate_tests(metafunc):
if "modpath" in metafunc.funcargnames: if "modpath" in metafunc.funcargnames:
args1 = []
args2 = []
for fpath, modnames in collect_test_modules().items(): for fpath, modnames in collect_test_modules().items():
basename = os.path.splitext(os.path.split(str(fpath))[1])[0] basename = os.path.splitext(os.path.split(str(fpath))[1])[0]
#os.system("cp %s %s/" % (fpath, temppath))
if "modname" in metafunc.funcargnames: if "modname" in metafunc.funcargnames:
for modname in modnames: for modname in modnames:
print modname args2.append([fpath, modname])
metafunc.addcall(id=basename+"/"+modname, funcargs=dict(modname=modname, modpath=fpath))
else: else:
metafunc.addcall(id=os.path.split(str(fpath))[1], funcargs=dict(modpath=fpath)) args1.append(fpath)
if "modname" in metafunc.funcargnames:
metafunc.parametrize(["modpath", "modname"], args2)
else:
metafunc.parametrize("modpath", args1)
def test_module_compile(modname, modpath): def test_module_compile(modname, modpath):
tempname = modpath.basename + '-' + modname + '.scad' tempname = modpath.basename + '-' + modname + '.scad'
@ -29,23 +33,21 @@ use <%s>
%s(); %s();
""" % (modpath, modname) """ % (modpath, modname)
print code print(code)
f.write(code) f.write(code)
f.flush() f.flush()
output = call_openscad(path=fpath, stlpath=stlpath, timeout=15) output = call_openscad(path=fpath, stlpath=stlpath, timeout=60)
print output print(output)
assert output[0] is 0 assert output[0] is 0
for s in ("warning", "error"): for s in ("warning", "error"):
assert s not in output[2].strip().lower() assert s not in output[2].strip().lower().decode("utf-8")
assert len(stlpath.readlines()) > 2 assert len(stlpath.readlines()) > 2
def test_file_compile(modpath): def test_file_compile(modpath):
stlpath = temppath.join(modpath.basename + "-test.stl") stlpath = temppath.join(modpath.basename + "-test.stl")
output = call_openscad(path=modpath, stlpath=stlpath) output = call_openscad(path=modpath, stlpath=stlpath)
print output print(output)
assert output[0] is 0 assert output[0] is 0
for s in ("warning", "error"): for s in ("warning", "error"):
assert s not in output[2].strip().lower() assert s not in output[2].strip().lower().decode("utf-8")
assert len(stlpath.readlines()) == 2 assert len(stlpath.readlines()) == 2

View file

@ -1,4 +1,4 @@
import py, re, os, signal, time, commands, sys import py, re, os, signal, time, subprocess, sys
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
mod_re = (r"\bmodule\s+(", r")\s*\(\s*") mod_re = (r"\bmodule\s+(", r")\s*\(\s*")
@ -17,11 +17,11 @@ def extract_func_names(fpath, name_re=r"\w+"):
def collect_test_modules(dirpath=None): def collect_test_modules(dirpath=None):
dirpath = dirpath or py.path.local("./") dirpath = dirpath or py.path.local("./")
print "Collecting openscad test module names" print("Collecting openscad test module names")
test_files = {} test_files = {}
for fpath in dirpath.visit('*.scad'): for fpath in dirpath.visit('*.scad'):
#print fpath #print(fpath)
modules = extract_mod_names(fpath, r"test\w*") modules = extract_mod_names(fpath, r"test\w*")
#functions = extract_func_names(fpath, r"test\w*") #functions = extract_func_names(fpath, r"test\w*")
test_files[fpath] = modules test_files[fpath] = modules
@ -32,20 +32,20 @@ class Timeout(Exception): pass
def call_openscad(path, stlpath, timeout=5): def call_openscad(path, stlpath, timeout=5):
if sys.platform == 'darwin': exe = 'OpenSCAD.app/Contents/MacOS/OpenSCAD' if sys.platform == 'darwin': exe = 'OpenSCAD.app/Contents/MacOS/OpenSCAD'
else: exe = 'openscad' else: exe = 'openscad'
command = [exe, '-s', str(stlpath), str(path)] command = [exe, '-o', str(stlpath), str(path)]
print command print(command)
if timeout: if timeout:
try: try:
proc = Popen(command, proc = Popen(command,
stdout=PIPE, stderr=PIPE, close_fds=True) stdout=PIPE, stderr=PIPE, close_fds=True)
calltime = time.time() calltime = time.time()
time.sleep(0.05) time.sleep(0.05)
#print calltime #print(calltime)
while True: while True:
if proc.poll() is not None: if proc.poll() is not None:
break break
time.sleep(0.5) time.sleep(0.5)
#print time.time() #print(time.time())
if time.time() > calltime + timeout: if time.time() > calltime + timeout:
raise Timeout() raise Timeout()
finally: finally:
@ -57,7 +57,7 @@ def call_openscad(path, stlpath, timeout=5):
return (proc.returncode,) + proc.communicate() return (proc.returncode,) + proc.communicate()
else: else:
output = commands.getstatusoutput(" ".join(command)) output = subprocess.getstatusoutput(" ".join(command)).decode("utf-8")
return output + ('', '') return output + ('', '')
def parse_output(text): def parse_output(text):

View file

@ -4,15 +4,17 @@ import os.path
dirpath = py.path.local("./") dirpath = py.path.local("./")
def pytest_generate_tests(metafunc): def pytest_generate_tests(metafunc):
names = []
if "filename" in metafunc.funcargnames: if "filename" in metafunc.funcargnames:
for fpath in dirpath.visit('*.scad'): for fpath in dirpath.visit('*.scad'):
metafunc.addcall(id=fpath.basename, funcargs=dict(filename=fpath.basename)) names.append(fpath.basename)
for fpath in dirpath.visit('*.py'): for fpath in dirpath.visit('*.py'):
name = fpath.basename name = fpath.basename
if not (name.startswith('test_') or name.startswith('_')): if not (name.startswith('test_') or name.startswith('_')):
metafunc.addcall(id=fpath.basename, funcargs=dict(filename=fpath.basename)) names.append(name)
metafunc.parametrize("filename", names)
def test_README(filename): def test_README(filename):
README = dirpath.join('README').read() README = dirpath.join('README.markdown').read()
assert filename in README assert filename in README