Skip to content

support python 3.14#575

Open
Joerg Henrichs (hiker) wants to merge 5 commits into
mainfrom
510_support_python_314
Open

support python 3.14#575
Joerg Henrichs (hiker) wants to merge 5 commits into
mainfrom
510_support_python_314

Conversation

@hiker

Copy link
Copy Markdown
Collaborator

Trying to fix python 3.14, see #510 for details.

@MatthewHambley Matthew Hambley (MatthewHambley) changed the title 510 support python 314 support python 314 Jun 19, 2026
@MatthewHambley Matthew Hambley (MatthewHambley) changed the title support python 314 support python 3.14 Jun 19, 2026
@hiker Joerg Henrichs (hiker) added the Ready for review Indicating that a PR is ready to be reviewed. label Jun 19, 2026
@hiker

Copy link
Copy Markdown
Collaborator Author

Sam Clarke-Green (@t00sa) , I don't fully understand the cui/aeguments.py file, so please check that my change there was ok.

I also fixed a small test bug (some tests would fail if you have a working mpif90 in your path, see conftest.py)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I am not in favour of code under test being different from deployed code but I think that is a problem we can postpone to later.

Comment thread tests/conftest.py
Comment on lines +198 to +202
# Remove all compiler and linker, since they might exist on the system
# running these tests, which can break tests.
for cat in [Category.C_COMPILER, Category.FORTRAN_COMPILER,
Category.LINKER]:
tool_repository[cat] = []

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this change relate to Python v3.14?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I've written:

I also fixed a small test bug (some tests would fail if you have a working mpif90 in your path, see conftest.py)

Not directly related, except my python 3.14 environment happened to have mpif90 and caused test failures.

@hiker

Joerg Henrichs (hiker) commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator Author

In general I am not in favour of code under test being different from deployed code but I think that is a problem we can postpone to later.

I totally agree with that, I only did it because of the existing comment acknowledging the line, and so I thought it would be acceptable for now (the commit that introduced the change only mentions something about making it aware of ifort or so. nothing really helpful as far as I could see).

I actually did try a few other things, but no real success. The problem seems to be that we have two level of child processes (multiprocessing spawn for the steps, then we run compiler etc), and Copilot told me (and admittedly I didn't check, but this is pretty much what I see):

pytest‑subprocess has never supported mocking subprocesses inside child processes.
Python 3.14’s stricter import/pickle rules make this limitation more visible.

E.g. we fake:

        fake_process.register(['sfc', '--version'], stdout='1.2.3')
        fake_process.register(['sfc', fake_process.any()])

and then call compile_pass, which does run_mp and then checks if the compiler is available (first fake process), and then the actual compilation. So even if we set the compiler to be available (avoiding the first fake process), we are still stuck with the second one :(

More googling might have given me a different approach: I tried before to switch multiprocessing back to fork, but that somehow didn't work (I believe the complication is to find where multiprocessing is imported first). But what seems to work:
in steps/__init__.py (run_mp):

    if config.multiprocessing and not no_multiprocessing:
        ctx = multiprocessing.get_context("fork") 
        with ctx.Pool(config.n_procs) as p:
            results = p.map(func, items)
    else:
        results = [func(f) for f in items]

    return results

I.e. explicitly switching from the new forkserver back to fork. I don't know enough about the details of this change to know if this is acceptable, but it feels like a better solution - at least then tests and 'real' code are consistent. But using fork might have disadvantages (i.e. there must be a reason why the python default multiprocessing was switched).

Let me know what you prefer me to do (and if I should leave the line in the build config in that disables subprocessing in case of debugging)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Indicating that a PR is ready to be reviewed.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants