-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
191 additions
and
95 deletions.
There are no files selected for viewing
This file contains 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,28 @@ | ||
--- | ||
name: Release pypi package | ||
on: | ||
push: | ||
branches: | ||
- "!*" | ||
tags: | ||
- "v*" | ||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout/@v3 | ||
- run: sed -i -e "s/^\(version = \).*/\1${GITHUB_REF_NAME/v}/" setup.cfg | ||
- uses: actions/setup-python@v3 | ||
with: | ||
python-version: '3.x' | ||
- run: pip install -r test-requirements.txt | ||
- run: pip install -e . | ||
- run: python -m pytest | ||
- run: python -m pylint src tests ldraw2scad | ||
- run: python -m pycodestyle src tests ldraw2scad | ||
- run: python -m build | ||
- run: pip install twine | ||
- run: python -m twine upload dist/* --verbose | ||
env: | ||
TWINE_USERNAME: __token__ | ||
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
This file contains 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 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,6 +1,9 @@ | ||
lib/ | ||
LDraw/ | ||
dist/ | ||
__pycache__/ | ||
.vscode/ | ||
test_anim/ | ||
.cache/ | ||
pytestdebug.log | ||
*.egg-info |
This file contains 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 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,88 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" Translate LDraw library or file to OpenSCAD library or file. """ | ||
|
||
import os | ||
import argparse | ||
from ldraw_to_scad import LDrawConverter | ||
|
||
|
||
def translate_dir(converter, src, dest, self_contained=False): | ||
""" translate a whole model directory """ | ||
types = ['.mpd', '.ldr', '.dat'] | ||
lst = {} | ||
for fdir, _, files in os.walk(src, followlinks=True): | ||
rel = os.path.relpath(fdir, src) | ||
for file in sorted(files): | ||
base, ext = os.path.splitext(file) | ||
key = os.path.join(rel, base) | ||
if ext in types: | ||
# We will now override the old extension with the new | ||
# one. Therefore let's warn the user that the one with | ||
# the old extension will get skipped. | ||
if key in lst: | ||
print(f'Skipping {os.path.join(src, key+lst[key])}') | ||
lst[key] = ext | ||
for key, value in lst.items(): | ||
print(f'Translating {os.path.join(src,key+value)}' | ||
f' to {os.path.join(dest,key+".scad")}...') | ||
converter.convert_file(os.path.join(src, key+value), | ||
os.path.join(dest, key+".scad"), | ||
self_contained) | ||
|
||
|
||
def main(): | ||
""" Main function """ | ||
parser = argparse.ArgumentParser( | ||
description='Convert an LDraw part to OpenSCAD') | ||
group = parser.add_mutually_exclusive_group(required=True) | ||
group.add_argument( | ||
'-t', '--translib', action='store_true', | ||
help='translate the library') | ||
parser.add_argument( | ||
'-s', '--selfcontained', action='store_true', | ||
help='create self-contained files') | ||
parser.add_argument( | ||
'-u', '--uncommented', action='store_true', | ||
help='create uncommented files') | ||
group.add_argument('ldraw_file', nargs='?', metavar='FILENAME', | ||
help='source file to translate') | ||
parser.add_argument('output_file', nargs='?', metavar='OUTPUT_FILENAME', | ||
help='name of the translated file') | ||
parser.add_argument( | ||
'-l', '--lib', default=os.path.join('lib', 'ldraw'), metavar='LIB_DIR', | ||
help='location of the LDraw parts library') | ||
parser.add_argument( | ||
'-o', '--openscadlibs', default='.', metavar='OPENSCAD_LIB_DIR', | ||
help='location of the OpenSCAD libraries') | ||
parser.add_argument( | ||
'-n', '--libname', default='LDraw', metavar='LIB_NAME', | ||
help='name of the OpenSCAD library') | ||
parser.add_argument( | ||
'--line', default=0.2, type=float, metavar='LINE_WIDTH', | ||
help='width of lines, 0 for no lines') | ||
args = parser.parse_args() | ||
converter = LDrawConverter(libdir=args.lib) | ||
converter.set('scadlibs', args.openscadlibs) | ||
converter.set('scadlibname', args.libname) | ||
converter.set('line', args.line) | ||
converter.set('commented', not args.uncommented) | ||
if args.translib: | ||
print("Translating library...") | ||
converter.convert_lib(args.selfcontained) | ||
else: | ||
if os.path.isdir(args.ldraw_file): | ||
translate_dir( | ||
converter, args.ldraw_file, | ||
args.output_file if args.output_file else args.ldraw_file, | ||
args.selfcontained) | ||
else: | ||
scadfile = args.output_file if args.output_file else \ | ||
os.path.splitext(args.ldraw_file)[0] + '.scad' | ||
print(f"Translating {args.ldraw_file} to {scadfile}...") | ||
converter.convert_file(args.ldraw_file, scadfile, | ||
args.selfcontained) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains 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,8 @@ | ||
[build-system] | ||
requires = ["setuptools>=42"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.pytest.ini_options] | ||
testpaths = [ | ||
"tests", | ||
] |
This file contains 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 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,31 @@ | ||
[metadata] | ||
name = ldraw-to-scad | ||
version = 0.0.0 | ||
author = Danny Staple | ||
author_email = danny@orionrobots.co.uk | ||
maintainer = Robert Schiele | ||
maintainer_email = rschiele@gmail.com | ||
description = The LDraw to OpenSCAD converter library | ||
long_description = file: README.md | ||
long_description_content_type = text/markdown | ||
url = https://github.com/orionrobots/ldraw-to-scad | ||
project_urls = | ||
Bug Tracker = https://github.com/orionrobots/ldraw-to-scad/issues | ||
classifiers = | ||
Programming Language :: Python :: 3 | ||
License :: OSI Approved :: Apache Software License | ||
Operating System :: OS Independent | ||
|
||
[options] | ||
package_dir = | ||
= src | ||
packages = find: | ||
python_requires = >=3.6 | ||
scripts = ldraw2scad | ||
include_package_data = True | ||
|
||
[options.packages.find] | ||
where = src | ||
|
||
[options.package_data] | ||
ldraw_to_scad = lib.scad |
This file contains 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,3 @@ | ||
""" the LDraw to OpenSCAD converter library """ | ||
|
||
from .ldrawconverter import * |
This file contains 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
File renamed without changes.
This file contains 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 |
---|---|---|
|
@@ -2,3 +2,4 @@ pytest | |
mock | ||
pylint | ||
pycodestyle | ||
build |
Empty file.
File renamed without changes.
File renamed without changes.
This file contains 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