beets icon indicating copy to clipboard operation
beets copied to clipboard

term_width() throws Exception on fresh installs

Open methical opened this issue 11 months ago • 15 comments

Problem

Fresh installing the latest version of beets using pipx results in beets not beeing usable.

11:33:59 chris@fedora ~ → pipx install beets
  installed package beets 2.5.1, installed using Python 3.14.2
  These apps are now globally available
    - beet
done! ✨ 🌟 ✨
11:34:11 chris@fedora ~ → beet config -e
Traceback (most recent call last):
  File "/home/chris/.local/bin/beet", line 5, in <module>
    from beets.ui import main
  File "/home/chris/.local/share/pipx/venvs/beets/lib64/python3.14/site-packages/beets/ui/__init__.py", line 858, in <module>
    indent_str, left, right, separator=" -> ", max_width=term_width()
                                                         ~~~~~~~~~~^^
  File "/home/chris/.local/share/pipx/venvs/beets/lib64/python3.14/site-packages/beets/ui/__init__.py", line 715, in term_width
    buf = fcntl.ioctl(0, termios.TIOCGWINSZ, " " * 4)
SystemError: buffer overflow

Setup

  • OS: Fedora Linux 43 (Workstation Edition) x86_64 (Linux 6.17.12-300.fc43.x86_64)
  • Python version: 3.14.2
  • beets version: 2.5.1
  • Turning off plugins made problem go away (yes/no): dnt

My configuration (output of beet config) is non existent

Running beet to create a config file beet config -e results in the above mentioned error

Bugfix

Editing init.py and catching the correct exception (in my case SystemError) in the method term_width() solves the problem and beets lets me edit a fresh config file.

methical avatar Dec 21 '25 10:12 methical

We do not officially support python 3.14 yet.

For the issue at hand please see also https://github.com/beetbox/beets/discussions/6222

semohr avatar Dec 21 '25 15:12 semohr

Thanks for the reply :) I tried searching the issues here but somehow I haven't found anything related to my problem. However given from the documentation: https://beets.readthedocs.io/en/stable/guides/installation.html#installation

Beets requires Python 3.9 or later.

Maybe the documentation must be updated then.

methical avatar Dec 21 '25 18:12 methical

I guess we would rather just support python 3.14 in our next release. Python 3.14 is just over a month old, and I think our last release even predates this. Early adoption can always comes with slight issues ;)

Btw we list all supported (tested) python versions in our pyprojet.toml: https://github.com/beetbox/beets/blob/master/pyproject.toml#L18-L23

Please just be patient for a short while we work on a fix🤞

semohr avatar Dec 21 '25 22:12 semohr

Python 3.14 is just over a month old

I am not that much into the python game to know that. Guess it happens when you keep your Linux up2date.

I am being patient until then and close this issue.

methical avatar Dec 22 '25 10:12 methical

Still a very valid issue! Let's keep it open otherwise it is hard to track.

semohr avatar Dec 23 '25 14:12 semohr

I'm temporarily applying this patch for debian packaging:

--- a/beets/ui/__init__.py
+++ b/beets/ui/__init__.py
@@ -712,7 +712,7 @@
         return fallback

     try:
-        buf = fcntl.ioctl(0, termios.TIOCGWINSZ, " " * 4)
+        buf = fcntl.ioctl(0, termios.TIOCGWINSZ, b'\x00' * 8)
     except OSError:
         return fallback
     try:
--- a/beetsplug/lyrics.py
+++ b/beetsplug/lyrics.py
@@ -745,7 +745,7 @@
     TRANSLATE_URL = "https://api.cognitive.microsofttranslator.com/translate"
     LINE_PARTS_RE = re.compile(r"^(\[\d\d:\d\d.\d\d\]|) *(.*)$")
     SEPARATOR = " | "
-    remove_translations = partial(re.compile(r" / [^\n]+").sub, "")
+    remove_translations = staticmethod(partial(re.compile(r" / [^\n]+").sub, ""))

     _log: Logger
     api_key: str

plenaerts avatar Dec 29 '25 10:12 plenaerts

@plenaerts would you like to submit a PR with the fix?

snejus avatar Dec 29 '25 16:12 snejus

@snejus I can, but I haven't tested every corner of beets. I got the thing to build and run again. The majority of tests run fine as per autopkgtest reports. But I'm not deep into the beets code base... Do you still want the PR? 🙂

Edit: sorry, I was very incomplete... I can't make gstreamer work for py 3.14 too. I disabled that in test_bdp.py and test_replaygain.py. Ref my temporary patch for that. I haven't looked into that too much yet.

Do you still want the PR? ;-)

plenaerts avatar Dec 29 '25 19:12 plenaerts

I believe this was already fixed by #6132, no? The relevant point is:

Python 3.14 introduced stricter requirements for input type in low level fnctl.ioctl function which we used to detect the terminal width. I replaced it with high-level, cross-platform shutil.get_terminal_size().

ctrueden avatar Jan 04 '26 23:01 ctrueden

I hope this is the right place to report that the same break appears on arch linux since python 3.14 rolled out.

$ python --version                                                                                                                         
Python 3.14.2

$ pacman -Q beets                                                                                                                          
beets 2.5.1-3

$ beet --help
Traceback (most recent call last):
  File "/usr/bin/beet", line 5, in <module>
    from beets.ui import main
  File "/usr/lib/python3.14/site-packages/beets/ui/__init__.py", line 858, in <module>
    indent_str, left, right, separator=" -> ", max_width=term_width()
                                                         ~~~~~~~~~~^^
  File "/usr/lib/python3.14/site-packages/beets/ui/__init__.py", line 715, in term_width
    buf = fcntl.ioctl(0, termios.TIOCGWINSZ, " " * 4)
SystemError: buffer overflow

Looking forward for the next version 😃 I take the opportunity to express my gratitude for your work. Beets is a cool piece of software and a pleasure to use.

Keksoj avatar Jan 11 '26 22:01 Keksoj

Arch package maintainer here, I'm currently ~throwing stuff at the wall to see what sticks~ fixing this.

EDIT: Arch package 2.5.1-4 contains a fix for this.

grawlinson avatar Jan 12 '26 00:01 grawlinson

Arch package maintainer here, I'm currently ~throwing stuff at the wall to see what sticks~ fixing this.

EDIT: Arch package 2.5.1-4 contains a fix for this.

Many thanks! I installed 2.5.1-4 on my arch machine and the error message changed!

$ sudo pacman -Sy beets
:: Synchronizing package databases...
 core                                                                   121.8 KiB   236 KiB/s 00:01 [###########################################################] 100%
 extra                                                                    7.9 MiB  27.4 MiB/s 00:00 [###########################################################] 100%
 multilib is up to date
resolving dependencies...
looking for conflicting packages...

Packages (1) beets-2.5.1-4

Total Download Size:   0.96 MiB
Total Installed Size:  5.54 MiB
Net Upgrade Size:      0.00 MiB

:: Proceed with installation? [Y/n]
:: Retrieving packages...
 beets-2.5.1-4-any                                                      984.5 KiB  3.22 MiB/s 00:00 [###########################################################] 100%
(1/1) checking keys in keyring                                                                      [###########################################################] 100%
(1/1) checking package integrity                                                                    [###########################################################] 100%
(1/1) loading package files                                                                         [###########################################################] 100%
(1/1) checking for file conflicts                                                                   [###########################################################] 100%
(1/1) checking available disk space                                                                 [###########################################################] 100%
:: Processing package changes...
(1/1) upgrading beets                                                                               [###########################################################] 100%
:: Running post-transaction hooks...
(1/2) Arming ConditionNeedsUpdate...
(2/2) Checking which packages need to be rebuilt
foreign	manim
foreign	mimeo
foreign	protonup-qt
foreign	python-backports.cached_property
foreign	python-click-default-group
foreign	python-cloup
foreign	python-future
foreign	python-glcontext
foreign	python-inputs
foreign	python-isosurfaces
foreign	python-manimpango
foreign	python-mapbox-earcut
foreign	python-moderngl
foreign	python-moderngl-window
foreign	python-multipledispatch
foreign	python-pyglet
foreign	python-pyrr
foreign	python-screeninfo
foreign	python-skia-pathops
foreign	python-steam
foreign	python-svgelements


$ beet --version
beets version 2.5.1
Python version 3.14.2
plugins: chroma, convert, duplicates, embedart, fetchart, info, inline, missing, parentwork, random, zero

beet import -c ufomammut-idolum/                                                                                                                              
Traceback (most recent call last):
  File "/usr/bin/beet", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/usr/lib/python3.14/site-packages/beets/ui/__init__.py", line 1697, in main
    _raw_main(args)
    ~~~~~~~~~^^^^^^
  File "/usr/lib/python3.14/site-packages/beets/ui/__init__.py", line 1676, in _raw_main
    subcommand.func(lib, suboptions, subargs)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/site-packages/beets/ui/commands.py", line 1378, in import_func
    import_files(lib, byte_paths, query)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/site-packages/beets/ui/commands.py", line 1322, in import_files
    session.run()
    ~~~~~~~~~~~^^
  File "/usr/lib/python3.14/site-packages/beets/importer/session.py", line 234, in run
    pl.run_parallel(QUEUE_SIZE)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/usr/lib/python3.14/site-packages/beets/util/pipeline.py", line 468, in run_parallel
    raise exc_info[1].with_traceback(exc_info[2])
  File "/usr/lib/python3.14/site-packages/beets/util/pipeline.py", line 333, in run
    out = self.coro.send(msg)
  File "/usr/lib/python3.14/site-packages/beets/util/pipeline.py", line 216, in coro
    func(*(args + (task,)))
    ~~~~^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/site-packages/beets/importer/stages.py", line 139, in lookup_candidates
    plugins.send("import_task_start", session=session, task=task)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/site-packages/beets/plugins.py", line 648, in send
    if (r := handler(**arguments)) is not None
             ~~~~~~~^^^^^^^^^^^^^
  File "/usr/lib/python3.14/site-packages/beets/plugins.py", line 329, in wrapper
    return func(*args, **kwargs)
  File "/usr/lib/python3.14/site-packages/beetsplug/chroma.py", line 195, in fingerprint_task
    return fingerprint_task(self._log, task, session)
  File "/usr/lib/python3.14/site-packages/beetsplug/chroma.py", line 274, in fingerprint_task
    acoustid_match(log, item.path)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/site-packages/beetsplug/chroma.py", line 90, in acoustid_match
    duration, fp = acoustid.fingerprint_file(util.syspath(path))
                   ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.14/site-packages/acoustid.py", line 352, in fingerprint_file
    return _fingerprint_file_audioread(path, maxlength)
  File "/usr/lib/python3.14/site-packages/acoustid.py", line 292, in _fingerprint_file_audioread
    with audioread.audio_open(path) as f:
         ~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/lib/python3.14/site-packages/audioread/__init__.py", line 122, in audio_open
    backends = available_backends()
  File "/usr/lib/python3.14/site-packages/audioread/__init__.py", line 79, in available_backends
    from . import rawread
  File "/usr/lib/python3.14/site-packages/audioread/rawread.py", line 16, in <module>
    import aifc
ModuleNotFoundError: No module named 'aifc'

It seems the aifc module is deprecated and was removed from python, as indicated last year on an audioread issue, but I'm not familiar with the python ecosystem.

I understand this may not be the best place to discuss the arch packaging though, since this is no longer a term_witdh() exception, which is fixed in my case (beet --version used to throw an error, no longer since @grawlinson repackaged it).

Keksoj avatar Jan 12 '26 12:01 Keksoj

If that specific error message is popping up, you have not installed all the related optional dependencies for beets (have a look at the output of pacman -Qi beets)

If you could file an issue on the Arch Linux gitlab, that would be the best place to continue this discussion as it does not relate to this particular issue anymore.

grawlinson avatar Jan 12 '26 18:01 grawlinson

No module named 'aifc' error magically went away today after system update. Not sure which package update fixed it. I was able to import an album that I couldn't yesterday.

ArtemSmaznov avatar Jan 12 '26 22:01 ArtemSmaznov

Same happened to me. I had updated beets to 2.5.1-4 on my machine, but not the other packages. Turns out, @grawlinson displaced dependencies python-standard-sunau and python-standard-aifc from the beets arch package, to the python-audioread, and explained it here Updating all arch packages meant updating python-audioread too, which triggered the installation of -aifc and -sunau packages. I think.

Now beets works on my machine too ! But as mentioned earlier, this more of an arch packaging aspect, and not really beets business.

Keksoj avatar Jan 12 '26 23:01 Keksoj