From 135a70dc89bfd6f498f9f00c697d24014f1f8dd5 Mon Sep 17 00:00:00 2001 From: Ray Donnelly Date: Tue, 15 Aug 2017 22:34:16 +0100 Subject: [PATCH 33/33] Add Anaconda Distribution version logic --- Include/pylifecycle.h | 1 + Lib/platform.py | 1 + Modules/main.c | 2 +- Python/getversion.c | 47 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/Include/pylifecycle.h b/Include/pylifecycle.h index c5368b3c5e..06cb88ee9c 100644 --- a/Include/pylifecycle.h 2022-03-21 11:03:42.132273076 +0300 +++ b/Include/pylifecycle.h 2022-03-21 11:03:49.096407850 +0300 @@ -54,6 +54,7 @@ #endif /* In their own files */ +PyAPI_FUNC(const char *) Anaconda_GetVersion(void); PyAPI_FUNC(const char *) Py_GetVersion(void); PyAPI_FUNC(const char *) Py_GetPlatform(void); PyAPI_FUNC(const char *) Py_GetCopyright(void); diff --git a/Lib/platform.py b/Lib/platform.py index 408587d36c..a32fefcebb 100755 --- a/Lib/platform.py 2022-03-21 11:03:42.132273076 +0300 +++ b/Lib/platform.py 2022-03-21 11:03:49.096407850 +0300 @@ -978,6 +978,7 @@ _sys_version_parser = re.compile( r'([\w.+]+)\s*' # "version" + r'(?:\|[^|]*\|)?\s*' # version extra r'\(#?([^,]+)' # "(#buildno" r'(?:,\s*([\w ]*)' # ", builddate" r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)" diff --git a/Modules/main.c b/Modules/main.c index 2b6b9855c4..5c4fcef424 100644 --- a/Modules/main.c 2022-03-21 11:03:42.132273076 +0300 +++ b/Modules/main.c 2022-03-21 11:03:49.096407850 +0300 @@ -198,7 +198,7 @@ return; } - fprintf(stderr, "Python %s on %s\n%s", Py_GetVersion(), Py_GetPlatform(), CondaEcosystemGetWarnings()); + fprintf(stderr, "Python %s :: %s on %s\n%s", Py_GetVersion(), Anaconda_GetVersion(), Py_GetPlatform(), CondaEcosystemGetWarnings()); if (config->site_import) { fprintf(stderr, "%s\n", COPYRIGHT); } diff --git a/Python/getversion.c b/Python/getversion.c index c32b6f9d60..b5dfffb606 100644 --- a/Python/getversion.c 2022-03-21 11:03:42.132273076 +0300 +++ b/Python/getversion.c 2022-03-21 11:03:49.100407927 +0300 @@ -2,9 +2,56 @@ /* Return the full version string. */ #include "Python.h" +#include "osdefs.h" #include "patchlevel.h" + +const char * +Anaconda_GetVersion(void) +{ +#ifdef MS_WIN32 + #define STDLIB_DIR L"\\Lib\\" + /* We want to allow paths > 260 characters on Windows some day. */ + #define MPL 2048 +#else + #define STR(_s) #_s + #define XSTR(_s) STR(_s) + #define STDLIB_DIR L"/lib/python" XSTR(PY_MAJOR_VERSION) L"." XSTR(PY_MINOR_VERSION) L"/" + #define MPL MAXPATHLEN +#endif + + static char res[128]; + FILE *f; + wchar_t path[MPL + 1]; + int c; + unsigned int i; + + wcscpy(path, Py_GetPrefix()); + wcscat(path, STDLIB_DIR L"version.txt"); + + f = _Py_wfopen(path, L"rb"); + if (f == NULL) + strcpy(res, "Anaconda, Inc."); + else { + i = 0; + while (i < sizeof(res) - 1) { + c = fgetc(f); + if (c == EOF || c == '\n' || c == '\r') + break; + res[i++] = c; + } + fclose(f); + res[i] = '\0'; + } + return res; + #undef STR + #undef XSTR + #undef STDLIB_DIR + #undef MPL +} + + const char * Py_GetVersion(void) {