SimonKagstrom / kcov

Code coverage tool for compiled programs, Python and Bash which uses debugging information to collect and report data without special compilation options
http://simonkagstrom.github.io/kcov/
GNU General Public License v2.0
709 stars 109 forks source link

python-helper: update deprecated code #417

Closed perillo closed 5 months ago

perillo commented 5 months ago

Currently python-helper.py imports the imp module, but this module has been deprecated since version 3.4 and removed in version 3.12.

Refactorize the code to handle Python versioning by moving the code at the start of the file.

Use one block for python>=3.0, declaring the report_trace_real function. Use a second block for python>=3.5, declaring the new_module function.

Add tests for python2 support.

Fix incorrect code using comparison to None instead of cond is None. Reported by ruff check.

Format the code with ruff format, with line-length = 100.

perillo commented 5 months ago

Before this change, when building kcov from old master, I got a lot of errors, but now this is fixed. I'm not sure what was causing these failures, probably the deprecation warning for the imp module, when using python3.11.

The only tests that have problems are:

SimonKagstrom commented 5 months ago

The system mode test can be removed. System mode has never worked satisfactory anyway, so can be disabled until some major future refactoring.

Thanks a lot for the PR!