9999-Add-Anaconda-Distribution-version-logic.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. From 135a70dc89bfd6f498f9f00c697d24014f1f8dd5 Mon Sep 17 00:00:00 2001
  2. From: Ray Donnelly <mingw.android@gmail.com>
  3. Date: Tue, 15 Aug 2017 22:34:16 +0100
  4. Subject: [PATCH 33/33] Add Anaconda Distribution version logic
  5. ---
  6. Include/pylifecycle.h | 1 +
  7. Lib/platform.py | 1 +
  8. Modules/main.c | 2 +-
  9. Python/getversion.c | 47 +++++++++++++++++++++++++++++++++++++++++++
  10. 4 files changed, 50 insertions(+), 1 deletion(-)
  11. diff --git a/Include/pylifecycle.h b/Include/pylifecycle.h
  12. index c5368b3c5e..06cb88ee9c 100644
  13. --- a/Include/pylifecycle.h 2022-03-21 11:03:42.132273076 +0300
  14. +++ b/Include/pylifecycle.h 2022-03-21 11:03:49.096407850 +0300
  15. @@ -54,6 +54,7 @@
  16. #endif
  17. /* In their own files */
  18. +PyAPI_FUNC(const char *) Anaconda_GetVersion(void);
  19. PyAPI_FUNC(const char *) Py_GetVersion(void);
  20. PyAPI_FUNC(const char *) Py_GetPlatform(void);
  21. PyAPI_FUNC(const char *) Py_GetCopyright(void);
  22. diff --git a/Lib/platform.py b/Lib/platform.py
  23. index 408587d36c..a32fefcebb 100755
  24. --- a/Lib/platform.py 2022-03-21 11:03:42.132273076 +0300
  25. +++ b/Lib/platform.py 2022-03-21 11:03:49.096407850 +0300
  26. @@ -978,6 +978,7 @@
  27. _sys_version_parser = re.compile(
  28. r'([\w.+]+)\s*' # "version<space>"
  29. + r'(?:\|[^|]*\|)?\s*' # version extra
  30. r'\(#?([^,]+)' # "(#buildno"
  31. r'(?:,\s*([\w ]*)' # ", builddate"
  32. r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)<space>"
  33. diff --git a/Modules/main.c b/Modules/main.c
  34. index 2b6b9855c4..5c4fcef424 100644
  35. --- a/Modules/main.c 2022-03-21 11:03:42.132273076 +0300
  36. +++ b/Modules/main.c 2022-03-21 11:03:49.096407850 +0300
  37. @@ -198,7 +198,7 @@
  38. return;
  39. }
  40. - fprintf(stderr, "Python %s on %s\n%s", Py_GetVersion(), Py_GetPlatform(), CondaEcosystemGetWarnings());
  41. + fprintf(stderr, "Python %s :: %s on %s\n%s", Py_GetVersion(), Anaconda_GetVersion(), Py_GetPlatform(), CondaEcosystemGetWarnings());
  42. if (config->site_import) {
  43. fprintf(stderr, "%s\n", COPYRIGHT);
  44. }
  45. diff --git a/Python/getversion.c b/Python/getversion.c
  46. index c32b6f9d60..b5dfffb606 100644
  47. --- a/Python/getversion.c 2022-03-21 11:03:42.132273076 +0300
  48. +++ b/Python/getversion.c 2022-03-21 11:03:49.100407927 +0300
  49. @@ -2,9 +2,56 @@
  50. /* Return the full version string. */
  51. #include "Python.h"
  52. +#include "osdefs.h"
  53. #include "patchlevel.h"
  54. +
  55. +const char *
  56. +Anaconda_GetVersion(void)
  57. +{
  58. +#ifdef MS_WIN32
  59. + #define STDLIB_DIR L"\\Lib\\"
  60. + /* We want to allow paths > 260 characters on Windows some day. */
  61. + #define MPL 2048
  62. +#else
  63. + #define STR(_s) #_s
  64. + #define XSTR(_s) STR(_s)
  65. + #define STDLIB_DIR L"/lib/python" XSTR(PY_MAJOR_VERSION) L"." XSTR(PY_MINOR_VERSION) L"/"
  66. + #define MPL MAXPATHLEN
  67. +#endif
  68. +
  69. + static char res[128];
  70. + FILE *f;
  71. + wchar_t path[MPL + 1];
  72. + int c;
  73. + unsigned int i;
  74. +
  75. + wcscpy(path, Py_GetPrefix());
  76. + wcscat(path, STDLIB_DIR L"version.txt");
  77. +
  78. + f = _Py_wfopen(path, L"rb");
  79. + if (f == NULL)
  80. + strcpy(res, "Anaconda, Inc.");
  81. + else {
  82. + i = 0;
  83. + while (i < sizeof(res) - 1) {
  84. + c = fgetc(f);
  85. + if (c == EOF || c == '\n' || c == '\r')
  86. + break;
  87. + res[i++] = c;
  88. + }
  89. + fclose(f);
  90. + res[i] = '\0';
  91. + }
  92. + return res;
  93. + #undef STR
  94. + #undef XSTR
  95. + #undef STDLIB_DIR
  96. + #undef MPL
  97. +}
  98. +
  99. +
  100. const char *
  101. Py_GetVersion(void)
  102. {