Skip to content

Commit

Permalink
Split the repo in two to reduce runtime dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
openvmp committed Jan 11, 2024
1 parent 3074a29 commit 7e887aa
Show file tree
Hide file tree
Showing 75 changed files with 254 additions and 121 deletions.
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
max-line-length = 80
# required for compatibility with Black:
extend-ignore = E203
exclude = .venv
3 changes: 0 additions & 3 deletions .github/FUNDING.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/version-bump.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ 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]')

- name: Bump Minor Version
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]')

Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -34,7 +34,6 @@
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ all of the consumers.
The recommended method to install PartCAD for most users is:

```shell
pip install partcad
pip install partcad-cli
```

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.
Expand Down
12 changes: 12 additions & 0 deletions examples/consume_standalone/example.py
Original file line number Diff line number Diff line change
@@ -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)
File renamed without changes.
31 changes: 31 additions & 0 deletions partcad-cli/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]" }
]
maintainers = [
{name = "Roman Kuzmenko", email = "[email protected]" }
]
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"
7 changes: 7 additions & 0 deletions partcad-cli/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
partcad==0.2.20
pycairo
renderlab
rlPyCairo
svglib
ocp_vscode
progress
7 changes: 7 additions & 0 deletions partcad-cli/src/partcad_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from .cli import main as main_cli

__all__ = [
"main_cli",
]

__version__: str = "0.2.20"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import logging

from . import init
import partcad as pc


def cli_help_show(subparsers):
Expand Down Expand Up @@ -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"
Expand Down
File renamed without changes.
19 changes: 19 additions & 0 deletions partcad-cli/src/partcad_cli/template/init-public.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import:
# Add dependencies here
# <package-name>:
# desc: <package description> # optional
# type: <local|git|tar>
# path: <relative path> # type:local only
# url: <url of the package> # type:git|tar only
# relPath: <relative path within the repo> # type:git|tar only
# web: <package's or maintainer's url> # optional
# poc: <maintainer's email> # optional
partcad-index:
type: git
url: https://github.com/openvmp/partcad-index.git

parts:
# Add parts here

assemblies:
# Add assemblies here
47 changes: 47 additions & 0 deletions partcad/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]" }
]
maintainers = [
{name = "Roman Kuzmenko", email = "[email protected]" }
]
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"
10 changes: 10 additions & 0 deletions partcad/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 12 additions & 6 deletions src/partcad/context.py → partcad/src/partcad/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import atexit
import logging
import os
from progress.spinner import Spinner

import importlib

from . import consts
from . import project_config
Expand Down Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions src/partcad/project.py → partcad/src/partcad/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
43 changes: 29 additions & 14 deletions src/partcad/shape.py → partcad/src/partcad/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 7e887aa

Please sign in to comment.