@@ -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 `).
@@ -101,15 +101,16 @@ The :mod:`runpy` module provides two functions:
101
101
Execute the code at the named filesystem location and return the resulting
102
102
module globals dictionary. As with a script name supplied to the CPython
103
103
command line, the supplied path may refer to a Python source file, a
104
- compiled bytecode file or a valid sys.path entry containing a ``__main__ ``
105
- module (e.g. a zipfile containing a top-level ``__main__.py `` file).
104
+ compiled bytecode file or a valid :data: `sys.path ` entry containing a
105
+ :mod: `__main__ ` module
106
+ (e.g. a zipfile containing a top-level ``__main__.py `` file).
106
107
107
108
For a simple script, the specified code is simply executed in a fresh
108
- module namespace. For a valid sys.path entry (typically a zipfile or
109
+ module namespace. For a valid :data: ` sys.path ` entry (typically a zipfile or
109
110
directory), the entry is first added to the beginning of ``sys.path ``. The
110
111
function then looks for and executes a :mod: `__main__ ` module using the
111
112
updated path. Note that there is no special protection against invoking
112
- an existing :mod: ` __main__ ` entry located elsewhere on ``sys.path `` if
113
+ an existing `` __main__ ` ` entry located elsewhere on ``sys.path `` if
113
114
there is no such module at the specified location.
114
115
115
116
The optional dictionary argument *init_globals * may be used to pre-populate
@@ -132,22 +133,22 @@ The :mod:`runpy` module provides two functions:
132
133
supplied path, and ``__spec__ ``, ``__cached__ ``, ``__loader__ `` and
133
134
``__package__ `` will all be set to :const: `None `.
134
135
135
- If the supplied path is a reference to a valid sys.path entry, then
136
- ``__spec__ `` will be set appropriately for the imported `` __main__ ` `
136
+ If the supplied path is a reference to a valid :data: ` sys.path ` entry, then
137
+ ``__spec__ `` will be set appropriately for the imported :mod: ` __main__ `
137
138
module (that is, ``__spec__.name `` will always be ``__main__ ``).
138
139
``__file__ ``, ``__cached__ ``, ``__loader__ `` and ``__package__ `` will be
139
140
:ref: `set as normal <import-mod-attrs >` based on the module spec.
140
141
141
142
A number of alterations are also made to the :mod: `sys ` module. Firstly,
142
- `` sys.path ` ` may be altered as described above. ``sys.argv[0] `` is updated
143
+ :data: ` sys.path ` may be altered as described above. ``sys.argv[0] `` is updated
143
144
with the value of ``path_name `` and ``sys.modules[__name__] `` is updated
144
145
with a temporary module object for the module being executed. All
145
146
modifications to items in :mod: `sys ` are reverted before the function
146
147
returns.
147
148
148
149
Note that, unlike :func: `run_module `, the alterations made to :mod: `sys `
149
150
are not optional in this function as these adjustments are essential to
150
- allowing the execution of sys.path entries. As the thread-safety
151
+ allowing the execution of :data: ` sys.path ` entries. As the thread-safety
151
152
limitations still apply, use of this function in threaded code should be
152
153
either serialised with the import lock or delegated to a separate process.
153
154
@@ -160,7 +161,7 @@ The :mod:`runpy` module provides two functions:
160
161
.. versionchanged :: 3.4
161
162
Updated to take advantage of the module spec feature added by
162
163
:pep: `451 `. This allows ``__cached__ `` to be set correctly in the
163
- case where ``__main__ `` is imported from a valid sys.path entry rather
164
+ case where ``__main__ `` is imported from a valid :data: ` sys.path ` entry rather
164
165
than being executed directly.
165
166
166
167
.. seealso ::
0 commit comments