@@ -39,7 +39,7 @@ The :mod:`runpy` module provides two functions:
39
39
40
40
The *mod_name * argument should be an absolute module name.
41
41
If the module name refers to a package rather than a normal
42
- module, then that package is imported and the `` __main__ ` ` submodule within
42
+ module, then that package is imported and the :mod: ` __main__ ` submodule within
43
43
that package is then executed and the resulting module globals dictionary
44
44
returned.
45
45
@@ -74,15 +74,15 @@ The :mod:`runpy` module provides two functions:
74
74
75
75
Note that this manipulation of :mod: `sys ` is not thread-safe. Other threads
76
76
may see the partially initialised module, as well as the altered list of
77
- arguments. It is recommended that the :mod: ` sys ` module be left alone when
77
+ arguments. It is recommended that the `` sys ` ` module be left alone when
78
78
invoking this function from threaded code.
79
79
80
80
.. seealso ::
81
81
The :option: `-m ` option offering equivalent functionality from the
82
82
command line.
83
83
84
84
.. versionchanged :: 3.1
85
- Added ability to execute packages by looking for a `` __main__ ` ` submodule.
85
+ Added ability to execute packages by looking for a :mod: ` __main__ ` submodule.
86
86
87
87
.. versionchanged :: 3.2
88
88
Added ``__cached__ `` global variable (see :pep: `3147 `).
@@ -106,15 +106,16 @@ The :mod:`runpy` module provides two functions:
106
106
Execute the code at the named filesystem location and return the resulting
107
107
module globals dictionary. As with a script name supplied to the CPython
108
108
command line, the supplied path may refer to a Python source file, a
109
- compiled bytecode file or a valid sys.path entry containing a ``__main__ ``
110
- module (e.g. a zipfile containing a top-level ``__main__.py `` file).
109
+ compiled bytecode file or a valid :data: `sys.path ` entry containing a
110
+ :mod: `__main__ ` module
111
+ (e.g. a zipfile containing a top-level ``__main__.py `` file).
111
112
112
113
For a simple script, the specified code is simply executed in a fresh
113
- module namespace. For a valid sys.path entry (typically a zipfile or
114
+ module namespace. For a valid :data: ` sys.path ` entry (typically a zipfile or
114
115
directory), the entry is first added to the beginning of ``sys.path ``. The
115
116
function then looks for and executes a :mod: `__main__ ` module using the
116
117
updated path. Note that there is no special protection against invoking
117
- an existing :mod: ` __main__ ` entry located elsewhere on ``sys.path `` if
118
+ an existing `` __main__ ` ` entry located elsewhere on ``sys.path `` if
118
119
there is no such module at the specified location.
119
120
120
121
The optional dictionary argument *init_globals * may be used to pre-populate
@@ -137,22 +138,22 @@ The :mod:`runpy` module provides two functions:
137
138
supplied path, and ``__spec__ ``, ``__cached__ ``, ``__loader__ `` and
138
139
``__package__ `` will all be set to :const: `None `.
139
140
140
- If the supplied path is a reference to a valid sys.path entry, then
141
- ``__spec__ `` will be set appropriately for the imported `` __main__ ` `
141
+ If the supplied path is a reference to a valid :data: ` sys.path ` entry, then
142
+ ``__spec__ `` will be set appropriately for the imported :mod: ` __main__ `
142
143
module (that is, ``__spec__.name `` will always be ``__main__ ``).
143
144
``__file__ ``, ``__cached__ ``, ``__loader__ `` and ``__package__ `` will be
144
145
:ref: `set as normal <import-mod-attrs >` based on the module spec.
145
146
146
147
A number of alterations are also made to the :mod: `sys ` module. Firstly,
147
- `` sys.path ` ` may be altered as described above. ``sys.argv[0] `` is updated
148
+ :data: ` sys.path ` may be altered as described above. ``sys.argv[0] `` is updated
148
149
with the value of ``path_name `` and ``sys.modules[__name__] `` is updated
149
150
with a temporary module object for the module being executed. All
150
151
modifications to items in :mod: `sys ` are reverted before the function
151
152
returns.
152
153
153
154
Note that, unlike :func: `run_module `, the alterations made to :mod: `sys `
154
155
are not optional in this function as these adjustments are essential to
155
- allowing the execution of sys.path entries. As the thread-safety
156
+ allowing the execution of :data: ` sys.path ` entries. As the thread-safety
156
157
limitations still apply, use of this function in threaded code should be
157
158
either serialised with the import lock or delegated to a separate process.
158
159
@@ -165,7 +166,7 @@ The :mod:`runpy` module provides two functions:
165
166
.. versionchanged :: 3.4
166
167
Updated to take advantage of the module spec feature added by
167
168
:pep: `451 `. This allows ``__cached__ `` to be set correctly in the
168
- case where ``__main__ `` is imported from a valid sys.path entry rather
169
+ case where ``__main__ `` is imported from a valid :data: ` sys.path ` entry rather
169
170
than being executed directly.
170
171
171
172
.. versionchanged :: 3.12
0 commit comments