diff options
author | Guido van Rossum <guido@python.org> | 1997-10-31 18:38:52 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-10-31 18:38:52 (GMT) |
commit | 197346fafe41332b896999b5bbdc7b1dabe57262 (patch) | |
tree | d33c989c731cacf01d7e266f8e68ba2335241b0c /Python/import.c | |
parent | 771c6c8f7a834baf41ea73914a13835325718fa9 (diff) | |
download | cpython-197346fafe41332b896999b5bbdc7b1dabe57262.zip cpython-197346fafe41332b896999b5bbdc7b1dabe57262.tar.gz cpython-197346fafe41332b896999b5bbdc7b1dabe57262.tar.bz2 |
New policy for package imports: only a directory containing
__init__.py (or __init__.pyc/.pyo, whichever applies) is considered a
package. All other subdirectories are left alone. Should make Konrad
Hinsen happy!
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/Python/import.c b/Python/import.c index 9f68c62..aef7353 100644 --- a/Python/import.c +++ b/Python/import.c @@ -636,6 +636,8 @@ is_builtin(name) extern FILE *PyWin_FindRegisteredModule(); #endif +static int find_init_module Py_PROTO((char *)); /* Forward */ + static struct filedescr * find_module(name, path, buf, buflen, p_fp) char *name; @@ -733,8 +735,10 @@ find_module(name, path, buf, buflen, p_fp) #ifdef HAVE_STAT if (stat(buf, &statbuf) == 0) { static struct filedescr fd = {"", "", PKG_DIRECTORY}; - if (S_ISDIR(statbuf.st_mode)) - return &fd; + if (S_ISDIR(statbuf.st_mode)) { + if (find_init_module(buf)) + return &fd; + } } #else /* XXX How are you going to test for directories? */ @@ -766,6 +770,38 @@ find_module(name, path, buf, buflen, p_fp) return fdp; } +#ifdef HAVE_STAT +/* Helper to look for __init__.py or __init__.py[co] in potential package */ +static int +find_init_module(buf) + char *buf; +{ + int save_len = strlen(buf); + int i = save_len; + struct stat statbuf; + + if (save_len + 13 >= MAXPATHLEN) + return 0; + buf[i++] = SEP; + strcpy(buf+i, "__init__.py"); + if (stat(buf, &statbuf) == 0) { + buf[save_len] = '\0'; + return 1; + } + i += strlen(buf+i); + if (Py_OptimizeFlag) + strcpy(buf+i, "o"); + else + strcpy(buf+i, "c"); + if (stat(buf, &statbuf) == 0) { + buf[save_len] = '\0'; + return 1; + } + buf[save_len] = '\0'; + return 0; +} +#endif /* HAVE_STAT */ + static int init_builtin Py_PROTO((char *)); /* Forward */ |