summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmile Anclin <emile.anclin@logilab.fr>2008-08-26 16:36:44 +0200
committerEmile Anclin <emile.anclin@logilab.fr>2008-08-26 16:36:44 +0200
commit77ff2dadcdb6d7274fc96111084a3c5d9e950b2d (patch)
treeba00037dbd5c3a0dce22a4286ae39e093c1d87bf
parent42406ba75962cbc0230c59bf110ec9af517ce59f (diff)
downloadpylint-77ff2dadcdb6d7274fc96111084a3c5d9e950b2d.tar.gz
rebuild ancestor and associated options
-rw-r--r--man/pyreverse.129
-rw-r--r--pyreverse/diadefslib.py37
-rw-r--r--test/unittest_pyreverse_diadefs.py6
3 files changed, 41 insertions, 31 deletions
diff --git a/man/pyreverse.1 b/man/pyreverse.1
index 6d8c3f4..68450b8 100644
--- a/man/pyreverse.1
+++ b/man/pyreverse.1
@@ -42,18 +42,25 @@ and vcg). (For now, the 'xmi' and 'tests' commands are not under developpement.)
.IP "-c <class>, --class=<class>"
create a class diagram with all classes related to <class> [current: none]
the class must be in the file <modules>. By default, this will include all
- ancestors of <class> and include module names (i.e. '-my' ).
-.IP "-l <depth>, --search-level=<depth>"
-In combination with
-.B -c
-, limit depth of search for associated classes [default: not limited].
- For example, <depth>=1 will only take classes directly related to the classes
- in the project, while <depth>=2 will also take all classes related to those
- fecthed by<depth>=1.
+ ancestors and associated classes of <class> and include module names
+ (i.e. '-ASmy' ).
+
+.IP -a <ancestor>, --show-ancestors=<ancestor>
+ show <ancestor> generations of ancestor classes not in <projects>
+.IP -A, --all-ancestors=[yn]
+ show all ancestors off all classes in <projects> [current: none]
+.IP -s <ass_level>, --show-associated=<associated>
+ show <ass_level> associated classes. <ass_level>=1 will only take classes
+ directly related to the classes in the project, while <ass_level>=2
+ will also take all classes related to those fecthed by<depth>=1.
+.IP -S, --all-associated=[yn]
+ show recursively all associated off all associated classes [current: none]
+
+.IP "-b, --builtin"
+ include builtin objects in representation of classes [current: False]
.IP "-m [yn], --module-names=[yn]"
- include module name in representation of classes [current: none]
-.IP "-b [yn], --builtin=[yn]"
- include builtin objects in representation of classes [current: none]
+ include module name in representation of classes. This will include full module path in the class name. [current: none]
+
.SH PYREVERSE DIAGRAM
If no -c and no --diadefs option specified,
diff --git a/pyreverse/diadefslib.py b/pyreverse/diadefslib.py
index b5be391..58fcc3c 100644
--- a/pyreverse/diadefslib.py
+++ b/pyreverse/diadefslib.py
@@ -141,13 +141,13 @@ class OptionHandler:
def __init__(self, linker, handler):
self.config = handler.config
self.show_attr = handler.show_attr
- self.include_module_name = self.config.module_names
+ self._set_default_options()
self.linker = linker
def get_title(self, node ):
"""get title for objects"""
title = node.name
- if self.include_module_name:
+ if self.module_names:
title = '%s.%s' % (node.root().name, title)
return title
@@ -156,7 +156,12 @@ class OptionHandler:
# FIXME : does it work as it should ?
return (self.config.show_builtin) or not \
(node.name in ('object', 'type') or node.root().name == '__builtin__')
-
+
+ def _set_default_options(self):
+ self.module_names = self._default[self.config.module_names]
+ self.all_ancestors = self._default[self.config.all_ancestors]
+ self.all_associated = self._default[self.config.all_associated]
+
class DefaultDiadefGenerator(LocalsVisitor, OptionHandler):
"""generate minimum diagram definition for the project :
@@ -166,6 +171,7 @@ class DefaultDiadefGenerator(LocalsVisitor, OptionHandler):
"""
def __init__(self, linker, handler):
+ self._default = {None:False, True:True, False:False}
OptionHandler.__init__(self, linker, handler)
LocalsVisitor.__init__(self)
@@ -205,7 +211,7 @@ class DefaultDiadefGenerator(LocalsVisitor, OptionHandler):
add this class to the class diagram definition
"""
self._do_class(node)
- if self.config.show_ancestors:
+ if self.config.show_ancestors or self.all_ancestors:
for ancestor in node.ancestors(recurs=False):
self._do_class(ancestor)
@@ -229,13 +235,12 @@ class ClassDiadefGenerator(OptionHandler):
"""
def __init__(self, linker, handler):
+ self._default = {None:True, True:True, False:False}
OptionHandler.__init__(self, linker, handler)
- if self.include_module_name == None:
- self.include_module_name = True
-
+
def class_diagram(self, project, klass):
"""return a class diagram definition for the given klass and its
- related klasses. Search deep depends on the config.include_level
+ related klasses. Search deep depends on the associated_level
(=1 will take all classes directly related, while =2 will also take
all classes related to the one fecthed by=1)
"""
@@ -248,24 +253,24 @@ class ClassDiadefGenerator(OptionHandler):
module = project.modules[0]
klass = klass.split('.')[-1]
klass = module.ilookup(klass).next()
- level = int(self.config.include_level)
+ level = int(self.config.show_associated)
self.extract_classes(diagram, klass, level)
return diagram
- def extract_classes(self, diagram, klass_node, include_level):
- """extract classes related to klass_node until include_level is 0
+ def extract_classes(self, diagram, klass_node, associated_level):
+ """extract classes related to klass_node until associated_level is 0
"""
if diagram.has_node(klass_node):
return
self.add_class_def(diagram, klass_node)
- # TODO : add all ancestors whatever the include_level ?
- include_level -= 1
+ # TODO : add ancestors depending on show_ancestors
+ associated_level -= 1
for ancestor in klass_node.ancestors():
if not self.show_builtin(ancestor):
continue
- self.extract_classes(diagram, ancestor, include_level)
+ self.extract_classes(diagram, ancestor, associated_level)
- if include_level == 0:
+ if associated_level == 0:
return
# association
for name, ass_nodes in klass_node.instance_attrs_type.items():
@@ -275,7 +280,7 @@ class ClassDiadefGenerator(OptionHandler):
if not isinstance(ass_node, astng.Class) \
or not self.show_builtin(ass_node):
continue
- self.extract_classes(diagram, ass_node, include_level)
+ self.extract_classes(diagram, ass_node, associated_level)
def add_class_def(self, diagram, klass_node):
"""add a class definition to the class diagram
diff --git a/test/unittest_pyreverse_diadefs.py b/test/unittest_pyreverse_diadefs.py
index 18ab9c8..7b2404a 100644
--- a/test/unittest_pyreverse_diadefs.py
+++ b/test/unittest_pyreverse_diadefs.py
@@ -30,10 +30,8 @@ def astng_wrapper(func, modname):
return func(modname)
project = ASTNGManager().project_from_files(['data'], astng_wrapper)
-attrs = {'module_names': None, 'output_format': None, 'diadefs_file': None,
- 'quiet': 0, 'classes': (), 'mode': 'PUB_ONLY',
- 'show_builtin': False, 'include_level': -1}
-config = Config(attrs)
+
+config = Config()
handler = DiadefsHandler(config)
def _process_classes(classes):