__init__.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
  2. # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
  3. # copyright 2003-2010 Sylvain Thenault, all rights reserved.
  4. # contact mailto:thenault@gmail.com
  5. #
  6. # This file is part of logilab-astng.
  7. #
  8. # logilab-astng is free software: you can redistribute it and/or modify it
  9. # under the terms of the GNU Lesser General Public License as published by the
  10. # Free Software Foundation, either version 2.1 of the License, or (at your
  11. # option) any later version.
  12. #
  13. # logilab-astng is distributed in the hope that it will be useful, but
  14. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
  16. # for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License along
  19. # with logilab-astng. If not, see <http://www.gnu.org/licenses/>.
  20. """Python Abstract Syntax Tree New Generation
  21. The aim of this module is to provide a common base representation of
  22. python source code for projects such as pychecker, pyreverse,
  23. pylint... Well, actually the development of this library is essentially
  24. governed by pylint's needs.
  25. It extends class defined in the python's _ast module with some
  26. additional methods and attributes. Instance attributes are added by a
  27. builder object, which can either generate extended ast (let's call
  28. them astng ;) by visiting an existent ast tree or by inspecting living
  29. object. Methods are added by monkey patching ast classes.
  30. Main modules are:
  31. * nodes and scoped_nodes for more information about methods and
  32. attributes added to different node classes
  33. * the manager contains a high level object to get astng trees from
  34. source files and living objects. It maintains a cache of previously
  35. constructed tree for quick access
  36. * builder contains the class responsible to build astng trees
  37. """
  38. __doctype__ = "restructuredtext en"
  39. import sys
  40. if sys.version_info >= (3, 0):
  41. BUILTINS_MODULE = 'builtins'
  42. else:
  43. BUILTINS_MODULE = '__builtin__'
  44. # WARNING: internal imports order matters !
  45. # make all exception classes accessible from astng package
  46. from logilab.astng.exceptions import *
  47. # make all node classes accessible from astng package
  48. from logilab.astng.nodes import *
  49. # trigger extra monkey-patching
  50. from logilab.astng import inference
  51. # more stuff available
  52. from logilab.astng import raw_building
  53. from logilab.astng.bases import YES, Instance, BoundMethod, UnboundMethod
  54. from logilab.astng.node_classes import are_exclusive, unpack_infer
  55. from logilab.astng.scoped_nodes import builtin_lookup
  56. # make a manager instance (borg) as well as Project and Package classes
  57. # accessible from astng package
  58. from logilab.astng.manager import ASTNGManager, Project
  59. MANAGER = ASTNGManager()
  60. del ASTNGManager
  61. # load brain plugins
  62. from os import listdir
  63. from os.path import join, dirname
  64. BRAIN_MODULES_DIR = join(dirname(__file__), 'brain')
  65. if BRAIN_MODULES_DIR not in sys.path:
  66. # add it to the end of the list so user path take precedence
  67. sys.path.append(BRAIN_MODULES_DIR)
  68. # load modules in this directory
  69. for module in listdir(BRAIN_MODULES_DIR):
  70. if module.endswith('.py'):
  71. __import__(module[:-3])