Skip to content

Commit 0188f04

Browse files
Merge pull request #100 from psardin001/pr/documentation
Fix and expand DocClassMethod() usage to add it to relevant functions
2 parents 5f606d1 + afba5d2 commit 0188f04

32 files changed

Lines changed: 322 additions & 129 deletions

doc/configure.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,13 @@ def _xmlDirFromPkgConfig(pkg):
116116

117117
nsToPackage = {
118118
"hpp::core": _xmlDirFromPkgConfig("hpp-core"),
119+
"hpp::core::path": _xmlDirFromPkgConfig("hpp-core"),
119120
"hpp::constraints": _xmlDirFromPkgConfig("hpp-constraints"),
121+
"hpp::constraints::solver": _xmlDirFromPkgConfig("hpp-constraints"),
122+
"hpp::pinocchio": _xmlDirFromPkgConfig("hpp-pinocchio"),
123+
"hpp::manipulation": _xmlDirFromPkgConfig("hpp-manipulation"),
124+
"hpp::manipulation::graph": _xmlDirFromPkgConfig("hpp-manipulation"),
125+
"hpp::manipulation::pathPlanner": _xmlDirFromPkgConfig("hpp-manipulation"),
120126
}
121127

122128

@@ -142,7 +148,7 @@ def make_doc_string(brief, detailled):
142148

143149

144150
def make_args_string(args):
145-
return "(" + ",".join(['arg("' + a + '")' for a in args]) + ")"
151+
return "(" + ",".join(['boost::python::arg("' + a + '")' for a in args]) + ")"
146152

147153

148154
def substitute(istr, ostr):

doc/doxygen_xml_parser.py

Lines changed: 90 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ def _getCompound(self, kind, name):
1616

1717
def classDoc(self, name):
1818
el = self._getCompound("class", name)
19-
return ClassDoc(path.join(self.directory, el.get("refid") + ".xml"))
19+
return ClassDoc(
20+
path.join(self.directory, el.get("refid") + ".xml"), self.directory
21+
)
2022

2123

2224
class ClassDoc:
23-
def __init__(self, filename):
25+
def __init__(self, filename, directory=None):
2426
self.tree = etree.parse(filename)
2527
self.compound = self.tree.find("./compounddef")
2628
self.classname = self.compound.find("compoundname").text.strip()
29+
self.directory = directory if directory else path.dirname(filename)
30+
self._group_cache = {}
2731

2832
@staticmethod
2933
def _getDoc(el):
@@ -33,30 +37,91 @@ def _getDoc(el):
3337
detailed = d.text.strip() if d.text else ""
3438
return brief, detailed
3539

40+
def _getMemberFromGroup(self, memberDefKind, name):
41+
"""Look for memberdef in a group file via member refid."""
42+
members = self.compound.xpath(
43+
"sectiondef/member[@kind='" + memberDefKind + "' and name='" + name + "']"
44+
)
45+
if not members:
46+
return None
47+
member = members[0]
48+
refid = member.get("refid")
49+
if not refid:
50+
return None
51+
group_id = refid.rsplit("_1", 1)[0]
52+
if group_id not in self._group_cache:
53+
group_file = path.join(self.directory, group_id + ".xml")
54+
if not path.isfile(group_file):
55+
return None
56+
self._group_cache[group_id] = etree.parse(group_file)
57+
group_tree = self._group_cache[group_id]
58+
memberdefs = group_tree.xpath(
59+
"//memberdef[@id='" + refid + "' and @kind='" + memberDefKind + "']"
60+
)
61+
if memberdefs:
62+
return memberdefs[0]
63+
return None
64+
65+
def _getMemberFromInherited(self, memberDefKind, name):
66+
"""Look for memberdef in base class XML via listofallmembers member refid."""
67+
members = self.compound.xpath("listofallmembers/member[name='" + name + "']")
68+
if not members:
69+
return None
70+
member = members[0]
71+
refid = member.get("refid")
72+
if not refid:
73+
return None
74+
# Extract base class file from refid
75+
# e.g., "classhpp_1_1pinocchio_1_1AbstractDevice_1a312..." -> "classhpp_1_1pinocchio_1_1AbstractDevice"
76+
parts = refid.rsplit("_1", 1)
77+
if len(parts) < 2:
78+
return None
79+
base_class_id = parts[0]
80+
base_class_file = path.join(self.directory, base_class_id + ".xml")
81+
if not path.isfile(base_class_file):
82+
return None
83+
if base_class_id not in self._group_cache:
84+
self._group_cache[base_class_id] = etree.parse(base_class_file)
85+
base_tree = self._group_cache[base_class_id]
86+
memberdefs = base_tree.xpath(
87+
"//memberdef[@id='" + refid + "' and @kind='" + memberDefKind + "']"
88+
)
89+
if memberdefs:
90+
return memberdefs[0]
91+
return None
92+
3693
def _getMember(self, sectionKind, memberDefKind, name):
37-
# return self.compound.xpath ("sectiondef[@kind='" + sectionKind
38-
try:
39-
return self.compound.xpath(
40-
"sectiondef[re:test(@kind,'"
41-
+ sectionKind
42-
+ "')]/memberdef[@kind='"
43-
+ memberDefKind
44-
+ "' and name='"
45-
+ name
46-
+ "']",
47-
namespaces={"re": "http://exslt.org/regular-expressions"},
48-
)[0]
49-
except IndexError as e:
50-
msg = (
51-
"Error: Could not find member ("
52-
+ sectionKind
53-
+ ") "
54-
+ name
55-
+ " of class "
56-
+ self.classname
57-
)
58-
print(msg + "\n" + str(e), file=sys.stderr)
59-
raise IndexError(msg)
94+
# First try to find memberdef directly in class XML
95+
results = self.compound.xpath(
96+
"sectiondef[re:test(@kind,'"
97+
+ sectionKind
98+
+ "')]/memberdef[@kind='"
99+
+ memberDefKind
100+
+ "' and name='"
101+
+ name
102+
+ "']",
103+
namespaces={"re": "http://exslt.org/regular-expressions"},
104+
)
105+
if results:
106+
return results[0]
107+
# Fall back to looking in group files (for @ingroup documented classes)
108+
memberdef = self._getMemberFromGroup(memberDefKind, name)
109+
if memberdef is not None:
110+
return memberdef
111+
# Fall back to looking in base class files (for inherited methods)
112+
memberdef = self._getMemberFromInherited(memberDefKind, name)
113+
if memberdef is not None:
114+
return memberdef
115+
msg = (
116+
"Error: Could not find member ("
117+
+ sectionKind
118+
+ ") "
119+
+ name
120+
+ " of class "
121+
+ self.classname
122+
)
123+
print(msg, file=sys.stderr)
124+
raise IndexError(msg)
60125

61126
def getClassDoc(self):
62127
return self._getDoc(self.compound)

src/pyhpp/constraints/by-substitution.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <hpp/constraints/solver/by-substitution.hh>
3232
#include <pyhpp/constraints/fwd.hh>
3333

34-
// DocNamespace(hpp::constraints)
34+
// DocNamespace(hpp::constraints::solver)
3535

3636
using namespace boost::python;
3737

@@ -54,7 +54,7 @@ void exposeBySubstitution() {
5454
.value("INFEASIBLE", HierarchicalIterative::INFEASIBLE)
5555
.value("SUCCESS", HierarchicalIterative::SUCCESS);
5656

57-
// DocClass(solver::BySubstitution)
57+
// DocClass(BySubstitution)
5858
class_<BySubstitution, bases<HierarchicalIterative> >(
5959
"BySubstitution", init<LiegroupSpacePtr_t>())
6060
.def("explicitConstraintSetHasChanged",

src/pyhpp/constraints/explicit.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <hpp/constraints/explicit.hh>
3232
#include <pinocchio/multibody/fwd.hpp>
3333

34+
// DocNamespace(hpp::constraints)
35+
3436
using namespace boost::python;
3537

3638
namespace pyhpp {
@@ -61,6 +63,7 @@ ExplicitPtr_t createExplicit(const LiegroupSpacePtr_t& configSpace,
6163
}
6264

6365
void exposeExplicit() {
66+
// DocClass(Explicit)
6467
class_<Explicit, ExplicitPtr_t, boost::noncopyable>("Explicit", no_init)
6568
.def("create", &createExplicit)
6669
.staticmethod("create");

src/pyhpp/constraints/generic-transformation.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <hpp/constraints/generic-transformation.hh>
3232
#include <pyhpp/constraints/fwd.hh>
3333

34+
// DocNamespace(hpp::constraints)
35+
3436
using namespace boost::python;
3537

3638
namespace pyhpp {

src/pyhpp/constraints/implicit.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void exposeImplicit() {
6161
.def("comparisonType",
6262
static_cast<const ComparisonTypes_t& (Implicit::*)() const>(
6363
&Implicit::comparisonType),
64-
return_internal_reference<>())
64+
return_internal_reference<>(), DocClassMethod(comparisonType))
6565
.def("comparisonType",
6666
static_cast<void (Implicit::*)(const ComparisonTypes_t&)>(
6767
&Implicit::comparisonType))

src/pyhpp/constraints/locked-joint.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <hpp/pinocchio/liegroup-element.hh>
2626
#include <pyhpp/constraints/fwd.hh>
2727

28+
// DocNamespace(hpp::constraints)
29+
2830
using namespace boost::python;
2931

3032
namespace pyhpp {

src/pyhpp/constraints/relative-com.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#include <hpp/pinocchio/device.hh>
3333
#include <pyhpp/core/fwd.hh>
3434
#include <pyhpp/util.hh>
35+
36+
// DocNamespace(hpp::constraints)
37+
3538
using namespace boost::python;
3639

3740
namespace pyhpp {
@@ -64,9 +67,10 @@ static RelativeComPtr_t create3(const std::string& name,
6467
}
6568

6669
void exposeRelativeCom() {
70+
// DocClass(RelativeCom)
6771
class_<RelativeCom, RelativeComPtr_t, bases<DifferentiableFunction>,
6872
boost::noncopyable>("RelativeCom", no_init)
69-
.def("create", &create1)
73+
.def("create", &create1, DocClassMethod(create))
7074
.def("create", &create2)
7175
.def("create", &create3)
7276
.staticmethod("create");

src/pyhpp/core/config-validation.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void exposeConfigValidation() {
6969
.PYHPP_DEFINE_METHOD2(ConfigValidations, add, DocClassMethod(add))
7070
.PYHPP_DEFINE_METHOD2(ConfigValidations, numberConfigValidations,
7171
DocClassMethod(numberConfigValidations))
72-
.PYHPP_DEFINE_METHOD2(ConfigValidations, clear, DocClassMethod(clear));
72+
.def("clear", &ConfigValidations::clear);
7373
}
7474
} // namespace core
7575
} // namespace pyhpp

src/pyhpp/core/configuration-shooter.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include <pyhpp/core/fwd.hh>
3333
#include <pyhpp/util.hh>
3434

35+
// DocNamespace(hpp::core)
36+
3537
using namespace boost::python;
3638

3739
namespace pyhpp {
@@ -43,9 +45,10 @@ struct CSWrapper {
4345
};
4446

4547
void exposeConfigurationShooter() {
48+
// DocClass(ConfigurationShooter)
4649
class_<ConfigurationShooter, ConfigurationShooterPtr_t, boost::noncopyable>(
4750
"ConfigurationShooter", no_init)
48-
.def("shoot", &CSWrapper::shoot);
51+
.def("shoot", &CSWrapper::shoot, DocClassMethod(shoot));
4952
}
5053
} // namespace core
5154
} // namespace pyhpp

0 commit comments

Comments
 (0)