From c94f11ddc0786091c01a0a79f4de99f2e1494081 Mon Sep 17 00:00:00 2001 From: Ray Donnelly Date: Tue, 15 Aug 2017 22:38:19 +0100 Subject: [PATCH 03/16] Add Anaconda Distribution version logic --- Include/pylifecycle.h | 1 + Lib/platform.py | 1 + Modules/main.c | 3 ++- Python/getversion.c | 42 +++++++++++++++++++++++++++++++++++++++--- 4 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Include/pylifecycle.h b/Include/pylifecycle.h index 1c5f7a6374..b0f8aeae76 100644 --- a/Include/pylifecycle.h +++ b/Include/pylifecycle.h @@ -63,6 +63,7 @@ int _Py_CheckPython3(); #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 d3ed5bf4c5..42f959e62b 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -1088,6 +1088,7 @@ def processor(): _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 d36db6d8b5..227daaf6b7 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -512,7 +512,8 @@ Py_Main(int argc, wchar_t **argv) return usage(0, argv[0]); if (version) { - printf("Python %s\n", PY_VERSION); + Py_SetProgramName(argv[0]); + fprintf(stderr, "Python %s :: %s\n", PY_VERSION, Anaconda_GetVersion()); return 0; } diff --git a/Python/getversion.c b/Python/getversion.c index 7bd6efd0a0..17fd1b98c4 100644 --- a/Python/getversion.c +++ b/Python/getversion.c @@ -2,14 +2,50 @@ /* 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\\" + #else + #define STDLIB_DIR L"/lib/python3.5/" + #endif + static char res[128]; + FILE *f; + wchar_t path[MAXPATHLEN+1]; + int c, 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 + 1 < sizeof(res)) { + c = fgetc(f); + if (c == EOF || c == '\n' || c == '\r') + break; + res[i++] = c; + } + fclose(f); + res[i] = '\0'; + } + return res; + #undef STDLIB_DIR +} + const char * Py_GetVersion(void) { static char version[250]; - PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s", - PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler()); + PyOS_snprintf(version, sizeof(version), "%.80s |%s| (%.80s) %.80s", + PY_VERSION, Anaconda_GetVersion(), + Py_GetBuildInfo(), Py_GetCompiler()); return version; } -- 2.14.3 (Apple Git-98)