Bug 280697 - editors/fileobj fails to start due to a curses error
Summary: editors/fileobj fails to start due to a curses error
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Li-Wen Hsu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-08-08 19:40 UTC by Navdeep Parhar
Modified: 2024-10-30 00:54 UTC (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Navdeep Parhar freebsd_committer freebsd_triage 2024-08-08 19:40:29 UTC
I'm not able to run fileobj on a recent 14.1-STABLE system.

$ uname -a
FreeBSD dwarf 14.1-STABLE FreeBSD 14.1-STABLE #17 stable/14-n268102-6b1f530935c: Fri Jul 12 09:41:20 PDT 2024     root@dwarf:/usr/obj/usr/src/amd64.amd64/sys/GENERIC amd64
$ pkg info -I fileobj
fileobj-0.8.6_1                Portable hex editor with vi like interface
$ fileobj
Traceback (most recent call last):
  File "/usr/local/bin/fileobj", line 29, in <module>
    import fileobj.core
  File "/usr/local/lib/python3.11/site-packages/fileobj/core.py", line 30, in <module>
    from . import allocator
  File "/usr/local/lib/python3.11/site-packages/fileobj/allocator.py", line 24, in <module>
    from . import fileobj
  File "/usr/local/lib/python3.11/site-packages/fileobj/fileobj.py", line 34, in <module>
    from . import screen
  File "/usr/local/lib/python3.11/site-packages/fileobj/screen.py", line 33, in <module>
    from . import ncurses as _screen
  File "/usr/local/lib/python3.11/site-packages/fileobj/ncurses.py", line 29, in <module>
    from . import kbd
  File "/usr/local/lib/python3.11/site-packages/fileobj/kbd.py", line 47, in <module>
    _KEY_RESIZE    = curses.KEY_RESIZE
                     ^^^^^^^^^^^^^^^^^
AttributeError: module 'curses' has no attribute 'KEY_RESIZE'. Did you mean: 'KEY_RESUME'?

It looks like the curses in the python port is missing the KEY_RESIZE attribute.  Other KEY_ attributes are available though.

$ pkg info -Ix ^python
python-3.11_3,2                "meta-port" for the default version of Python interpreter
python3-3_4                    Meta-port for the Python interpreter 3.x
python311-3.11.9_1             Interpreted object-oriented programming language
$ python
Python 3.11.9 (main, Jul  9 2024, 16:57:46) [Clang 18.1.5 (https://github.com/llvm/llvm-project.git llvmorg-18.1.5-0-g617a15 on freebsd14
Type "help", "copyright", "credits" or "license" for more information.
>>> import curses
>>> curses.KEY_RESIZE
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'curses' has no attribute 'KEY_RESIZE'. Did you mean: 'KEY_RESUME'?
>>> curses.KEY_F1
265
>>>
Comment 1 Bugzilla Automation freebsd_committer freebsd_triage 2024-08-08 19:40:29 UTC
Maintainer informed via mail
Comment 2 Sean Farley freebsd_committer freebsd_triage 2024-09-13 13:26:35 UTC
This looks like an issue related to the latest ncurses (v6.5) import since this used to work with 14-STABLE and still does on 13.3-RELEASE-p6.  I think this issue belongs to base, but I am hesitant to move it over as I am only an alumni.  :)

When Python is built, is relies upon keyname() to determine which KEY_* variables to incorporate. Previously, keyname() would return KEY_RESIZE when the terminal was resized, but now, it returns NULL.

This is point where Python makes the determination.  If keyname() returns a NULL, then the KEY will not be included.  https://github.com/python/cpython/blob/v3.11.10/Modules/_cursesmodule.c#L4908

I did not dive into ncurses code much, but this has mention of KEY_RESIZE:  https://invisible-island.net/ncurses/NEWS.html#t20240120

Here is a simple program to show what keyname() can return:

#include <ncurses.h>

int main(void) {
    int ch;

    initscr();
    cbreak();
    noecho();

    printw("KEY_RESIZE: %s\n", keyname(KEY_RESIZE));
    while ((ch = getch()) != ERR) {
        printw("Got: %s\n", keyname(ch));
        refresh();
    }

    return (endwin());
}
Comment 3 Li-Wen Hsu freebsd_committer freebsd_triage 2024-10-16 13:33:24 UTC
CC bapt for ncurses 6.5 importing.
Comment 4 SHENG-YI HUNG 2024-10-16 14:13:05 UTC
Hello, this may fix your problem. Can you give it a try? https://reviews.freebsd.org/D47153. I have tested on ranger and it works again.
Comment 5 Sean Farley freebsd_committer freebsd_triage 2024-10-21 11:40:20 UTC
(In reply to SHENG-YI HUNG from comment #4)
Thank you!  That did fix both fileobj and that sample program.
Comment 6 commit-hook freebsd_committer freebsd_triage 2024-10-23 20:41:50 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=514f4e89acd2e7b1824b261055bef49a3da6a956

commit 514f4e89acd2e7b1824b261055bef49a3da6a956
Author:     SHENG-YI HONG <aokblast@FreeBSD.org>
AuthorDate: 2024-10-23 20:38:33 +0000
Commit:     Li-Wen Hsu <lwhsu@FreeBSD.org>
CommitDate: 2024-10-23 20:39:36 +0000

    ncurses: Fix codegen for key names and codes

    Adding back arguments, which were missed during the import of ncurses version
    6.5, to the code gen awk script.

    This is modified from lib_keyname.c and keys.list targets in
    contrib/ncurses/ncurses/Makefile.in of
    21817992b3314c908ab50f0bb88d2ee750b9c4ac

    PR:             280697
    Reported by:    np
    Reviewed by:    bapt
    Tested by:      scf
    Fixes:          21817992b331 ncurses: vendor import version 6.5
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D47153

 lib/ncurses/tinfo/Makefile | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Comment 7 commit-hook freebsd_committer freebsd_triage 2024-10-30 00:54:45 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=1e4603b7a8193064a9879c6c1906be1c7cb57575

commit 1e4603b7a8193064a9879c6c1906be1c7cb57575
Author:     SHENG-YI HONG <aokblast@FreeBSD.org>
AuthorDate: 2024-10-23 20:38:33 +0000
Commit:     Li-Wen Hsu <lwhsu@FreeBSD.org>
CommitDate: 2024-10-30 00:53:05 +0000

    ncurses: Fix codegen for key names and codes

    Adding back arguments, which were missed during the import of ncurses version
    6.5, to the code gen awk script.

    This is modified from lib_keyname.c and keys.list targets in
    contrib/ncurses/ncurses/Makefile.in of
    21817992b3314c908ab50f0bb88d2ee750b9c4ac

    PR:             280697
    Reported by:    np
    Reviewed by:    bapt
    Tested by:      scf
    Fixes:          21817992b331 ncurses: vendor import version 6.5
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D47153

    (cherry picked from commit 514f4e89acd2e7b1824b261055bef49a3da6a956)

 lib/ncurses/tinfo/Makefile | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)