@@ -122,6 +122,12 @@ set_process_name(PyConfig *config)
122
122
break ;
123
123
}
124
124
}
125
+ size_t i = executable.find_last_of (L" /\\ " );
126
+ if (i == std::wstring::npos) {
127
+ executable = PROGNAME;
128
+ } else {
129
+ executable.replace (i + 1 , std::wstring::npos, PROGNAME);
130
+ }
125
131
}
126
132
127
133
if (!home.empty ()) {
@@ -163,10 +169,29 @@ wmain(int argc, wchar_t **argv)
163
169
PyPreConfig preconfig;
164
170
PyConfig config;
165
171
172
+ const wchar_t *moduleName = NULL ;
173
+ const wchar_t *p = wcsrchr (argv[0 ], L' \\ ' );
174
+ if (!p) {
175
+ p = argv[0 ];
176
+ }
177
+ if (p) {
178
+ if (*p == L' \\ ' ) {
179
+ p++;
180
+ }
181
+
182
+ if (wcsnicmp (p, L" pip" , 3 ) == 0 ) {
183
+ moduleName = L" pip" ;
184
+ } else if (wcsnicmp (p, L" idle" , 4 ) == 0 ) {
185
+ moduleName = L" idlelib" ;
186
+ }
187
+ }
188
+
166
189
PyPreConfig_InitPythonConfig (&preconfig);
167
- status = Py_PreInitializeFromArgs (&preconfig, argc, argv);
168
- if (PyStatus_Exception (status)) {
169
- goto fail_without_config;
190
+ if (!moduleName) {
191
+ status = Py_PreInitializeFromArgs (&preconfig, argc, argv);
192
+ if (PyStatus_Exception (status)) {
193
+ goto fail_without_config;
194
+ }
170
195
}
171
196
172
197
status = PyConfig_InitPythonConfig (&config);
@@ -178,48 +203,32 @@ wmain(int argc, wchar_t **argv)
178
203
if (PyStatus_Exception (status)) {
179
204
goto fail;
180
205
}
206
+ if (moduleName) {
207
+ config.parse_argv = 0 ;
208
+ }
181
209
182
210
status = set_process_name (&config);
183
211
if (PyStatus_Exception (status)) {
184
212
goto fail;
185
213
}
186
214
187
- const wchar_t * p = _wgetenv (L" PYTHONUSERBASE" );
215
+ p = _wgetenv (L" PYTHONUSERBASE" );
188
216
if (!p || !*p) {
189
217
_wputenv_s (L" PYTHONUSERBASE" , get_user_base ().c_str ());
190
218
}
191
219
192
- p = wcsrchr (argv[0 ], L' \\ ' );
193
- if (!p) {
194
- p = argv[0 ];
195
- }
196
- if (p) {
197
- if (*p == L' \\ ' ) {
198
- p++;
220
+ if (moduleName) {
221
+ status = PyConfig_SetString (&config, &config.run_module , moduleName);
222
+ if (PyStatus_Exception (status)) {
223
+ goto fail;
199
224
}
200
-
201
- const wchar_t *moduleName = NULL ;
202
- if (wcsnicmp (p, L" pip" , 3 ) == 0 ) {
203
- moduleName = L" pip" ;
204
- /* No longer required when pip 19.1 is added */
205
- _wputenv_s (L" PIP_USER" , L" true" );
206
- } else if (wcsnicmp (p, L" idle" , 4 ) == 0 ) {
207
- moduleName = L" idlelib" ;
225
+ status = PyConfig_SetString (&config, &config.run_filename , NULL );
226
+ if (PyStatus_Exception (status)) {
227
+ goto fail;
208
228
}
209
-
210
- if (moduleName) {
211
- status = PyConfig_SetString (&config, &config.run_module , moduleName);
212
- if (PyStatus_Exception (status)) {
213
- goto fail;
214
- }
215
- status = PyConfig_SetString (&config, &config.run_filename , NULL );
216
- if (PyStatus_Exception (status)) {
217
- goto fail;
218
- }
219
- status = PyConfig_SetString (&config, &config.run_command , NULL );
220
- if (PyStatus_Exception (status)) {
221
- goto fail;
222
- }
229
+ status = PyConfig_SetString (&config, &config.run_command , NULL );
230
+ if (PyStatus_Exception (status)) {
231
+ goto fail;
223
232
}
224
233
}
225
234
0 commit comments