From 7e887aa00d4dd221eb6c97c6b248e156f9b952af Mon Sep 17 00:00:00 2001 From: Roman Kuzmenko Date: Wed, 10 Jan 2024 21:41:05 -0800 Subject: [PATCH] Split the repo in two to reduce runtime dependencies --- .flake8 | 5 ++ .github/FUNDING.yml | 3 - .github/workflows/version-bump.yml | 6 +- .gitignore | 9 ++- .vscode/settings.json | 5 +- README.md | 5 +- examples/consume_standalone/example.py | 12 ++++ .../consume_standalone/partcad.yaml | 0 partcad-cli/pyproject.toml | 31 ++++++++++ partcad-cli/requirements.txt | 7 +++ partcad-cli/src/partcad_cli/__init__.py | 7 +++ .../src/partcad_cli}/cli.py | 0 .../src/partcad_cli}/cli_add.py | 0 .../src/partcad_cli}/cli_init.py | 0 .../src/partcad_cli}/cli_install.py | 0 .../src/partcad_cli}/cli_list.py | 0 .../src/partcad_cli}/cli_render.py | 0 .../src/partcad_cli}/cli_show.py | 6 +- .../partcad_cli}/template/init-private.yaml | 0 .../src/partcad_cli/template/init-public.yaml | 19 +++++++ partcad/pyproject.toml | 47 ++++++++++++++++ partcad/requirements.txt | 10 ++++ {src => partcad/src}/partcad/__init__.py | 1 - {src => partcad/src}/partcad/assembly.py | 0 .../src}/partcad/assembly_factory.py | 0 .../src}/partcad/assembly_factory_assy.py | 0 {src => partcad/src}/partcad/consts.py | 0 {src => partcad/src}/partcad/context.py | 18 ++++-- {src => partcad/src}/partcad/part.py | 0 {src => partcad/src}/partcad/part_factory.py | 0 .../src}/partcad/part_factory_3mf.py | 0 .../src}/partcad/part_factory_build123d.py | 0 .../src}/partcad/part_factory_cadquery.py | 0 .../src}/partcad/part_factory_python.py | 0 .../src}/partcad/part_factory_scad.py | 0 .../src}/partcad/part_factory_step.py | 0 .../src}/partcad/part_factory_stl.py | 0 {src => partcad/src}/partcad/project.py | 6 ++ .../src}/partcad/project_config.py | 0 .../src}/partcad/project_factory.py | 0 .../src}/partcad/project_factory_git.py | 0 .../src}/partcad/project_factory_local.py | 0 .../src}/partcad/project_factory_tar.py | 0 {src => partcad/src}/partcad/render.py | 0 {src => partcad/src}/partcad/runtime.py | 0 .../src}/partcad/runtime_python.py | 0 .../src}/partcad/runtime_python_all.py | 0 .../src}/partcad/runtime_python_conda.py | 0 .../src}/partcad/runtime_python_none.py | 0 .../src}/partcad/runtime_python_pypy.py | 0 {src => partcad/src}/partcad/scene.py | 0 {src => partcad/src}/partcad/shape.py | 43 +++++++++----- {src => partcad/src}/partcad/user_config.py | 0 {src => partcad/src}/partcad/wrapper.py | 0 .../src}/partcad/wrappers/cq_serialize.py | 0 .../partcad/wrappers/wrapper_build123d.py | 0 .../src}/partcad/wrappers/wrapper_cadquery.py | 0 .../src}/partcad/wrappers/wrapper_common.py | 0 {tests => partcad/tests}/__init__.py | 0 .../tests}/partcad-examples.yaml | 10 ++-- {tests => partcad/tests}/partcad.yaml | 0 .../unit/data/project_config_invalid_1.yaml | 0 .../unit/data/project_config_template.yaml | 4 ++ .../unit/data/project_config_valid_1.yaml | 0 .../tests}/unit/test_assembly.py | 8 +-- {tests => partcad/tests}/unit/test_context.py | 2 +- {tests => partcad/tests}/unit/test_part.py | 6 +- {tests => partcad/tests}/unit/test_project.py | 4 +- .../tests}/unit/test_project_config.py | 6 +- {tests => partcad/tests}/unit/test_render.py | 6 +- .../tests}/unit/test_runtime_python.py | 6 +- tox.ini => partcad/tox.ini | 0 pyproject.toml | 56 +++++++------------ requirements.txt | 23 ++------ tests/unit/data/project_config_template.yaml | 4 -- 75 files changed, 254 insertions(+), 121 deletions(-) create mode 100644 .flake8 delete mode 100644 .github/FUNDING.yml create mode 100644 examples/consume_standalone/example.py rename src/partcad/template/init-public.yaml => examples/consume_standalone/partcad.yaml (100%) create mode 100644 partcad-cli/pyproject.toml create mode 100644 partcad-cli/requirements.txt create mode 100644 partcad-cli/src/partcad_cli/__init__.py rename {src/partcad => partcad-cli/src/partcad_cli}/cli.py (100%) rename {src/partcad => partcad-cli/src/partcad_cli}/cli_add.py (100%) rename {src/partcad => partcad-cli/src/partcad_cli}/cli_init.py (100%) rename {src/partcad => partcad-cli/src/partcad_cli}/cli_install.py (100%) rename {src/partcad => partcad-cli/src/partcad_cli}/cli_list.py (100%) rename {src/partcad => partcad-cli/src/partcad_cli}/cli_render.py (100%) rename {src/partcad => partcad-cli/src/partcad_cli}/cli_show.py (94%) rename {src/partcad => partcad-cli/src/partcad_cli}/template/init-private.yaml (100%) create mode 100644 partcad-cli/src/partcad_cli/template/init-public.yaml create mode 100644 partcad/pyproject.toml create mode 100644 partcad/requirements.txt rename {src => partcad/src}/partcad/__init__.py (96%) rename {src => partcad/src}/partcad/assembly.py (100%) rename {src => partcad/src}/partcad/assembly_factory.py (100%) rename {src => partcad/src}/partcad/assembly_factory_assy.py (100%) rename {src => partcad/src}/partcad/consts.py (100%) rename {src => partcad/src}/partcad/context.py (94%) rename {src => partcad/src}/partcad/part.py (100%) rename {src => partcad/src}/partcad/part_factory.py (100%) rename {src => partcad/src}/partcad/part_factory_3mf.py (100%) rename {src => partcad/src}/partcad/part_factory_build123d.py (100%) rename {src => partcad/src}/partcad/part_factory_cadquery.py (100%) rename {src => partcad/src}/partcad/part_factory_python.py (100%) rename {src => partcad/src}/partcad/part_factory_scad.py (100%) rename {src => partcad/src}/partcad/part_factory_step.py (100%) rename {src => partcad/src}/partcad/part_factory_stl.py (100%) rename {src => partcad/src}/partcad/project.py (98%) rename {src => partcad/src}/partcad/project_config.py (100%) rename {src => partcad/src}/partcad/project_factory.py (100%) rename {src => partcad/src}/partcad/project_factory_git.py (100%) rename {src => partcad/src}/partcad/project_factory_local.py (100%) rename {src => partcad/src}/partcad/project_factory_tar.py (100%) rename {src => partcad/src}/partcad/render.py (100%) rename {src => partcad/src}/partcad/runtime.py (100%) rename {src => partcad/src}/partcad/runtime_python.py (100%) rename {src => partcad/src}/partcad/runtime_python_all.py (100%) rename {src => partcad/src}/partcad/runtime_python_conda.py (100%) rename {src => partcad/src}/partcad/runtime_python_none.py (100%) rename {src => partcad/src}/partcad/runtime_python_pypy.py (100%) rename {src => partcad/src}/partcad/scene.py (100%) rename {src => partcad/src}/partcad/shape.py (88%) rename {src => partcad/src}/partcad/user_config.py (100%) rename {src => partcad/src}/partcad/wrapper.py (100%) rename {src => partcad/src}/partcad/wrappers/cq_serialize.py (100%) rename {src => partcad/src}/partcad/wrappers/wrapper_build123d.py (100%) rename {src => partcad/src}/partcad/wrappers/wrapper_cadquery.py (100%) rename {src => partcad/src}/partcad/wrappers/wrapper_common.py (100%) rename {tests => partcad/tests}/__init__.py (100%) rename {tests => partcad/tests}/partcad-examples.yaml (65%) rename {tests => partcad/tests}/partcad.yaml (100%) rename {tests => partcad/tests}/unit/data/project_config_invalid_1.yaml (100%) create mode 100644 partcad/tests/unit/data/project_config_template.yaml rename {tests => partcad/tests}/unit/data/project_config_valid_1.yaml (100%) rename {tests => partcad/tests}/unit/test_assembly.py (86%) rename {tests => partcad/tests}/unit/test_context.py (84%) rename {tests => partcad/tests}/unit/test_part.py (96%) rename {tests => partcad/tests}/unit/test_project.py (94%) rename {tests => partcad/tests}/unit/test_project_config.py (83%) rename {tests => partcad/tests}/unit/test_render.py (86%) rename {tests => partcad/tests}/unit/test_runtime_python.py (87%) rename tox.ini => partcad/tox.ini (100%) delete mode 100644 tests/unit/data/project_config_template.yaml diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..cec1e2f0 --- /dev/null +++ b/.flake8 @@ -0,0 +1,5 @@ +[flake8] +max-line-length = 80 +# required for compatibility with Black: +extend-ignore = E203 +exclude = .venv \ No newline at end of file diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 785f1962..00000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,3 +0,0 @@ -# These are supported funding model platforms - -patreon: openvmp diff --git a/.github/workflows/version-bump.yml b/.github/workflows/version-bump.yml index a79943cc..767054e0 100644 --- a/.github/workflows/version-bump.yml +++ b/.github/workflows/version-bump.yml @@ -37,7 +37,7 @@ jobs: env: COMMIT_MSG: ${{ github.event.head_commit.message }} run: | - bump-my-version bump major + (cd partcad && bump-my-version bump major) echo "SKIPBUMP=TRUE" >> $GITHUB_ENV if: startsWith(github.event.head_commit.message, '[MAJOR]') @@ -45,7 +45,7 @@ jobs: env: COMMIT_MSG: ${{ github.event.head_commit.message }} run: | - bump-my-version bump minor + (cd partcad && bump-my-version bump minor) echo "SKIPBUMP=TRUE" >> $GITHUB_ENV if: startsWith(github.event.head_commit.message, '[FEATURE]') @@ -54,7 +54,7 @@ jobs: env: COMMIT_MSG: ${{ github.event.head_commit.message }} run: | - bump-my-version bump patch + (cd partcad && bump-my-version bump patch) if: env.SKIPBUMP == 'FALSE' - name: Commit version change to master diff --git a/.gitignore b/.gitignore index c3766e2d..da5441a2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,10 +4,9 @@ __pycache__ .pytest_cache *.pyc .tox -generated_files/*.stl -generated_files/*.obj -generated_files/*.svg .partcad -/build -/dist +/partcad/build +/partcad-cli/build +/partcad/dist +/partcad-cli/dist .ocp_vscode diff --git a/.vscode/settings.json b/.vscode/settings.json index 52a37208..5ec03906 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -22,8 +22,8 @@ ".conda": true, ".tox": true, "**/.partcad": true, - "build": true, - "dist": true + "partcad*/build": true, + "partcad*/dist": true }, "markdown.extension.toc.omittedFromToc": { "README.md": [ @@ -34,7 +34,6 @@ "editor.defaultFormatter": "ms-python.black-formatter" }, "python.testing.pytestArgs": [ - "tests" ], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, diff --git a/README.md b/README.md index 5fa24377..d3ffa691 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ all of the consumers. The recommended method to install PartCAD for most users is: ```shell -pip install partcad +pip install partcad-cli ``` For contributors: @@ -50,7 +50,8 @@ For contributors: ```shell git clone https://github.com/openvmp/partcad.git cd partcad -python3 -m pip install -e . +python3 -m pip install -e ./partcad +python3 -m pip install -e ./partcad-cli ``` PartCAD works best when [conda](https://docs.conda.io/) is installed. diff --git a/examples/consume_standalone/example.py b/examples/consume_standalone/example.py new file mode 100644 index 00000000..d2cc2eeb --- /dev/null +++ b/examples/consume_standalone/example.py @@ -0,0 +1,12 @@ +import partcad as pc + +if __name__ != "__cqgi__": + from cq_server.ui import ui, show_object + +part = pc.get_part( + # Part name + "fastener/screw-buttonhead", + # Package name + "standard-metric-cqwarehouse", +) +pc.finalize(part, show_object) diff --git a/src/partcad/template/init-public.yaml b/examples/consume_standalone/partcad.yaml similarity index 100% rename from src/partcad/template/init-public.yaml rename to examples/consume_standalone/partcad.yaml diff --git a/partcad-cli/pyproject.toml b/partcad-cli/pyproject.toml new file mode 100644 index 00000000..4a47b60f --- /dev/null +++ b/partcad-cli/pyproject.toml @@ -0,0 +1,31 @@ +[project] +name = "partcad_cli" +version = "0.2.20" +description = "Command-line interface to PartCAD" +readme = "README.md" +keywords = ["cadquery", "build123d", "cad", "design", "openscad", "step", "stl"] +requires-python = ">=3.7" +license = {file = "LICENSE.txt"} +authors = [ + {name = "Roman Kuzmenko", email = "openvmp@proton.me" } +] +maintainers = [ + {name = "Roman Kuzmenko", email = "openvmp@proton.me" } +] +dynamic = ["dependencies"] + +[tool.setuptools.package-data] +"partcad_cli.template" = ["*.yaml"] + +[project.scripts] +pc = "partcad_cli:main_cli" + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} + +[tool.pytest.ini_options] +pythonpath = "src" + +[project.urls] +Homepage = "https://github.com/openvmp/partcad" +Issues = "https://github.com/openvmp/partcad/issues" diff --git a/partcad-cli/requirements.txt b/partcad-cli/requirements.txt new file mode 100644 index 00000000..2b33a832 --- /dev/null +++ b/partcad-cli/requirements.txt @@ -0,0 +1,7 @@ +partcad==0.2.20 +pycairo +renderlab +rlPyCairo +svglib +ocp_vscode +progress diff --git a/partcad-cli/src/partcad_cli/__init__.py b/partcad-cli/src/partcad_cli/__init__.py new file mode 100644 index 00000000..60667028 --- /dev/null +++ b/partcad-cli/src/partcad_cli/__init__.py @@ -0,0 +1,7 @@ +from .cli import main as main_cli + +__all__ = [ + "main_cli", +] + +__version__: str = "0.2.20" diff --git a/src/partcad/cli.py b/partcad-cli/src/partcad_cli/cli.py similarity index 100% rename from src/partcad/cli.py rename to partcad-cli/src/partcad_cli/cli.py diff --git a/src/partcad/cli_add.py b/partcad-cli/src/partcad_cli/cli_add.py similarity index 100% rename from src/partcad/cli_add.py rename to partcad-cli/src/partcad_cli/cli_add.py diff --git a/src/partcad/cli_init.py b/partcad-cli/src/partcad_cli/cli_init.py similarity index 100% rename from src/partcad/cli_init.py rename to partcad-cli/src/partcad_cli/cli_init.py diff --git a/src/partcad/cli_install.py b/partcad-cli/src/partcad_cli/cli_install.py similarity index 100% rename from src/partcad/cli_install.py rename to partcad-cli/src/partcad_cli/cli_install.py diff --git a/src/partcad/cli_list.py b/partcad-cli/src/partcad_cli/cli_list.py similarity index 100% rename from src/partcad/cli_list.py rename to partcad-cli/src/partcad_cli/cli_list.py diff --git a/src/partcad/cli_render.py b/partcad-cli/src/partcad_cli/cli_render.py similarity index 100% rename from src/partcad/cli_render.py rename to partcad-cli/src/partcad_cli/cli_render.py diff --git a/src/partcad/cli_show.py b/partcad-cli/src/partcad_cli/cli_show.py similarity index 94% rename from src/partcad/cli_show.py rename to partcad-cli/src/partcad_cli/cli_show.py index f4ebb08e..69847b68 100644 --- a/src/partcad/cli_show.py +++ b/partcad-cli/src/partcad_cli/cli_show.py @@ -9,7 +9,7 @@ import logging -from . import init +import partcad as pc def cli_help_show(subparsers): @@ -46,9 +46,9 @@ def cli_help_show(subparsers): def cli_show(args): if not args.config_path is None: - ctx = init(args.config_path) + ctx = pc.init(args.config_path) else: - ctx = init() + ctx = pc.init() if args.package is None: package = "this" diff --git a/src/partcad/template/init-private.yaml b/partcad-cli/src/partcad_cli/template/init-private.yaml similarity index 100% rename from src/partcad/template/init-private.yaml rename to partcad-cli/src/partcad_cli/template/init-private.yaml diff --git a/partcad-cli/src/partcad_cli/template/init-public.yaml b/partcad-cli/src/partcad_cli/template/init-public.yaml new file mode 100644 index 00000000..384d7b1c --- /dev/null +++ b/partcad-cli/src/partcad_cli/template/init-public.yaml @@ -0,0 +1,19 @@ +import: + # Add dependencies here + # : + # desc: # optional + # type: + # path: # type:local only + # url: # type:git|tar only + # relPath: # type:git|tar only + # web: # optional + # poc: # optional + partcad-index: + type: git + url: https://github.com/openvmp/partcad-index.git + +parts: + # Add parts here + +assemblies: + # Add assemblies here diff --git a/partcad/pyproject.toml b/partcad/pyproject.toml new file mode 100644 index 00000000..930b7822 --- /dev/null +++ b/partcad/pyproject.toml @@ -0,0 +1,47 @@ +[project] +name = "partcad" +description = "Package manager for CAD models and a modelling framework" +readme = "README.md" +keywords = ["cadquery", "build123d", "cad", "design", "openscad", "step", "stl"] +requires-python = ">=3.7" +license = {file = "LICENSE.txt"} +authors = [ + {name = "Roman Kuzmenko", email = "openvmp@proton.me" } +] +maintainers = [ + {name = "Roman Kuzmenko", email = "openvmp@proton.me" } +] +dynamic = ["version", "dependencies"] + +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", +] + +[tool.setuptools.package-data] +"partcad.wrappers" = ["*.py"] + +[tool.setuptools.dynamic] +version = {attr = "partcad.__version__"} +dependencies = {file = ["requirements.txt"]} + +[tool.bumpversion] +current_version = "0.2.20" +commit = "true" +commit_args = "--no-verify" +tag = "true" +tag_name = "{new_version}" +message = "Version updated from {current_version} to {new_version}" + +[[tool.bumpversion.files]] +filename = [ + "src/partcad/__init__.py", + "../partcad-cli/src/partcad_cli/__init__.py", + "../partcad-cli/pyproject.toml", + "../partcad-cli/requirements.txt" +] + +[project.urls] +Homepage = "https://github.com/openvmp/partcad" +Issues = "https://github.com/openvmp/partcad/issues" diff --git a/partcad/requirements.txt b/partcad/requirements.txt new file mode 100644 index 00000000..e9eb0acc --- /dev/null +++ b/partcad/requirements.txt @@ -0,0 +1,10 @@ +build123d>=0.2.0 +cadquery>=2.3.1 +numpy>=1.25.2 +scipy>=1.11.1 +pyyaml>=6.0.1 +GitPython>=3.1.40 +ruamel.yaml>=0.18.5 +packaging>=23.1 +setuptools +jinja2 diff --git a/src/partcad/__init__.py b/partcad/src/partcad/__init__.py similarity index 96% rename from src/partcad/__init__.py rename to partcad/src/partcad/__init__.py index de7d0e5a..8d498716 100644 --- a/src/partcad/__init__.py +++ b/partcad/src/partcad/__init__.py @@ -16,7 +16,6 @@ from .project_factory_local import ProjectFactoryLocal from .project_factory_git import ProjectFactoryGit from .project_factory_tar import ProjectFactoryTar -from .cli import main as main_cli from .user_config import user_config diff --git a/src/partcad/assembly.py b/partcad/src/partcad/assembly.py similarity index 100% rename from src/partcad/assembly.py rename to partcad/src/partcad/assembly.py diff --git a/src/partcad/assembly_factory.py b/partcad/src/partcad/assembly_factory.py similarity index 100% rename from src/partcad/assembly_factory.py rename to partcad/src/partcad/assembly_factory.py diff --git a/src/partcad/assembly_factory_assy.py b/partcad/src/partcad/assembly_factory_assy.py similarity index 100% rename from src/partcad/assembly_factory_assy.py rename to partcad/src/partcad/assembly_factory_assy.py diff --git a/src/partcad/consts.py b/partcad/src/partcad/consts.py similarity index 100% rename from src/partcad/consts.py rename to partcad/src/partcad/consts.py diff --git a/src/partcad/context.py b/partcad/src/partcad/context.py similarity index 94% rename from src/partcad/context.py rename to partcad/src/partcad/context.py index aee8051a..e95bccce 100644 --- a/src/partcad/context.py +++ b/partcad/src/partcad/context.py @@ -9,7 +9,8 @@ import atexit import logging import os -from progress.spinner import Spinner + +import importlib from . import consts from . import project_config @@ -87,12 +88,17 @@ def __init__(self, config_path="."): self._projects_being_loaded = {} self._last_to_finalize = None + spinner = None if logging.root.level < 60: - spinner = Spinner("PartCAD: Loading dependencies...") - spinner.start() - spinner.next() - else: - spinner = None + try: + progress = importlib.import_module("progress.spinner") + if not progress is None: + spinner = progress.Spinner("PartCAD: Loading dependencies...") + spinner.start() + spinner.next() + except Exception as e: + print(e) + _ignore = True self.import_project( None, # parent diff --git a/src/partcad/part.py b/partcad/src/partcad/part.py similarity index 100% rename from src/partcad/part.py rename to partcad/src/partcad/part.py diff --git a/src/partcad/part_factory.py b/partcad/src/partcad/part_factory.py similarity index 100% rename from src/partcad/part_factory.py rename to partcad/src/partcad/part_factory.py diff --git a/src/partcad/part_factory_3mf.py b/partcad/src/partcad/part_factory_3mf.py similarity index 100% rename from src/partcad/part_factory_3mf.py rename to partcad/src/partcad/part_factory_3mf.py diff --git a/src/partcad/part_factory_build123d.py b/partcad/src/partcad/part_factory_build123d.py similarity index 100% rename from src/partcad/part_factory_build123d.py rename to partcad/src/partcad/part_factory_build123d.py diff --git a/src/partcad/part_factory_cadquery.py b/partcad/src/partcad/part_factory_cadquery.py similarity index 100% rename from src/partcad/part_factory_cadquery.py rename to partcad/src/partcad/part_factory_cadquery.py diff --git a/src/partcad/part_factory_python.py b/partcad/src/partcad/part_factory_python.py similarity index 100% rename from src/partcad/part_factory_python.py rename to partcad/src/partcad/part_factory_python.py diff --git a/src/partcad/part_factory_scad.py b/partcad/src/partcad/part_factory_scad.py similarity index 100% rename from src/partcad/part_factory_scad.py rename to partcad/src/partcad/part_factory_scad.py diff --git a/src/partcad/part_factory_step.py b/partcad/src/partcad/part_factory_step.py similarity index 100% rename from src/partcad/part_factory_step.py rename to partcad/src/partcad/part_factory_step.py diff --git a/src/partcad/part_factory_stl.py b/partcad/src/partcad/part_factory_stl.py similarity index 100% rename from src/partcad/part_factory_stl.py rename to partcad/src/partcad/part_factory_stl.py diff --git a/src/partcad/project.py b/partcad/src/partcad/project.py similarity index 98% rename from src/partcad/project.py rename to partcad/src/partcad/project.py index 5b8d3f11..5b4b6f37 100644 --- a/src/partcad/project.py +++ b/partcad/src/partcad/project.py @@ -62,6 +62,9 @@ def get_part_config(self, part_name): return self.part_configs[part_name] def init_parts(self): + if self.part_configs is None: + return + for part_name in self.part_configs: part_config = self.get_part_config(part_name) @@ -118,6 +121,9 @@ def get_assembly_config(self, assembly_name): return self.assembly_configs[assembly_name] def init_assemblies(self): + if self.assembly_configs is None: + return + for assembly_name in self.assembly_configs: assembly_config = self.get_assembly_config(assembly_name) diff --git a/src/partcad/project_config.py b/partcad/src/partcad/project_config.py similarity index 100% rename from src/partcad/project_config.py rename to partcad/src/partcad/project_config.py diff --git a/src/partcad/project_factory.py b/partcad/src/partcad/project_factory.py similarity index 100% rename from src/partcad/project_factory.py rename to partcad/src/partcad/project_factory.py diff --git a/src/partcad/project_factory_git.py b/partcad/src/partcad/project_factory_git.py similarity index 100% rename from src/partcad/project_factory_git.py rename to partcad/src/partcad/project_factory_git.py diff --git a/src/partcad/project_factory_local.py b/partcad/src/partcad/project_factory_local.py similarity index 100% rename from src/partcad/project_factory_local.py rename to partcad/src/partcad/project_factory_local.py diff --git a/src/partcad/project_factory_tar.py b/partcad/src/partcad/project_factory_tar.py similarity index 100% rename from src/partcad/project_factory_tar.py rename to partcad/src/partcad/project_factory_tar.py diff --git a/src/partcad/render.py b/partcad/src/partcad/render.py similarity index 100% rename from src/partcad/render.py rename to partcad/src/partcad/render.py diff --git a/src/partcad/runtime.py b/partcad/src/partcad/runtime.py similarity index 100% rename from src/partcad/runtime.py rename to partcad/src/partcad/runtime.py diff --git a/src/partcad/runtime_python.py b/partcad/src/partcad/runtime_python.py similarity index 100% rename from src/partcad/runtime_python.py rename to partcad/src/partcad/runtime_python.py diff --git a/src/partcad/runtime_python_all.py b/partcad/src/partcad/runtime_python_all.py similarity index 100% rename from src/partcad/runtime_python_all.py rename to partcad/src/partcad/runtime_python_all.py diff --git a/src/partcad/runtime_python_conda.py b/partcad/src/partcad/runtime_python_conda.py similarity index 100% rename from src/partcad/runtime_python_conda.py rename to partcad/src/partcad/runtime_python_conda.py diff --git a/src/partcad/runtime_python_none.py b/partcad/src/partcad/runtime_python_none.py similarity index 100% rename from src/partcad/runtime_python_none.py rename to partcad/src/partcad/runtime_python_none.py diff --git a/src/partcad/runtime_python_pypy.py b/partcad/src/partcad/runtime_python_pypy.py similarity index 100% rename from src/partcad/runtime_python_pypy.py rename to partcad/src/partcad/runtime_python_pypy.py diff --git a/src/partcad/scene.py b/partcad/src/partcad/scene.py similarity index 100% rename from src/partcad/scene.py rename to partcad/src/partcad/scene.py diff --git a/src/partcad/shape.py b/partcad/src/partcad/shape.py similarity index 88% rename from src/partcad/shape.py rename to partcad/src/partcad/shape.py index de38b98e..24f94d9d 100644 --- a/src/partcad/shape.py +++ b/partcad/src/partcad/shape.py @@ -9,8 +9,9 @@ import cadquery as cq import build123d as b3d -from svglib.svglib import svg2rlg -from reportlab.graphics import renderPM +# from svglib.svglib import svg2rlg +# from reportlab.graphics import renderPM +import importlib import logging import os import tempfile @@ -45,18 +46,22 @@ def show(self, show_object=None): shape = self.get_wrapped() if shape is not None: if show_object is None: - import ocp_vscode as ov - - try: - ov.config.status() - logging.info('Visualizing in "OCP CAD Viewer"...') - # logging.debug(self.shape) - ov.show(shape) - except Exception as e: - logging.warning(e) - logging.warning( - 'No VS Code or "OCP CAD Viewer" extension detected.' + ocp_vscode = importlib.import_module("ocp_vscode") + if ocp_vscode is None: + logging.warn( + 'Failed to load "ocp_vscode". Giving up on connection to VS Code.' ) + else: + try: + ocp_vscode.config.status() + logging.info('Visualizing in "OCP CAD Viewer"...') + # logging.debug(self.shape) + ocp_vscode.show(shape) + except Exception as e: + logging.warning(e) + logging.warning( + 'No VS Code or "OCP CAD Viewer" extension detected.' + ) if show_object is not None: show_object( @@ -188,6 +193,16 @@ def render_png( width=None, height=None, ): + svglib = importlib.import_module("svglib.svglib") + if svglib is None: + logging.error('Failed to load "svglib". Aborting.') + return + + renderPM = importlib.import_module("reportlab.graphics.renderPM") + if renderPM is None: + logging.error('Failed to load "renderPM". Aborting.') + return + png_opts, filepath = self.render_getopts("png", ".png", project, filepath) if width is None: @@ -205,7 +220,7 @@ def render_png( svg_path = self._get_svg_path() # Render the raster image - drawing = svg2rlg(svg_path) + drawing = svglib.svg2rlg(svg_path) scale_width = float(width) / float(drawing.width) scale_height = float(height) / float(drawing.height) scale = min(scale_width, scale_height) diff --git a/src/partcad/user_config.py b/partcad/src/partcad/user_config.py similarity index 100% rename from src/partcad/user_config.py rename to partcad/src/partcad/user_config.py diff --git a/src/partcad/wrapper.py b/partcad/src/partcad/wrapper.py similarity index 100% rename from src/partcad/wrapper.py rename to partcad/src/partcad/wrapper.py diff --git a/src/partcad/wrappers/cq_serialize.py b/partcad/src/partcad/wrappers/cq_serialize.py similarity index 100% rename from src/partcad/wrappers/cq_serialize.py rename to partcad/src/partcad/wrappers/cq_serialize.py diff --git a/src/partcad/wrappers/wrapper_build123d.py b/partcad/src/partcad/wrappers/wrapper_build123d.py similarity index 100% rename from src/partcad/wrappers/wrapper_build123d.py rename to partcad/src/partcad/wrappers/wrapper_build123d.py diff --git a/src/partcad/wrappers/wrapper_cadquery.py b/partcad/src/partcad/wrappers/wrapper_cadquery.py similarity index 100% rename from src/partcad/wrappers/wrapper_cadquery.py rename to partcad/src/partcad/wrappers/wrapper_cadquery.py diff --git a/src/partcad/wrappers/wrapper_common.py b/partcad/src/partcad/wrappers/wrapper_common.py similarity index 100% rename from src/partcad/wrappers/wrapper_common.py rename to partcad/src/partcad/wrappers/wrapper_common.py diff --git a/tests/__init__.py b/partcad/tests/__init__.py similarity index 100% rename from tests/__init__.py rename to partcad/tests/__init__.py diff --git a/tests/partcad-examples.yaml b/partcad/tests/partcad-examples.yaml similarity index 65% rename from tests/partcad-examples.yaml rename to partcad/tests/partcad-examples.yaml index 1bdadaa6..e2ef0d27 100644 --- a/tests/partcad-examples.yaml +++ b/partcad/tests/partcad-examples.yaml @@ -12,16 +12,16 @@ import: example_part_step: type: local - path: ../examples/part_step + path: ../../examples/part_step example_part_cadquery_primitive: type: local - path: ../examples/part_cadquery_primitive + path: ../../examples/part_cadquery_primitive example_part_cadquery_logo: type: local - path: ../examples/part_cadquery_logo + path: ../../examples/part_cadquery_logo example_part_build123d_primitive: type: local - path: ../examples/part_build123d_primitive + path: ../../examples/part_build123d_primitive example_assembly_assy: type: local - path: ../examples/assembly_assy + path: ../../examples/assembly_assy diff --git a/tests/partcad.yaml b/partcad/tests/partcad.yaml similarity index 100% rename from tests/partcad.yaml rename to partcad/tests/partcad.yaml diff --git a/tests/unit/data/project_config_invalid_1.yaml b/partcad/tests/unit/data/project_config_invalid_1.yaml similarity index 100% rename from tests/unit/data/project_config_invalid_1.yaml rename to partcad/tests/unit/data/project_config_invalid_1.yaml diff --git a/partcad/tests/unit/data/project_config_template.yaml b/partcad/tests/unit/data/project_config_template.yaml new file mode 100644 index 00000000..2be55a7b --- /dev/null +++ b/partcad/tests/unit/data/project_config_template.yaml @@ -0,0 +1,4 @@ +parts: + {{package_name}}: + type: cadquery + path: ../../../../examples/part_cadquery_primitive/cube.py diff --git a/tests/unit/data/project_config_valid_1.yaml b/partcad/tests/unit/data/project_config_valid_1.yaml similarity index 100% rename from tests/unit/data/project_config_valid_1.yaml rename to partcad/tests/unit/data/project_config_valid_1.yaml diff --git a/tests/unit/test_assembly.py b/partcad/tests/unit/test_assembly.py similarity index 86% rename from tests/unit/test_assembly.py rename to partcad/tests/unit/test_assembly.py index f9cb782e..3ceec4de 100644 --- a/tests/unit/test_assembly.py +++ b/partcad/tests/unit/test_assembly.py @@ -12,7 +12,7 @@ def test_assembly_primitive(): - ctx = pc.init("tests/partcad-examples.yaml") + ctx = pc.init("partcad/tests/partcad-examples.yaml") part1 = ctx.get_part("cube", "example_part_cadquery_primitive") assert part1 is not None part2 = ctx.get_part("cylinder", "example_part_cadquery_primitive") @@ -25,7 +25,7 @@ def test_assembly_primitive(): def test_assembly_example_assy_primitive(): - ctx = pc.init("tests/partcad-examples.yaml") + ctx = pc.init("partcad/tests/partcad-examples.yaml") primitive = ctx.get_assembly("primitive", "example_assembly_assy") assert primitive is not None assert primitive.get_cadquery() is not None @@ -34,7 +34,7 @@ def test_assembly_example_assy_primitive(): def test_assembly_example_assy_logo(): - ctx = pc.init("tests/partcad-examples.yaml") + ctx = pc.init("partcad/tests/partcad-examples.yaml") logo = ctx.get_assembly("logo", "example_assembly_assy") assert logo is not None assert logo.get_cadquery() is not None @@ -43,7 +43,7 @@ def test_assembly_example_assy_logo(): def test_assembly_example_assy_logo_embedded(): - ctx = pc.init("tests/partcad-examples.yaml") + ctx = pc.init("partcad/tests/partcad-examples.yaml") logo = ctx.get_assembly("logo_embedded", "example_assembly_assy") assert logo is not None assert logo.get_cadquery() is not None diff --git a/tests/unit/test_context.py b/partcad/tests/unit/test_context.py similarity index 84% rename from tests/unit/test_context.py rename to partcad/tests/unit/test_context.py index 84ef578d..60abf9ba 100644 --- a/tests/unit/test_context.py +++ b/partcad/tests/unit/test_context.py @@ -12,5 +12,5 @@ def test_ctx1(): - ctx = pc.Context("tests") + ctx = pc.Context("partcad/tests") assert ctx is not None diff --git a/tests/unit/test_part.py b/partcad/tests/unit/test_part.py similarity index 96% rename from tests/unit/test_part.py rename to partcad/tests/unit/test_part.py index 8cc024c3..f5c3a676 100644 --- a/tests/unit/test_part.py +++ b/partcad/tests/unit/test_part.py @@ -114,7 +114,7 @@ def test_part_aliases(): def test_part_example_cadquery_primitive(): """Instantiate all parts from the example: part_cadquery_primitive""" - ctx = pc.init("tests/partcad-examples.yaml") + ctx = pc.init("partcad/tests/partcad-examples.yaml") cube = ctx.get_part("cube", "example_part_cadquery_primitive") assert cube is not None cylinder = ctx.get_part("cylinder", "example_part_cadquery_primitive") @@ -124,7 +124,7 @@ def test_part_example_cadquery_primitive(): def test_part_example_cadquery_logo(): """Instantiate all parts from the example: part_cadquery_logo""" - ctx = pc.init("tests/partcad-examples.yaml") + ctx = pc.init("partcad/tests/partcad-examples.yaml") bone = ctx.get_part("bone", "example_part_cadquery_logo") assert bone is not None head_half = ctx.get_part("head_half", "example_part_cadquery_logo") @@ -134,7 +134,7 @@ def test_part_example_cadquery_logo(): def test_part_example_build123d_primitive(): """Instantiate all parts from the example: part_build123d_primitive""" - ctx = pc.init("tests/partcad-examples.yaml") + ctx = pc.init("partcad/tests/partcad-examples.yaml") cube = ctx.get_part("cube", "example_part_build123d_primitive") assert cube is not None assert cube.get_wrapped() is not None diff --git a/tests/unit/test_project.py b/partcad/tests/unit/test_project.py similarity index 94% rename from tests/unit/test_project.py rename to partcad/tests/unit/test_project.py index d7ebe686..ea91b184 100644 --- a/tests/unit/test_project.py +++ b/partcad/tests/unit/test_project.py @@ -27,7 +27,7 @@ def test_project_this_1(): - ctx = pc.Context("tests") + ctx = pc.Context("partcad/tests") prj = ctx.get_project("this") assert prj is not None @@ -39,7 +39,7 @@ def test_project_this_2(): def test_project_this_3(): - ctx = pc.Context("tests/partcad-examples.yaml") + ctx = pc.Context("partcad/tests/partcad-examples.yaml") prj = ctx.get_project("this") assert prj is not None diff --git a/tests/unit/test_project_config.py b/partcad/tests/unit/test_project_config.py similarity index 83% rename from tests/unit/test_project_config.py rename to partcad/tests/unit/test_project_config.py index 6d20d56e..095c1124 100644 --- a/tests/unit/test_project_config.py +++ b/partcad/tests/unit/test_project_config.py @@ -14,7 +14,7 @@ def test_project_config_version_1(): """Positive test case for PartCAD version requirement in the package config file""" try: - ctx = pc.Context("tests/unit/data/project_config_valid_1.yaml") + ctx = pc.Context("partcad/tests/unit/data/project_config_valid_1.yaml") assert ctx.config_obj["partcad"] == ">=0.1.0" except Exception as e: assert False, "Valid configuration file caused an exception: %s" % e @@ -23,14 +23,14 @@ def test_project_config_version_1(): def test_project_config_version_2(): """Negative test case for PartCAD version requirement in the package config file""" try: - ctx = pc.Context("tests/unit/data/project_config_invalid_1.yaml") + ctx = pc.Context("partcad/tests/unit/data/project_config_invalid_1.yaml") assert False, "Invalid configuration file did not cause an exception" except: _ignore = True def test_project_config_template(): - ctx = pc.init("tests/partcad-examples.yaml") + ctx = pc.init("partcad/tests/partcad-examples.yaml") this = ctx.get_project(pc.THIS) ctx.import_project( this, diff --git a/tests/unit/test_render.py b/partcad/tests/unit/test_render.py similarity index 86% rename from tests/unit/test_render.py rename to partcad/tests/unit/test_render.py index cc93472c..16c78091 100644 --- a/tests/unit/test_render.py +++ b/partcad/tests/unit/test_render.py @@ -13,7 +13,7 @@ def test_render_svg_part_1(): """Render a primitive shape to SVG""" - ctx = pc.init("tests/partcad-examples.yaml") + ctx = pc.init("partcad/tests/partcad-examples.yaml") cube = ctx.get_part("cube", "example_part_cadquery_primitive") assert cube is not None try: @@ -24,7 +24,7 @@ def test_render_svg_part_1(): def test_render_svg_assy_1(): """Render a primitive shape to SVG""" - ctx = pc.init("tests/partcad-examples.yaml") + ctx = pc.init("partcad/tests/partcad-examples.yaml") assy = ctx.get_assembly("logo", "example_assembly_assy") assert assy is not None try: @@ -35,7 +35,7 @@ def test_render_svg_assy_1(): def test_render_svg_assy_2(): """Render a primitive shape to SVG""" - ctx = pc.init("tests/partcad-examples.yaml") + ctx = pc.init("partcad/tests/partcad-examples.yaml") assy = ctx.get_assembly("logo_embedded", "example_assembly_assy") assert assy is not None try: diff --git a/tests/unit/test_runtime_python.py b/partcad/tests/unit/test_runtime_python.py similarity index 87% rename from tests/unit/test_runtime_python.py rename to partcad/tests/unit/test_runtime_python.py index 9bbf5201..02f20e3e 100644 --- a/tests/unit/test_runtime_python.py +++ b/partcad/tests/unit/test_runtime_python.py @@ -12,7 +12,7 @@ def test_runtime_python_version_3_7(): - ctx = pc.Context("tests") + ctx = pc.Context("partcad/tests") runtime = ctx.get_python_runtime("3.7") version_string, errors = runtime.run(["--version"]) assert errors == "" @@ -20,7 +20,7 @@ def test_runtime_python_version_3_7(): def test_runtime_python_version_3_10(): - ctx = pc.Context("tests") + ctx = pc.Context("partcad/tests") runtime = ctx.get_python_runtime("3.10") version_string, errors = runtime.run(["--version"]) assert errors == "" @@ -28,7 +28,7 @@ def test_runtime_python_version_3_10(): def test_runtime_python_version_3_11(): - ctx = pc.Context("tests") + ctx = pc.Context("partcad/tests") runtime = ctx.get_python_runtime("3.11") version_string, errors = runtime.run(["--version"]) assert errors == "" diff --git a/tox.ini b/partcad/tox.ini similarity index 100% rename from tox.ini rename to partcad/tox.ini diff --git a/pyproject.toml b/pyproject.toml index 2a517eb3..53cec6a5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,40 +1,24 @@ -[project] -name = "partcad" -description = "Framework for packaging CAD models" -readme = "README.md" -keywords = ["cadquery", "build123d"] -requires-python = ">=3.10" -license = {file = "LICENSE.txt"} -authors = [ - {name = "Roman Kuzmenko", email = "openvmp@proton.me" } -] -maintainers = [ - {name = "Roman Kuzmenko", email = "openvmp@proton.me" } -] -dynamic = ["version", "dependencies"] - -[project.scripts] -pc = "partcad:main_cli" - -[tool.setuptools.package-data] -"partcad.template" = ["*.yaml"] -"partcad.wrappers" = ["*.py"] +[tool.pytest.ini_options] +pythonpath = "partcad/src" -[tool.setuptools.dynamic] -version = {attr = "partcad.__version__"} -dependencies = {file = ["requirements.txt"]} +[tool.black] +line-length = 80 +target-version = ['py37'] -[tool.pytest.ini_options] -# addopts = -ra -s -rx -pythonpath = "src" +[tool.pylint."messages control"] +ignore = ["setup.py", "__init__.py"] +disable = "all" +enable = [ + "empty-docstring", + "missing-class-docstring", + "missing-function-docstring", + "missing-module-docstring" +] -[tool.bumpversion] -current_version = "0.2.20" -commit = "true" -commit_args = "--no-verify" -tag = "true" -tag_name = "{new_version}" -message = "Version updated from {current_version} to {new_version}" +[tool.isort] +profile = "black" +known_first_party = ["partcad"] -[[tool.bumpversion.files]] -filename = "src/partcad/__init__.py" +[tools.pyright] +reportMissingTypeArgument = true # Report generic classes used without type arguments +strictListInference = true # Use union types when inferring types of lists elements, instead of Any diff --git a/requirements.txt b/requirements.txt index b35c9de9..2b091c94 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,17 +1,6 @@ -build123d>=0.2.0 -cadquery>=2.3.1 -numpy>=1.25.2 -scipy>=1.11.1 -#tox==4.9.0 -pyyaml>=6.0.1 -pycairo -renderlab -rlPyCairo -svglib -ocp_vscode>=2.0.13 -GitPython>=3.1.40 -progress>=1.6 -ruamel.yaml>=0.18.5 -packaging>=23.1 -setuptools -jinja2 +black +flake8 +isort +pytest +pytest-cov +#tox==4.9.0 \ No newline at end of file diff --git a/tests/unit/data/project_config_template.yaml b/tests/unit/data/project_config_template.yaml deleted file mode 100644 index de0c09ed..00000000 --- a/tests/unit/data/project_config_template.yaml +++ /dev/null @@ -1,4 +0,0 @@ -parts: - {{package_name}}: - type: cadquery - path: ../../../examples/part_cadquery_primitive/cube.py