From efede514539a4a0310f4276643ad50f838e7f957 Mon Sep 17 00:00:00 2001 From: Chris Lenk Date: Wed, 21 Mar 2018 13:56:50 -0400 Subject: [PATCH] Skip documenting some workbench stuff --- docs/conf.py | 11 +++++++++++ stix2/workbench.py | 17 +++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 49416a0..0764454 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -115,5 +115,16 @@ class STIXPropertyDocumenter(ClassDocumenter): self.add_line('', '') +def autodoc_skipper(app, what, name, obj, skip, options): + """Customize Sphinx to skip some member we don't want documented. + + Skips anything containing ':autodoc-skip:' in its docstring. + """ + if obj.__doc__ and ':autodoc-skip:' in obj.__doc__: + return skip or True + return skip + + def setup(app): app.add_autodocumenter(STIXPropertyDocumenter) + app.connect('autodoc-skip-member', autodoc_skipper) diff --git a/stix2/workbench.py b/stix2/workbench.py index 4436609..3a26a64 100644 --- a/stix2/workbench.py +++ b/stix2/workbench.py @@ -47,24 +47,24 @@ STIX_OBJS = [_AttackPattern, _Campaign, _CourseOfAction, _Identity, _ThreatActor, _Tool, _Vulnerability] -def created_by_wrapper(self, *args, **kwargs): +def _created_by_wrapper(self, *args, **kwargs): return _environ.creator_of(self, *args, **kwargs) -def relationships_wrapper(self, *args, **kwargs): +def _relationships_wrapper(self, *args, **kwargs): return _environ.relationships(self, *args, **kwargs) -def related_wrapper(self, *args, **kwargs): +def _related_wrapper(self, *args, **kwargs): return _environ.related_to(self, *args, **kwargs) -def constructor_wrapper(obj_type): +def _constructor_wrapper(obj_type): # Use an intermediate wrapper class so the implicit environment will create objects that have our wrapper functions wrapped_type = type(obj_type.__name__, obj_type.__bases__, dict( - created_by=created_by_wrapper, - relationships=relationships_wrapper, - related=related_wrapper, + created_by=_created_by_wrapper, + relationships=_relationships_wrapper, + related=_related_wrapper, **obj_type.__dict__ )) @@ -77,7 +77,8 @@ def constructor_wrapper(obj_type): # Create wrapper classes whose constructors call the implicit environment's create() for obj_type in STIX_OBJS: new_class = type(obj_type.__name__, (), {}) - new_class.__new__ = constructor_wrapper(obj_type) + new_class.__new__ = _constructor_wrapper(obj_type) + new_class.__doc__ = ':autodoc-skip:' globals()[obj_type.__name__] = new_class