ó
¡¼™\c           @  s‘  d  Z  d d l m Z e d k rd d l Z d d l Z d d l m Z d d l Z d d l	 m
 Z
 m Z m Z m Z e
 e ƒ Z e e e ƒ d d d ƒ Z e e ƒ Z e j j d e ƒ e j d	 d
 ƒ Z e j e d d ƒ Z e j d d d d d ƒe j d d d d d ƒe j e ƒ e j e d d ƒ Z e j d d d d d ƒe j d d d d d ƒe j e ƒ e j ƒ  \ a Z e r±e j d e e j d f ƒ n  t j d k rÐe j d ƒ n  t j d k rïe j d ƒ n  t j  d k re j d ƒ n  t j! d k r-e j d ƒ n  t j d k t _ t j d k t _ t j  d k t _  t j! d k t _! t j r™t j r™e j d  ƒ n  t j r»t j r»e j d! ƒ n  t j  rÝt j! rÝe j d" ƒ n  t j  oît j! t _" e j# Z$ d# e% f d$ „  ƒ  YZ& i  a' d% „  Z( d& „  Z) g  a* d' „  Z+ e, ƒ  g  d d d( „ Z. e. e _# e# d) ƒ t* j/ ƒ  x t* D] Z0 e1 e0 ƒ qvWn  d S(*   sE   
Import diagnostics. Run bin/diagnose_imports.py --help for details.
iÿÿÿÿ(   t   print_functiont   __main__N(   t   builtins(   t   abspatht   dirnamet   joint   normpaths   ..i    t   usagesQ   Usage: %prog option [options]

Import analysis for imports between SymPy modules.s   Analysis optionssC   Options that define what to do. Exactly one of these must be given.s
   --problemst   helpsú   Print all import problems, that is: If an import pulls in a package instead of a module (e.g. sympy.core instead of sympy.core.add); if it imports a symbol that is already present; if it imports a symbol from somewhere other than the defining module.t   actiont   counts	   --originsss   For each imported symbol in each module, print the module that defined it. (This is useful for import refactoring.)s   Sort optionss    These options define the sort order for output lines. At most one of these options is allowed. Unsorted output will reflect the order in which imports happened.s   --by-importers.   Sort output lines by name of importing module.s   --by-origins-   Sort output lines by name of imported module.s'   Unexpected arguments %s (try %s --help)i   s,   --problems must not be given more than once.s+   --origins must not be given more than once.s/   --by-importer must not be given more than once.s-   --by-origin must not be given more than once.s4   At least one of --problems and --origins is requireds2   At most one of --problems and --origins is alloweds7   At most one of --by-importer and --by-origin is allowedt
   Definitionc           B  s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s(   Information about a symbol's definition.c         C  s   | |  _  | |  _ | |  _ d  S(   N(   t   namet   valuet   definer(   t   selfR   R   R   (    (    sE   lib/python2.7/site-packages/sympy/utilities/tests/diagnose_imports.pyt   __init__`   s    		c         C  s   t  |  j ƒ S(   N(   t   hashR   (   R   (    (    sE   lib/python2.7/site-packages/sympy/utilities/tests/diagnose_imports.pyt   __hash__d   s    c         C  s"   |  j  | j  k o! |  j | j k S(   N(   R   R   (   R   t   other(    (    sE   lib/python2.7/site-packages/sympy/utilities/tests/diagnose_imports.pyt   __eq__f   s    c         C  s   |  | k S(   N(    (   R   R   (    (    sE   lib/python2.7/site-packages/sympy/utilities/tests/diagnose_imports.pyt   __ne__h   s    c         C  s    d t  |  j ƒ t  |  j ƒ f S(   Ns   Definition(%s, ..., %s)(   t   reprR   R   (   R   (    (    sE   lib/python2.7/site-packages/sympy/utilities/tests/diagnose_imports.pyt   __repr__j   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R   (    (    (    sE   lib/python2.7/site-packages/sympy/utilities/tests/diagnose_imports.pyR   ^   s   				c         C  s5   |  | k p4 |  d k o4 | d k o4 |  j | d ƒ S(   s,   Is a the same module as or a submodule of b?t   .N(   t   Nonet
   startswith(   t   at   b(    (    sE   lib/python2.7/site-packages/sympy/utilities/tests/diagnose_imports.pyt	   in_modulep   s    c         C  s   t  |  d ƒ S(   sg   Is module relevant for import checking?

        Only imports between relevant modules will be checked.t   sympy(   R    (   t   module(    (    sE   lib/python2.7/site-packages/sympy/utilities/tests/diagnose_imports.pyt   relevantt   s    c         G  s/   t  j r t |  | ƒ n t j |  | ƒ d  S(   N(   t   optionst
   by_processt   printt   sorted_messagest   append(   t   msgt   args(    (    sE   lib/python2.7/site-packages/sympy/utilities/tests/diagnose_imports.pyR)   |   s    	c         C  s†  t  j t j d ƒ ƒ } | j } | d } | | j k rV d | t | j ƒ f } n | } t |  | | | | ƒ }	 |	 j }
 t	 | ƒ r‚t	 |
 ƒ r‚xI |	 j
 j ƒ  D]8 } t | |	 j
 | | ƒ } | t k r¥ |
 t | <q¥ q¥ Wt |	 d ƒ rt j rt d |  | ƒ qt d | |  ƒ n  | d k r‚| } d | k r…| j d ƒ sj| j d	 ƒ sj| j d
 ƒ rsg  } q…|	 j
 j ƒ  } n  x÷ | D]ì } | |	 j
 k rÖt j rÀt d |
 | | ƒ qxt d | |
 | ƒ qŒt | |	 j
 | | ƒ } t | } | |
 k r:t j r$t d |
 | | ƒ qxt d | |
 | ƒ qŒt j r_t d |
 | | | | ƒ qŒt d | |
 | | | ƒ qŒWq‚n  |	 S(   sŽ  __import__ wrapper - does not change imports at all, but tracks them.

        Default order is implemented by doing output directly.
        All other orders are implemented by collecting output information into
        a sorted list that will be emitted after all imports are processed.

        Indirect imports can only occur after the requested symbol has been
        imported directly (because the indirect import would not have a module
        to pick the symbol up from).
        So this code detects indirect imports by checking whether the symbol in
        question was already imported.

        Keeps the semantics of __import__ unchanged.i   R   s
   %s line %st   __path__s'   Error: %s (a package) is imported by %ss$   Error: %s contains package import %st   *s   __init__.pys   __init__.pycs   __init__.pyos<   Error: %s.%s is not defined (yet), but %s tries to import its>   Error: %s tries to import %s.%s, which did not define it (yet)s&   Error: %s.%s is imported again into %ss   Error: %s imports %s.%s againsA   Error: %s.%s is imported by %s, which should import %s.%s insteads7   Error: %s imports %s.%s but should import %s.%s insteadN(   t   inspectt   getframeinfot   syst	   _getframet   filenamet   strt   linenot   builtin_importR   R#   t   __dict__t   iterkeysR   t   symbol_definerst   hasattrR$   t	   by_originR)   R   t   endswith(   R"   t   globalst   localst   fromlistt   levelt   caller_framet   importer_filenamet   importer_modulet   importer_referencet   resultt   importee_modulet   symbolt
   definitiont   symbol_listt   symbol_definer(    (    sE   lib/python2.7/site-packages/sympy/utilities/tests/diagnose_imports.pyt   tracking_importƒ   sf    	
				
		R!   (2   R   t
   __future__R    R   R/   R-   t   sympy.core.compatibilityR   t   optparset   os.pathR   R   R   R   t   __file__t	   this_filet	   sympy_dirt   patht   insertt   OptionParsert   option_parsert   OptionGroupt   option_groupt
   add_optiont   add_option_groupt
   parse_argsR$   R*   t   errort   argvt   problemst   originst   by_importerR9   R%   t
   __import__R4   t   objectR   R7   R    R#   R'   R)   R;   R   RI   t   sortt   messageR&   (    (    (    sE   lib/python2.7/site-packages/sympy/utilities/tests/diagnose_imports.pyt   <module>   sœ   "				


				S	

