Hi again,

after some more investigations,
I noticed that actually pyreverse
get associated classes right in
analysing its own source code:

http://www.logilab.org/image/6887

you see that, for instance, the class
classDiagram is defined in the file
diagrams.py and is an attribute of
classDiadefGenerator, the latter being
defined in diadefslib.py.
And we actually get the diamond arrow in
the UML diagram.

So I tried to cut the sources down
to a minimal example, getting

#-------------8<-------------------------
# this is the file diagrams.py
from pylint.pyreverse.utils import FilterMixIn

class Figure:
   pass
class Relationship(Figure):
pass class DiagramEntity(Figure):
   pass
class ClassDiagram(Figure, FilterMixIn):
pass class PackageDiagram(ClassDiagram):
   pass
#-------------8<-------------------------

#-------------8<-------------------------
# this is the file diadefslib.py
from diagrams import ClassDiagram

class DiaDefGenerator:
   pass
class ClassDiadefGenerator(DiaDefGenerator):
   def class_diagram(self, project, klass):
       self.classdiagram = ClassDiagram(klass, self.config.mode)
       return self.classdiagram
#-------------8<-------------------------

now doing

bash-3.2$ pyreverse -o png diadefslib.py diagrams.py -S

I don't get the attribute classdiagram to be recognized of type
ClassDiagram; see
http://www-sop.inria.fr/members/Giovanni.Gherdovich/tmp/wrong_from_pyreverse_src.png

BUT if I import from the site-packages folder instead of
from the same folder, i.e. I do

from pylint.pyreverse.diagrams import ClassDiagram

instead of

from diagrams import ClassDiagram

I get the right diagram: see
http://www-sop.inria.fr/members/Giovanni.Gherdovich/tmp/right_from_pyreverse_src.png

I tried to inspect the sources to understand
the reason of this, namely I was looking at
the `run` method in the class PyreverseCommand, in the file
/usr/lib/python2.5/site-packages/pylint/pyreverse/main.py

which is

#----------------------------------------------------
   def run(self, args):
       """checking argmuents and run project"""
       if not args:
           print self.help()
           return
       project = self.manager.project_from_files(args, astng_wrapper)
       linker = Linker(project, tag=True)
       handler = DiadefsHandler(self.config)
       diadefs = handler.get_diadefs(project, linker)
       if self.config.output_format == "vcg":
           writer.VCGWriter(self.config).write(diadefs)
       else:
           writer.DotWriter(self.config).write(diadefs)
#----------------------------------------------------

and I was trying to inspect the `project` object.
But I ended up lost in the _ast module, without
many clues for where to look for my answers.
Which data structures should I inspect, and how?

Any gotchas?

Thanks,
Giovanni Gherdovich
_______________________________________________
Python-Projects mailing list
Python-Projects@lists.logilab.org
http://lists.logilab.org/mailman/listinfo/python-projects

Reply via email to