classification
Title: Expose curses library name and version on Python level
Type: enhancement Stage:
Components: Extension Modules Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: haypo, serhiy.storchaka, terry.reedy, twouters
Priority: normal Keywords:

Created on 2017-10-03 19:39 by serhiy.storchaka, last changed 2017-10-06 19:38 by serhiy.storchaka.

Messages (8)
msg303640 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-10-03 19:39
The name and the version of the curses library are needed for work around bugs in old versions or skip tests on platforms that provide broken curses library (like OpenBSD providing ncurses 5.7).

The curses and _curses modules provide the attribute "version" (= b'2.2'), but this is just a version of the module.
msg303644 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2017-10-03 19:41
How can we get the ncurses version?
msg303645 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2017-10-03 19:44
On Fedora 26, /usr/include/ncurses/curses.h contains:
---
/* These are defined only in curses.h, and are used for conditional compiles */
#define NCURSES_VERSION_MAJOR 6
#define NCURSES_VERSION_MINOR 0
#define NCURSES_VERSION_PATCH 20170212

/* This is defined in more than one ncurses header, for identification */
#undef  NCURSES_VERSION
#define NCURSES_VERSION "6.0"

/*
 * Identify the mouse encoding version.
 */
#define NCURSES_MOUSE_VERSION 2
---

You want to expose such versions? Do you know if there are "curses" implementations different than GNU ncurses?
https://www.gnu.org/software/ncurses/

I'm asking to know how other implementations expose their versions.
msg303646 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2017-10-03 19:45
> The name and the version of the curses library are needed for work around bugs in old versions or skip tests on platforms that provide broken curses library (like OpenBSD providing ncurses 5.7).

If there are known issues depending on the ncurses version, it may help to export this version in the test.pythoninfo utility. Do you have an example of known bug? Do we already skip tests depending on the ncurses version?
msg303654 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-10-03 21:54
Yes, this is what I meant. The version should be exposed as a tuple (major, minor, patch) or as a special named tuple. I don't know what to do with other implementations. NCURSES_VERSION_MAJOR is not a part of standard. One solution -- set the version to (0, 0, 0) for unknown implementations. Or expose ncurses version as optional ncurses_version, and expose versions for other known implementations with different names.

A known bug is issue15037. We still don't skip tests depending on the ncurses version because there is no easy way to determine the ncurses version in Python.
msg303657 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2017-10-03 22:51
I suggest:

curses._NCURSES_VERSION_INFO = (6, 0, 20170212)
curses._NCURSES_VERSION = "6.0"
curses._NCURSES_MOUSE_VERSION = 2

Similar example, the readline module uses:

    PyModule_AddIntConstant(m, "_READLINE_VERSION", RL_READLINE_VERSION);
    PyModule_AddIntConstant(m, "_READLINE_RUNTIME_VERSION", rl_readline_version);
    PyModule_AddStringConstant(m, "_READLINE_LIBRARY_VERSION", rl_library_version);

readline has two famous implementations: GNU readline and editline. editline reuses GNU readline constants, but the string mentions "editline". Example on macOS El Capitain (test.pythoninfo output):

readline._READLINE_LIBRARY_VERSION: EditLine wrapper
readline._READLINE_RUNTIME_VERSION: 0x402
readline._READLINE_VERSION: 0x402

http://buildbot.python.org/all/builders/x86-64%20El%20Capitan%203.x/builds/871/steps/pythoninfo/logs/stdio

I'm not sure that it's useful to make versions public. I suggest to start with private versions, since we only plan to use them in tests right now.
msg303845 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-10-06 19:13
pythoninfo seems like the right place.  It is publicly readable.  We just reserved the right to change it in any release as needed.  (This actually is useful to other users also as long as they know.) #15037 was originally filed for 3.4 and is currently marked for 3.6.  Backporting this to 3.6 will allow a 3.6 fix for #15037.
msg303846 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-10-06 19:38
No need to backport this to 3.6. The test in 3.6 can be skipped on OpenBSD, independently from the ncurses version.
History
Date User Action Args
2017-10-06 19:38:54serhiy.storchakasetmessages: + msg303846
2017-10-06 19:13:14terry.reedysetnosy: + terry.reedy
messages: + msg303845
2017-10-03 22:51:23hayposetmessages: + msg303657
2017-10-03 21:54:35serhiy.storchakasetmessages: + msg303654
2017-10-03 19:45:23hayposetmessages: + msg303646
2017-10-03 19:44:04hayposetmessages: + msg303645
2017-10-03 19:41:26hayposetnosy: + haypo
messages: + msg303644
2017-10-03 19:39:02serhiy.storchakacreate