Page MenuHomePhabricator

Toolforge Build Service does not support .python-version
Closed, ResolvedPublic

Description

Help:Toolforge/Building container images (permalink) advises that one can use e.g. “python 3.12, see Specifying a Python runtime”. The linked Heroku documentation advises users to create a .python-version file that should control the Python version. However, the build service does not appear to take this file into account whatsoever. Only specifying a runtime.txt file, as documented in older Heroku documentation, appears to work – I assume we’re using an older version of whatever the relevant component is (pack?).

Presumably for the same reason, Python 3.13 doesn’t appear to be available – trying to select python-3.13.0 in runtime.txt results in:

[step-build] 2024-12-10T18:08:21.777668762Z [Error: Requested Python version is not available]
[step-build] 2024-12-10T18:08:21.777686324Z The requested Python version (3.13.0) is not available for this stack (heroku-22).
[step-build] 2024-12-10T18:08:21.777701510Z 
[step-build] 2024-12-10T18:08:21.777711416Z Please update the version in 'runtime.txt' to a supported Python version, or else
[step-build] 2024-12-10T18:08:21.777721493Z remove the file to instead use the default version (currently Python 3.12.1).
[step-build] 2024-12-10T18:08:21.777729950Z 
[step-build] 2024-12-10T18:08:21.777739389Z For a list of the supported Python versions, see:
[step-build] 2024-12-10T18:08:21.777749236Z https://devcenter.heroku.com/articles/python-support#supported-runtimes
[step-build] 2024-12-10T18:08:21.777758243Z 
[step-build] 2024-12-10T18:08:21.779447421Z ERROR: failed to build: exit status 1

Related Objects

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

@LucasWerkmeister can you try now with toolforge build start --use-latest-versions <url>? That will be using the new runner (ubuntu24) and the newer buildpacks too (python, etc.)

Mentioned in SAL (#wikimedia-cloud) [2025-05-12T17:42:30Z] <wmbot~lucaswerkmeister@tools-bastion-13> deployed d949e8ee4a (Python 3.13 using --use-latest-versions via T381923)

Seems to be working \o/

I feel like the first build took longer to start showing output than usual, but that might just be random noise or even bad memory. (I wasn’t paying attention during the second build.)

Nice :), it might be because it's the first time it uses the builder/runner/etc. images, so it has to pull them anew.

Feel free to close the task once you tested it a bit.

I don’t think I have any more Python build service tools at the moment, so I’ll just go ahead and close this ^^

Seems to be working \o/

I spoke too soon :( I just noticed that the tool has been partially broken since this deployment, with errors like these:

tools.quickcategories@tools-bastion-13:~$ kubectl logs background-runner-6d4b45f48-jj6bv
Traceback (most recent call last):
  File "/layers/heroku_python/python/lib/python3.13/getpass.py", line 173, in getuser
    return pwd.getpwuid(os.getuid())[0]
           ~~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'getpwuid(): uid not found: 53976'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/workspace/./background_runner.py", line 15, in <module>
    from database import DatabaseBatchStore, DatabasePreferenceStore
  File "/workspace/database.py", line 10, in <module>
    import pymysql
  File "/layers/heroku_python/venv/lib/python3.13/site-packages/pymysql/__init__.py", line 79, in <module>
    from . import connections  # noqa: E402
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/layers/heroku_python/venv/lib/python3.13/site-packages/pymysql/connections.py", line 41, in <module>
    DEFAULT_USER = getpass.getuser()
  File "/layers/heroku_python/python/lib/python3.13/getpass.py", line 175, in getuser
    raise OSError('No username set in the environment') from e
OSError: No username set in the environment

The webservice is still alive because Kubernetes dutifully kept the old pod up – yay for health checks! – but that also means that nobody reported the breakage to me.

tools.quickcategories@tools-bastion-13:~$ kubectl get pods                                                                                                                                                                                    
NAME                                READY   STATUS             RESTARTS           AGE                                                                                                                                                         
background-runner-6d4b45f48-52thd   0/1     CrashLoopBackOff   2861 (3m16s ago)   10d                                                                                                                                                         
quickcategories-69958b9845-tn85m    0/1     CrashLoopBackOff   3045 (73s ago)     10d                                                                                                                                                         
quickcategories-9dc6df5d9-qrmct     1/1     Running            0                  45d                                                                                                                                                         

(Since then, I tried to deploy another update, so the age and restarts of the broken pods are now much lower.)

I assume this error is due to --use-latest-versions, though I haven’t yet tried to revert that.

Mentioned in SAL (#wikimedia-cloud) [2025-05-22T21:52:35Z] <wmbot~lucaswerkmeister@tools-bastion-13> deployed 74cd3dee83 (install PyMySQL from Git for Python 3.13 compatibility; CC T381923)

False alarm – turns out this error was caused by an unfortunate confluence of several factors:

  • Build service containers have always had SSSD uninstalled / unconfigured, so the user name was never available, but this was previously not a problem
  • Python 3.13 changed getpass.getuser() to raise an OSError rather than a KeyError if no user name is defined in the environment
  • PyMySQL previously caught ImportError and KeyError when calling getpass.getuser(), but not OSError, so this now crashed the tool
  • PyMySQL merged a fix for this, but has yet to publish it in a new release, so even upgrading all dependencies (as I did earlier today) didn’t fix the error

So for now, I’m installing PyMySQL from Git to include the fix and make the tool work under Python 3.13 again.