This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pythonstartup addition of minor error checking
Type: behavior Stage:
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: JosephArmbruster, amaury.forgeotdarc, christian.heimes, georg.brandl
Priority: low Keywords: patch

Created on 2007-11-14 04:07 by JosephArmbruster, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pythonstartup.patch JosephArmbruster, 2008-01-04 16:55 main.c patch for PYTHONSTARTUP error handling
Messages (7)
msg57482 - (view) Author: Joseph Armbruster (JosephArmbruster) Date: 2007-11-14 04:07
Trunk revision: 58963

Description:  No warning or error is reported it a file pointed to by
PYTHONSTARTUP is not readable.

Request:  To display a warning so that the user may be notified.

Note:  Errors that may occur in PyRun_SimpleFileExFlags are being cast
away, may be worthwhile to report an error for those as well (unless
this was avoided for good reason :-)

Suggestion:

static void RunStartupFile(PyCompilerFlags *cf)
{
  char *startup = Py_GETENV("PYTHONSTARTUP");
  if (startup != NULL && startup[0] != '\0') {
    FILE *fp = fopen(startup, "r");
    if (fp != NULL) {
      (void) PyRun_SimpleFileExFlags(fp, startup, 0, cf);
      PyErr_Clear();
      fclose(fp);
    }
    else {
      fprintf(stderr,"Warning: Could not read startup file %s\n",startup);
    }
  }
}
msg57489 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-11-14 15:18
Good idea!

Errors in the startup file are already reported by PyRun_*
msg57490 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-11-14 16:22
I've a far better patch that uses Python's infrastructure to report the
error:

Index: Modules/main.c
===================================================================
--- Modules/main.c      (Revision 58966)
+++ Modules/main.c      (Arbeitskopie)
@@ -132,6 +132,16 @@
                        (void) PyRun_SimpleFileExFlags(fp, startup, 0, cf);
                        PyErr_Clear();
                        fclose(fp);
+               } else {
+                       int save_errno;
+
+                       save_errno = errno;
+                       PySys_WriteStderr("Could not open PYTHONSTARTUP\n");
+                       errno = save_errno;
+                       PyErr_SetFromErrnoWithFilename(PyExc_IOError,
+                                       startup);
+                       PyErr_Print();
+                       PyErr_Clear();
                }
        }
 }


$ ./python
Python 3.0a1+ (py3k:58966M, Nov 14 2007, 17:17:06)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Could not open PYTHONSTARTUP
IOError: [Errno 2] No such file or directory:
'/home/heimes/.python/startup.py'
>>>                      

Fixed in r58969 (py3k)
msg57804 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2007-11-24 13:07
Shall we close this issue?
msg57807 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-11-24 15:45
I think we should backport it to 2.6 and maybe 2.5.
msg59239 - (view) Author: Joseph Armbruster (JosephArmbruster) Date: 2008-01-04 16:55
Backport to 2.6a0 and tested with:

Python 2.6a0 (trunk:59710M, Jan  4 2008, 11:36:45) [MSC v.1500 32 bit
(Intel)] on win32
msg64673 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-03-29 01:51
Backported to 2.6 in r62030 and 2.5 in r62031.
History
Date User Action Args
2022-04-11 14:56:28adminsetgithub: 45783
2008-03-29 01:51:16georg.brandlsetstatus: open -> closed
nosy: + georg.brandl
messages: + msg64673
2008-01-04 16:55:26JosephArmbrustersetfiles: + pythonstartup.patch
messages: + msg59239
2007-11-24 15:45:42christian.heimessetmessages: + msg57807
2007-11-24 13:07:20amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg57804
2007-11-14 16:22:06christian.heimessetresolution: accepted
messages: + msg57490
versions: - Python 3.0
2007-11-14 15:18:14christian.heimessetpriority: low
nosy: + christian.heimes
messages: + msg57489
versions: + Python 3.0
2007-11-14 08:04:55loewissetkeywords: + patch
2007-11-14 04:07:24JosephArmbrustercreate