@@ -122,6 +122,12 @@ set_process_name(PyConfig *config)
122122 break ;
123123 }
124124 }
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+ }
125131 }
126132
127133 if (!home.empty ()) {
@@ -163,10 +169,29 @@ wmain(int argc, wchar_t **argv)
163169 PyPreConfig preconfig;
164170 PyConfig config;
165171
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+
166189 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+ }
170195 }
171196
172197 status = PyConfig_InitPythonConfig (&config);
@@ -178,48 +203,32 @@ wmain(int argc, wchar_t **argv)
178203 if (PyStatus_Exception (status)) {
179204 goto fail;
180205 }
206+ if (moduleName) {
207+ config.parse_argv = 0 ;
208+ }
181209
182210 status = set_process_name (&config);
183211 if (PyStatus_Exception (status)) {
184212 goto fail;
185213 }
186214
187- const wchar_t * p = _wgetenv (L" PYTHONUSERBASE" );
215+ p = _wgetenv (L" PYTHONUSERBASE" );
188216 if (!p || !*p) {
189217 _wputenv_s (L" PYTHONUSERBASE" , get_user_base ().c_str ());
190218 }
191219
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;
199224 }
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;
208228 }
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;
223232 }
224233 }
225234
0 commit comments