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

MAINT: Python 3.12 support improve #4300

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

tylerjereddy
Copy link
Member

@tylerjereddy tylerjereddy commented Sep 24, 2023

  • Fixes Python 3.12 cannot pickle PickleBufferIOPicklable instances #4299, and allows the testsuite to have 12 failures instead of 56 with Python 3.12.0rc3 for me locally on x86_64 Linux; full suite still passing for Python 3.11.x

  • the main idea is to circumvent more aggressive CPython blocks on serialization by overriding the highest-priority pickling method available, __reduce_ex__, which CPython had locked down, making it such that our old __getstate__ pickling shims were ignored as indicators of pickling safety

  • there is probably a slightly simpler diff that allows this to work, but this took a few hours to draft so feel free to push in simplifications if you're sure you've tested on 3.11.x and 3.12 RC

  • also, I believe this does slightly increase the chance of hanging the testsuite at very high levels of concurrency, but I needed more than 30 processes to repro that, so it may just be a feature of our testsuite in general (it was fine on 12 cores at least, but on 32 or so file locks had issues I think)

[skip cirrus]


📚 Documentation preview 📚: https://mdanalysis--4300.org.readthedocs.build/en/4300/

* Fixes MDAnalysisgh-4299, and allows the testsuite to have 12 failures
instead of 56 with Python `3.12.0rc3` for me locally on x86_64 Linux;
full suite still passing for Python `3.11.x`

* the main idea is to circumvent more aggressive CPython
blocks on serialization by overriding the highest-priority
pickling method available, `__reduce_ex__`, which CPython
had locked down, making it such that our old `__getstate__`
pickling shims were ignored as indicators of pickling safety

* there is probably a slightly simpler diff that allows
this to work, but this took a few hours to draft so feel
free to push in simplifications if you're sure you've tested
on 3.11.x and 3.12 RC

[skip cirrus]
@pep8speaks
Copy link

Hello @tylerjereddy! Thanks for opening this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 113:5: E303 too many blank lines (2)
Line 162:5: E303 too many blank lines (2)

@github-actions
Copy link

Linter Bot Results:

Hi @tylerjereddy! Thanks for making this PR. We linted your code and found the following:

Some issues were found with the formatting of your code.

Code Location Outcome
main package ⚠️ Possible failure
testsuite ✅ Passed

Please have a look at the darker-main-code and darker-test-code steps here for more details: https://github.com/MDAnalysis/mdanalysis/actions/runs/6292350915/job/17081677332


Please note: The black linter is purely informational, you can safely ignore these outcomes if there are no flake8 failures!

@IAlibay
Copy link
Member

IAlibay commented Sep 24, 2023

Thanks @tylerjereddy - should we temporarily merge my Py3.12 PR knowing it fails and then just turn off the cron shim to test here?

@tylerjereddy
Copy link
Member Author

We could I suppose. Do we even need a cron guard? The final CPython 3.12 release is about a week or two away at most right, so maybe not too long to ignore a failing entry while we try to fix it up? I guess we may not plan support quite that fast though, in which case cron could be fine yeah.

@codecov
Copy link

codecov bot commented Sep 24, 2023

Codecov Report

Patch coverage: 74.28% and project coverage change: -0.05% ⚠️

Comparison is base (427f1a7) 93.40% compared to head (fd7df3c) 93.36%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4300      +/-   ##
===========================================
- Coverage    93.40%   93.36%   -0.05%     
===========================================
  Files          170      184      +14     
  Lines        22257    23374    +1117     
  Branches      4071     4071              
===========================================
+ Hits         20790    21823    +1033     
- Misses         951     1035      +84     
  Partials       516      516              
Files Changed Coverage Δ
package/MDAnalysis/lib/picklable_file_io.py 88.00% <74.28%> (-10.91%) ⬇️

... and 14 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

tylerjereddy added a commit to tylerjereddy/mdanalysis that referenced this pull request Oct 2, 2023
* force the use of a relative path for `mkdtemp` in our source code
because, from the Python `3.12` release notes:

> `tempfile.mkdtemp() now always returns an absolute path, even if the
argument provided to the dir parameter is a relative path.`

* with this patch, the full testsuite now passes on Python `3.12.0`
(which is now out) when combined with MDAnalysisgh-4301 and MDAnalysisgh-4300 (though
see my cautions about thread safety/concurrency for the latter)

* this fixes the 1 remaining failure with 3.12:
`MDAnalysisTests/analysis/test_hole2.py::TestCheckAndFixLongFilename::test_symlink_dir`

[skip cirrus]
IAlibay pushed a commit that referenced this pull request Oct 12, 2023
* force the use of a relative path for `mkdtemp` in our source code
because, from the Python `3.12` release notes:

> `tempfile.mkdtemp() now always returns an absolute path, even if the
argument provided to the dir parameter is a relative path.`

* with this patch, the full testsuite now passes on Python `3.12.0`
(which is now out) when combined with gh-4301 and gh-4300 (though
see my cautions about thread safety/concurrency for the latter)

* this fixes the 1 remaining failure with 3.12:
`MDAnalysisTests/analysis/test_hole2.py::TestCheckAndFixLongFilename::test_symlink_dir`

[skip cirrus]
@IAlibay IAlibay merged commit 8c41dc8 into MDAnalysis:develop Oct 12, 2023
19 of 23 checks passed
@tylerjereddy tylerjereddy deleted the treddy_issue_4299 branch October 15, 2023 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python 3.12 cannot pickle PickleBufferIOPicklable instances
4 participants