Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose curses library name and version on Python level #75861

Closed
serhiy-storchaka opened this issue Oct 3, 2017 · 10 comments
Closed

Expose curses library name and version on Python level #75861

serhiy-storchaka opened this issue Oct 3, 2017 · 10 comments
Assignees
Labels
3.8 only security fixes extension-modules C modules in the Modules dir type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

BPO 31680
Nosy @Yhg1s, @terryjreedy, @vstinner, @serhiy-storchaka
PRs
  • bpo-31680: Add curses.ncurses_version. #4217
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2018-10-30.11:23:08.706>
    created_at = <Date 2017-10-03.19:39:02.613>
    labels = ['extension-modules', 'type-feature', '3.8']
    title = 'Expose curses library name and version on Python level'
    updated_at = <Date 2018-10-30.11:23:21.692>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2018-10-30.11:23:21.692>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2018-10-30.11:23:08.706>
    closer = 'serhiy.storchaka'
    components = ['Extension Modules']
    creation = <Date 2017-10-03.19:39:02.613>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31680
    keywords = ['patch']
    message_count = 10.0
    messages = ['303640', '303644', '303645', '303646', '303654', '303657', '303845', '303846', '305381', '328896']
    nosy_count = 4.0
    nosy_names = ['twouters', 'terry.reedy', 'vstinner', 'serhiy.storchaka']
    pr_nums = ['4217']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue31680'
    versions = ['Python 3.8']

    @serhiy-storchaka
    Copy link
    Member Author

    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.

    @serhiy-storchaka serhiy-storchaka added 3.7 (EOL) end of life extension-modules C modules in the Modules dir type-feature A feature request or enhancement labels Oct 3, 2017
    @vstinner
    Copy link
    Member

    vstinner commented Oct 3, 2017

    How can we get the ncurses version?

    @vstinner
    Copy link
    Member

    vstinner commented Oct 3, 2017

    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.

    @vstinner
    Copy link
    Member

    vstinner commented Oct 3, 2017

    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?

    @serhiy-storchaka
    Copy link
    Member Author

    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 bpo-15037. We still don't skip tests depending on the ncurses version because there is no easy way to determine the ncurses version in Python.

    @vstinner
    Copy link
    Member

    vstinner commented Oct 3, 2017

    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.

    @terryjreedy
    Copy link
    Member

    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.) bpo-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 bpo-15037.

    @serhiy-storchaka
    Copy link
    Member Author

    No need to backport this to 3.6. The test in 3.6 can be skipped on OpenBSD, independently from the ncurses version.

    @serhiy-storchaka
    Copy link
    Member Author

    PR 4217 adds a named tuple curses.ncurses_version containing the three components of the ncurses library version: major, minor, and patch.

    >>> curses.ncurses_version
    curses.ncurses_version(major=6, minor=0, patch=20160625)

    Other curses implementation don't provide a version programmically.

    @serhiy-storchaka serhiy-storchaka self-assigned this Nov 1, 2017
    @serhiy-storchaka
    Copy link
    Member Author

    New changeset b232df9 by Serhiy Storchaka in branch 'master':
    bpo-31680: Add curses.ncurses_version. (GH-4217)
    b232df9

    @serhiy-storchaka serhiy-storchaka added 3.8 only security fixes and removed 3.7 (EOL) end of life labels Oct 30, 2018
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes extension-modules C modules in the Modules dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants