Skip to content

Commit

Permalink
Merge branch 'master' into rporter/MDAGModifier
Browse files Browse the repository at this point in the history
  • Loading branch information
yantor3d committed Jun 12, 2021
2 parents c1b8778 + b97a148 commit 491a2fd
Show file tree
Hide file tree
Showing 21 changed files with 2,536 additions and 660 deletions.
19 changes: 18 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,22 @@ jobs:
image: "2018.7" # For docker
pip: "2.7/get-pip.py"
devkit: "https://autodesk-adn-transfer.s3.us-west-2.amazonaws.com/ADN%20Extranet/M%26E/Maya/devkit%202018/Autodesk_Maya_2018_7_Update_DEVKIT_Linux.tgz"
generate_stubs: false # stubs generation only works with python 3
- maya: "2019.3"
image: "2019"
pip: "2.7/get-pip.py"
devkit: "https://autodesk-adn-transfer.s3.us-west-2.amazonaws.com/ADN%20Extranet/M%26E/Maya/devkit%202019/Autodesk_Maya_2019_3_Update_DEVKIT_Linux.tgz"
generate_stubs: false
- maya: "2020.4"
image: "2020"
pip: "2.7/get-pip.py"
devkit: "https://autodesk-adn-transfer.s3.us-west-2.amazonaws.com/ADN%20Extranet/M%26E/Maya/devkit%202020/Autodesk_Maya_2020_4_Update_DEVKIT_Linux.tgz"
generate_stubs: false
- maya: "2022"
image: "2022"
pip: "get-pip.py"
devkit: "https://autodesk-adn-transfer.s3.us-west-2.amazonaws.com/ADN%20Extranet/M%26E/Maya/devkit%202022/Autodesk_Maya_2022_DEVKIT_Linux.tgz"
generate_stubs: true

container: mottosso/maya:${{ matrix.image }}

Expand Down Expand Up @@ -169,12 +173,22 @@ jobs:
mayapy --version
export PYTHONPATH=$(pwd)/build
mayapy -m nose -xv --exe ./tests
- name: Generate Stubs
if: ${{ matrix.generate_stubs }}
run: |
mayapy -m pip install --user \
pybind11-stubgen==0.8.7 && \
export PYTHONPATH=$(pwd)/build
mayapy ./scripts/generate_stubs.py
- name: Artifacts
uses: actions/upload-artifact@v2
with:
name: linux-${{ matrix.maya }}
path: build/cmdc.so
path: |
build/cmdc.so
build/cmdc.pyi
# maya-osx:
Expand Down Expand Up @@ -243,13 +257,16 @@ jobs:
# linux-2019.3/cmdc.so
# linux-2020.4/cmdc.so
# linux-2022/cmdc.so
# /stubs/cmdc.pyi
# /cmdc.mod
with:
path: modules/cmdc-0.1.0

- name: Create distribution
run: |
cp ./cmdc.mod modules/
mkdir ./modules/cmdc-0.1.0/stubs
mv ./modules/cmdc-0.1.0/linux-2022/cmdc.pyi ./modules/cmdc-0.1.0/stubs/
zip -r cmdc-0.1.0.zip modules/
- name: Upload distribution
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*.dist-info
*.pyd
*.py[id]
build/**
tmp/*
*.pyc
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile.2022
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ RUN mayapy -m pip install --user \
flaky==3.7.0 \
six==1.16.0 \
sphinx==1.8.5 \
sphinxcontrib-napoleon==0.7
sphinxcontrib-napoleon==0.7 \
pybind11-stubgen==0.8.7

# Since 2019, this sucker throws an
# unnecessary warning if not declared.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ docker build -t cmdc .

Interested in helping out? Here's how to do it.

1. Get a free compiler, like [Visual Studio 2019]()
1. Download a Maya devkit, such as [this one]()
1. Get a free compiler, like [Visual Studio 2019](https://visualstudio.microsoft.com/vs/community/) for Windows
1. Download and unzip a [Maya devkit](https://www.autodesk.com/developer-network/platform-technologies/maya) (scroll down)
2. Clone this repository
3. Write your header file
4. Submit a pull-request
Expand All @@ -156,7 +156,7 @@ Great, then here's what's next.

```bash
# Tell cmdc about where your devkit is
$env:DEVKIT_LOCATION="C:\github\mayaexamples\maya-devkit\2020.2\windows"
$env:DEVKIT_LOCATION="C:\maya-devkit"

# Clone the big jeeves out of this repository
git clone https://github.com/mottosso/cmdc.git
Expand All @@ -173,4 +173,4 @@ From here, you'll have a freshly generated header file, ready to fill in. As you

```bash

```
```
4 changes: 2 additions & 2 deletions build_win32.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ Write-Host "(4) Cleaning.."
& python .\scripts\mfn.py clear

$t4 = $stopwatch.ElapsedMilliseconds

$clean_duration = $t4 - $t3
$total_duration = $t4 - $t0

Write-Host "(4) Finished in $clean_duration ms"
Write-Host "(4) ----------------------------"

$total_duration = $t4 - $t0
Write-Host "Successfully created .\build\cmdc.pyd in $total_duration ms"
32 changes: 32 additions & 0 deletions scripts/generate_stubs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import time
import pybind11_stubgen

STUBS_LOCATION = "build/cmdc.pyi"

print("Generating stubs")
t0 = time.time()

module = pybind11_stubgen.ModuleStubsGenerator("cmdc")
module.write_setup_py = False

print("(1) Parsing module..")

module.parse()

t1 = time.time()
print("(1) Finished in {0:0.3} s".format(t1-t0))
print("(1) ----------------------------")

print("(2) Writing stubs..")

with open(STUBS_LOCATION, "w") as handle:
content = "\n".join(module.to_lines())

handle.write(content)

t2 = time.time()
print("(2) Finished in {0:0.3} s".format(t2-t1))
print("(2) ----------------------------")

print("Succesfully created .{0} in {1:0.3} s".format(STUBS_LOCATION, t2-t0))

24 changes: 23 additions & 1 deletion scripts/parse_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,12 @@ def parse_header(header_name):
arguments = ', {}'.format(arguments)

m_method = getattr(m_class, method_name)
docstring = _remove_docstring_signatures(m_method.__doc__)

method_str = method_str_fmt.format(
class_name=class_name,
arguments=arguments,
doctstring=m_method.__doc__,
doctstring=docstring,
method_name=method_name,
return_type=return_type,
)
Expand Down Expand Up @@ -362,6 +363,27 @@ def filter_header_lines(class_name, lines):
if line == '};\n':
in_class_definition = False

def _remove_docstring_signatures(docstring):
signature_regex = re.compile(r".*\(.*\) -> .*")

lines = docstring.splitlines()

while lines:
line = lines[0]

# Exclude signature lines and empty lines
if signature_regex.match(line) or not line:
lines.pop(0)
continue

# Stop trying to pop as soon as we encounter a real doc line.
if line:
break

filtered_docstring = "\n".join(lines)

return filtered_docstring


def _is_complete_statement(statement):
if '(' in statement:
Expand Down
30 changes: 30 additions & 0 deletions src/ForwardDeclarations.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
py::class_<MAngle> Angle(m, "Angle");
py::class_<MDAGDrawOverrideInfo> DAGDrawOverrideInfo(m, "DAGDrawOverrideInfo");
py::class_<MDagPath> DagPath(m, "DagPath");
py::class_<MDagPathArray> DagPathArray(m, "DagPathArray");
py::class_<MDataBlock> DataBlock(m, "DataBlock");
py::class_<MDataHandle> DataHandle(m, "DataHandle");
py::class_<MDistance> Distance(m, "Distance");
py::class_<MFn> Fn(m, "Fn");
py::class_<MFnDependencyNode> FnDependencyNode(m, "FnDependencyNode");
py::class_<MMatrix> Matrix(m, "Matrix");
py::class_<MObject> Object(m, "Object");
py::class_<MObjectArray> ObjectArray(m, "ObjectArray");
py::class_<MObjectHandle> ObjectHandle(m, "ObjectHandle");
py::class_<MPlug> Plug(m, "Plug");
py::class_<MPoint> Point(m, "Point");
py::class_<MPxData> PxData(m, "PxData");
py::class_<MQuaternion> Quaternion(m, "Quaternion");
py::class_<MSelectionList> SelectionList(m, "SelectionList");
py::class_<MStatus> Status(m, "Status");
py::class_<MString> String(m, "String");
py::class_<MTime> Time(m, "Time");
py::class_<MTypeId> TypeId(m, "TypeId");
py::class_<MVector> Vector(m, "Vector");
py::enum_<MFn::Type> fn_type(Fn, "Type");
py::class_<MUuid> Uuid(m, "Uuid");
py::class_<MNodeClass> NodeClass(m, "NodeClass");
py::class_<MDGModifier> DGModifier(m, "DGModifier");
py::class_<MFnDagNode> FnDagNode(m, "FnDagNode");
py::class_<MBoundingBox> BoundingBox(m, "BoundingBox");
py::class_<MColor> Color(m, "Color");
57 changes: 46 additions & 11 deletions src/MBoundingBox.inl
Original file line number Diff line number Diff line change
@@ -1,42 +1,77 @@
py::class_<MBoundingBox>(m, "BoundingBox")
#define _doc_BoundingBox_center \
"Center point"

#define _doc_BoundingBox_clear \
"Empties the bounding box, setting its corners to (0, 0, 0)."

#define _doc_BoundingBox_contains \
"Returns True if a point lies within the bounding box."

#define _doc_BoundingBox_depth \
"Size in Z"

#define _doc_BoundingBox_expand \
"Expands the bounding box to include a point or other bounding box."

#define _doc_BoundingBox_height \
"Size in Y"

#define _doc_BoundingBox_intersects \
"Returns True if any part of a given bounding box lies within this one."

#define _doc_BoundingBox_transformUsing \
"Multiplies the bounding box's corners by a matrix."

#define _doc_BoundingBox_width \
"Size in X"

BoundingBox
.def(py::init<>())

.def("center", [](MBoundingBox& self) -> MPoint {
return self.center();
}, R"pbdoc(Center point)pbdoc")
}, _doc_BoundingBox_center)

.def("clear", [](MBoundingBox& self) -> void {
self.clear();
}, R"pbdoc(Empties the bounding box, setting its corners to (0, 0, 0).)pbdoc")
}, _doc_BoundingBox_clear)

.def("contains", [](MBoundingBox& self, MPoint point) -> bool {
return self.contains(point);
}, R"pbdoc(Returns True if a point lies within the bounding box.)pbdoc")
},
py::arg("point"),
_doc_BoundingBox_contains)

.def("depth", [](MBoundingBox& self) -> double {
return self.depth();
}, R"pbdoc(Size in Z)pbdoc")
}, _doc_BoundingBox_depth)

.def("expand", [](MBoundingBox& self, MBoundingBox box) -> void {
self.expand(box);
}, R"pbdoc(Expands the bounding box to include a point or other bounding box.)pbdoc")
},
py::arg("box"),
_doc_BoundingBox_expand)

.def("expand", [](MBoundingBox& self, MPoint point) -> void {
self.expand(point);
}, R"pbdoc(Expands the bounding box to include a point or other bounding box.)pbdoc")
}, py::arg("point"),
_doc_BoundingBox_expand)

.def("height", [](MBoundingBox& self) -> double {
return self.height();
}, R"pbdoc(Size in Y)pbdoc")
}, _doc_BoundingBox_height)

.def("intersects", [](MBoundingBox& self, MBoundingBox box, double tol = 0.0) -> bool {
return self.intersects(box, tol);
}, R"pbdoc(Returns True if any part of a given bounding box lies within this one.)pbdoc")
}, py::arg("box"),
py::arg("tol") = 0.0,
_doc_BoundingBox_intersects)

.def("transformUsing", [](MBoundingBox& self, MMatrix matrix) -> void {
self.transformUsing(matrix);
}, R"pbdoc(Multiplies the bounding box's corners by a matrix.)pbdoc")
}, py::arg("matrix"),
_doc_BoundingBox_transformUsing)

.def("width", [](MBoundingBox& self) -> double {
return self.width();
}, R"pbdoc(Size in X)pbdoc");
}, _doc_BoundingBox_width);
Loading

0 comments on commit 491a2fd

Please sign in to comment.