Fix build against Python 3.12#1922
Open
ogayot wants to merge 2 commits into
Open
Conversation
Ever since Python 3.2, configparser.SafeConfigParser has been deprecated in favor of configparser.ConfigParser. An alias existed for backward compatibility but the alias was dropped from Python 3.12. Let us now use ConfigParser explicitly, and use .read_file() instead of .readfp() which was dropped too. The imp module has also been dropped, but a similar behavior can be achieved using importlib. Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
Python scripts under scripts/ in the source tree do not consistently close files that they open for writing. While some of the scripts use context managers, most of them do not (or do so inconsistently). In previous releases of Python, this apparently was not much of a concern. However, Python 3.12 seems to be much less forgiving when files are not properly closed. When running the test suite, many of the files that are not explicitly closed appear truncated. This leads to various tests failing or hanging. Furthermore, khmer defines the get_file_writer() function, but it cannot be consistently used as a context manager because it sometimes closes the underlying file descriptor ; and sometimes does not depending on the arguments. Fixed by defining a new FileWriter context manager and ensuring that each call to open() / get_file_writer() frees up resources properly. Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
0c7fd0e to
982832b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ever since Python 3.2,
configparser.SafeConfigParserhas been deprecated in favor ofconfigparser.ConfigParser. An alias existed for backward compatibility but the alias was dropped from Python 3.12.The
impmodule was dropped from Python 3.12, butimportlibcan be used as a substitute.Furthermore, Python scripts were not consistently closing the files that they opened for writing. With earlier versions of Python, it was not a big deal. But with Python 3.12, the files appear truncated. The second patch goes through every call to
open(..., mode="w")and ensures that the resource is properly cleaned up after.The change will probably fail to build with Python 2.7.
make clean diff-coveror the CodeCov report that is automaticallygenerated following a successful CI build.)
changes were made?
Only backwards-compatible additions are allowed without a major version
increment. Changing file formats also requires a major version number
increment.
CHANGELOG.md? Seekeepachangelog for more details.