|
44 | 44 |
|
45 | 45 | * When Python is hosted in another exe (different directory, embedded via |
46 | 46 | COM, etc), the Python Home will not be deduced, so the core path from |
47 | | - the registry is used. Other "application paths "in the registry are |
| 47 | + the registry is used. Other "application paths" in the registry are |
48 | 48 | always read. |
49 | 49 |
|
50 | 50 | * If Python can't find its home and there is no registry (eg, frozen |
@@ -576,6 +576,40 @@ calculate_path(void) |
576 | 576 | buf = strchr(buf, '\0'); |
577 | 577 | } |
578 | 578 | *buf = '\0'; |
| 579 | + /* Now to pull one last hack/trick. If sys.prefix is |
| 580 | + empty, then try and find it somewhere on the paths |
| 581 | + we calculated. We scan backwards, as our general policy |
| 582 | + is that Python core directories are at the *end* of |
| 583 | + sys.path. We assume that our "lib" directory is |
| 584 | + on the path, and that our 'prefix' directory is |
| 585 | + the parent of that. |
| 586 | + */ |
| 587 | + if (*prefix=='\0') { |
| 588 | + char lookBuf[MAXPATHLEN+1]; |
| 589 | + char *look = buf - 1; /* 'buf' is at the end of the buffer */ |
| 590 | + while (1) { |
| 591 | + int nchars; |
| 592 | + char *lookEnd = look; |
| 593 | + /* 'look' will end up one character before the |
| 594 | + start of the path in question - even if this |
| 595 | + is one character before the start of the buffer |
| 596 | + */ |
| 597 | + while (*look != DELIM && look >= module_search_path) |
| 598 | + look--; |
| 599 | + nchars = lookEnd-look; |
| 600 | + strncpy(lookBuf, look+1, nchars); |
| 601 | + lookBuf[nchars] = '\0'; |
| 602 | + /* Up one level to the parent */ |
| 603 | + reduce(lookBuf); |
| 604 | + if (search_for_prefix(lookBuf, LANDMARK)) { |
| 605 | + break; |
| 606 | + } |
| 607 | + /* If we are out of paths to search - give up */ |
| 608 | + if (look < module_search_path) |
| 609 | + break; |
| 610 | + look--; |
| 611 | + } |
| 612 | + } |
579 | 613 | } |
580 | 614 |
|
581 | 615 |
|
|
0 commit comments