Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"cadquery@git+https://github.com/CadQuery/cadquery.git",
"cadquery==2.4.0",
"cadquery_freecad_import_plugin"
]

Expand Down
38 changes: 38 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from setuptools import setup, find_packages

setup(
name="cq_cli",
version="2.3.0",
license="LICENSE",
author="Jeremy Wright",
description="Command Line Interface for executing CadQuery scripts and converting their output to another format.",
long_description=open("README.md", encoding="utf-8").read(),
long_description_content_type="text/markdown",
python_requires=">=3.9",
classifiers=[
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
],
packages=find_packages(where="src"),
package_dir={"": "src"},
install_requires=[
"cadquery==2.4.0",
"cadquery_freecad_import_plugin",
],
extras_require={
"dev": [
"pytest",
"black==19.10b0",
"click==8.0.4",
],
},
entry_points={
"console_scripts": [
"cq-cli=cq_cli.main:main",
],
},
url="https://github.com/CadQuery/cq-cli",
project_urls={
"Bug Tracker": "https://github.com/CadQuery/cq-cli/issues",
},
)
35 changes: 34 additions & 1 deletion src/cq_cli/cqcodecs/codec_helpers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
from contextlib import contextmanager, redirect_stderr, redirect_stdout
from os import devnull

import tempfile
import shutil
import logging

@contextmanager
def suppress_stdout_stderr():
"""A context manager that redirects stdout and stderr to devnull"""
logging.info("STDOUT and STDERR are send to devnull.")
with open(devnull, "w") as fnull:
with redirect_stderr(fnull) as err, redirect_stdout(fnull) as out:
yield (err, out)


class temp_dir():
def __init__(self):
"""
A function to create temp codec files inside temporary directories, and
enable multiple codec processing, preventing file writing racing conditions.
Returns
-------
str, Temporary directory path.
"""
self.path = tempfile.mkdtemp()
logging.debug(f"temp_dir: {self.path}")

def dlt(self):
"""
Safe temp_dir deletion and path invalidation.
Returns
-------
None.

"""
if self.path:
shutil.rmtree(self.path)
self.path = None
logging.debug("temp_dir.path: deleted")
return True
else:
logging.error("temp_dir.path: does not exist.")
return False
6 changes: 3 additions & 3 deletions src/cq_cli/cqcodecs/cq_codec_dxf.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os, tempfile
import os
from cadquery import exporters
import cq_cli.cqcodecs.codec_helpers as helpers


def convert(build_result, output_file=None, error_file=None, output_opts=None):
# Create a temporary file to put the STL output into
temp_dir = tempfile.gettempdir()
temp_file = os.path.join(temp_dir, "temp_dxf.dxf")
temp_dir = helpers.temp_dir()
temp_file = os.path.join(temp_dir.path, "temp_dxf.dxf")

# The exporters will add extra output that we do not want, so suppress it
with helpers.suppress_stdout_stderr():
Expand Down
6 changes: 3 additions & 3 deletions src/cq_cli/cqcodecs/cq_codec_glb.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os, tempfile
import os
import cq_cli.cqcodecs.codec_helpers as helpers


def convert(build_result, output_file=None, error_file=None, output_opts=None):
# Create a temporary file to put the STL output into
temp_dir = tempfile.gettempdir()
temp_file = os.path.join(temp_dir, "temp_glb.glb")
temp_dir = helpers.temp_dir()
temp_file = os.path.join(temp_dir.path, "temp_glb.glb")

# The exporters will add extra output that we do not want, so suppress it
with helpers.suppress_stdout_stderr():
Expand Down
6 changes: 3 additions & 3 deletions src/cq_cli/cqcodecs/cq_codec_gltf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os, tempfile
import os
import cq_cli.cqcodecs.codec_helpers as helpers


def convert(build_result, output_file=None, error_file=None, output_opts=None):
# Create a temporary file to put the STL output into
temp_dir = tempfile.gettempdir()
temp_file = os.path.join(temp_dir, "temp_gltf.gltf")
temp_dir = helpers.temp_dir()
temp_file = os.path.join(temp_dir.path, "temp_gltf.gltf")

# The exporters will add extra output that we do not want, so suppress it
with helpers.suppress_stdout_stderr():
Expand Down
7 changes: 3 additions & 4 deletions src/cq_cli/cqcodecs/cq_codec_step.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import os, tempfile
import os
from cadquery import exporters
import cadquery as cq
import cq_cli.cqcodecs.codec_helpers as helpers


def convert(build_result, output_file=None, error_file=None, output_opts=None):
# Create a temporary file to put the STL output into
temp_dir = tempfile.gettempdir()
temp_file = os.path.join(temp_dir, "temp_step.step")
temp_dir = helpers.temp_dir()
temp_file = os.path.join(temp_dir.path, "temp_step.step")

# The exporters will add extra output that we do not want, so suppress it
with helpers.suppress_stdout_stderr():
Expand Down
8 changes: 3 additions & 5 deletions src/cq_cli/cqcodecs/cq_codec_stl.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import os, tempfile
from cadquery import exporters
import cadquery as cq
import os
import cq_cli.cqcodecs.codec_helpers as helpers


def convert(build_result, output_file=None, error_file=None, output_opts=None):
# Create a temporary file to put the STL output into
temp_dir = tempfile.gettempdir()
temp_file = os.path.join(temp_dir, "temp_stl.stl")
temp_dir = helpers.temp_dir()
temp_file = os.path.join(temp_dir.path, "temp_stl.stl")

linearDeflection = 0.1
angularDeflection = 0.1
Expand Down
6 changes: 3 additions & 3 deletions src/cq_cli/cqcodecs/cq_codec_svg.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os, tempfile
import os
from cadquery import exporters
import cq_cli.cqcodecs.codec_helpers as helpers


def convert(build_result, output_file=None, error_file=None, output_opts=None):
# Create a temporary file to put the STL output into
temp_dir = tempfile.gettempdir()
temp_file = os.path.join(temp_dir, "temp_svg.svg")
temp_dir = helpers.temp_dir()
temp_file = os.path.join(temp_dir.path, "temp_svg.svg")

# The exporters will add extra output that we do not want, so suppress it
with helpers.suppress_stdout_stderr():
Expand Down
7 changes: 3 additions & 4 deletions src/cq_cli/cqcodecs/cq_codec_threejs.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import os, tempfile
import os
from cadquery import exporters
import cadquery as cq
import cq_cli.cqcodecs.codec_helpers as helpers


def convert(build_result, output_file=None, error_file=None, output_opts=None):
# Create a temporary file to put the STL output into
temp_dir = tempfile.gettempdir()
temp_file = os.path.join(temp_dir, "temp_threejs.json")
temp_dir = helpers.temp_dir()
temp_file = os.path.join(temp_dir.path, "temp_threejs.json")

# The exporters will add extra output that we do not want, so suppress it
with helpers.suppress_stdout_stderr():
Expand Down