Format: application/x-python-code
1 o
2
3 ��h�[ � @ sL d Z ddlmZ ddlmZmZmZ dZddlZddl Z ddl
4 Z
5 ddlZddlZddl
6 Z
7 ddlZddlmZmZ ddlmZ G dd � d �Zg d
8 �Zdd� Zd
9 d� Zdd� Zdd� Zdd� Zdd� efdd� efdd� efgZe�dd� dd� fg� dd� ZG dd� d�Zg d�Zd)d!d"�Z eddfd#d$�Z!eG d%d&� d&e��Z"d'd(� Z#dS )*a� IPython extension to reload modules before executing user code.
10
11 ``autoreload`` reloads modules automatically before entering the execution of
12 code typed at the IPython prompt.
13
14 This makes for example the following workflow possible:
15
16 .. sourcecode:: ipython
17
18 In [1]: %load_ext autoreload
19
20 In [2]: %autoreload 2
21
22 In [3]: from foo import some_function
23
24 In [4]: some_function()
25 Out[4]: 42
26
27 In [5]: # open foo.py in an editor and change some_function to return 43
28
29 In [6]: some_function()
30 Out[6]: 43
31
32 The module was reloaded without reloading it explicitly, and the object
33 imported with ``from foo import ...`` was also updated.
34
35 Usage
36 =====
37
38 The following magic commands are provided:
39
40 ``%autoreload``, ``%autoreload now``
41
42 Reload all modules (except those excluded by ``%aimport``)
43 automatically now.
44
45 ``%autoreload 0``, ``%autoreload off``
46
47 Disable automatic reloading.
48
49 ``%autoreload 1``, ``%autoreload explicit``
50
51 Reload all modules imported with ``%aimport`` every time before
52 executing the Python code typed.
53
54 ``%autoreload 2``, ``%autoreload all``
55
56 Reload all modules (except those excluded by ``%aimport``) every
57 time before executing the Python code typed.
58
59 ``%autoreload 3``, ``%autoreload complete``
60
61 Same as 2/all, but also adds any new objects in the module. See
62 unit test at IPython/extensions/tests/test_autoreload.py::test_autoload_newly_added_objects
63
64 Adding ``--print`` or ``-p`` to the ``%autoreload`` line will print autoreload activity to
65 standard out. ``--log`` or ``-l`` will do it to the log at INFO level; both can be used
66 simultaneously.
67
68 ``%aimport``
69
70 List modules which are to be automatically imported or not to be imported.
71
72 ``%aimport foo``
73
74 Import module 'foo' and mark it to be autoreloaded for ``%autoreload 1``
75
76 ``%aimport foo, bar``
77
78 Import modules 'foo', 'bar' and mark them to be autoreloaded for ``%autoreload 1``
79
80 ``%aimport -foo``
81
82 Mark module 'foo' to not be autoreloaded.
83
84 Caveats
85 =======
86
87 Reloading Python modules in a reliable way is in general difficult,
88 and unexpected things may occur. ``%autoreload`` tries to work around
89 common pitfalls by replacing function code objects and parts of
90 classes previously in the module with new versions. This makes the
91 following things to work:
92
93 - Functions and classes imported via 'from xxx import foo' are upgraded
94 to new versions when 'xxx' is reloaded.
95
96 - Methods and properties of classes are upgraded on reload, so that
97 calling 'c.foo()' on an object 'c' created before the reload causes
98 the new code for 'foo' to be executed.
99
100 Some of the known remaining caveats are:
101
102 - Replacing code objects does not always succeed: changing a @property
103 in a class to an ordinary method or a method to a member variable
104 can cause problems (but in old objects only).
105
106 - Functions that are removed (eg. via monkey-patching) from a module
107 before it is reloaded are not upgraded.
108
109 - C extension modules cannot be reloaded, and so cannot be autoreloaded.
110
111 - While comparing Enum and Flag, the 'is' Identity Operator is used (even in the case '==' has been used (Similar to the 'None' keyword)).
112
113 - Reloading a module, or importing the same module by a different name, creates new Enums. These may look the same, but are not.
114 � )�magic_arguments)�Magics�magics_class�
115 line_magicTN)�
116 import_module�reload)�source_from_cachec @ sR e Zd ZdZ dZ dZ ddd�Zdd� Zdd � Zd
117 d� Z dd
118 � Z
119 ddd�ZdS )�ModuleReloaderFTNc C sF i | _ i | _i | _i | _i | _|| _dd� | _| jddd� d| _d S )Nc S � d S �N� ��msgr r �Sc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/extensions/autoreload.py�<lambda>� � z)ModuleReloader.__init__.<locals>.<lambda>TF)� check_all� do_reload) �failed�modules�skip_modules�old_objects�modules_mtimes�shell�_report�check�hide_errors)�selfr r r r �__init__� s
120
121 zModuleReloader.__init__c C �. z| j |= W n ty Y nw d| j|<