python-coverage-comment-action icon indicating copy to clipboard operation
python-coverage-comment-action copied to clipboard

Supporting coverage plugins

Open phrfpeixoto opened this issue 1 year ago • 6 comments

Is there any way to support coverage plugins?

My .coveragerc file uses the django_coverage_plugin plugin

[run]
relative_files = True
branch = True
plugins = django_coverage_plugin

And I get this error when running the workflow:

Traceback (most recent call last):
  File "/workdir/coverage_comment/subprocess.py", line 22, in run
    return subprocess.run(
           ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('coverage', 'json', '-o', '-')' returned non-zero exit status 1.

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

Traceback (most recent call last):
  File "/workdir/coverage_comment/main.py", line 44, in main
    exit_code = action(
                ^^^^^^^
  File "/workdir/coverage_comment/main.py", line 96, in action
    return process_pr(
           ^^^^^^^^^^^
  File "/workdir/coverage_comment/main.py", line 127, in process_pr
    _, coverage = coverage_module.get_coverage_info(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workdir/coverage_comment/coverage.py", line 99, in get_coverage_info
    subprocess.run("coverage", "json", "-o", "-", path=coverage_path)
  File "/workdir/coverage_comment/subprocess.py", line 36, in run
    raise SubProcessError("\n".join([exc.stderr, exc.stdout])) from exc
coverage_comment.subprocess.SubProcessError: Traceback (most recent call last):
  File "/usr/local/bin/coverage", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.12/site-packages/coverage/cmdline.py", line 970, in main
    status = CoverageScript().command_line(argv)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/coverage/cmdline.py", line 704, in command_line
    self.coverage.load()
  File "/usr/local/lib/python3.12/site-packages/coverage/control.py", line 501, in load
    self._init()
  File "/usr/local/lib/python3.12/site-packages/coverage/control.py", line [34](https://github.com/myollie/olliemain/actions/runs/9292185517/job/25572489665?pr=10274#step:13:35)3, in _init
    self._plugins = Plugins.load_plugins(self.config.plugins, self.config, self._debug)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/coverage/plugin_support.py", line 55, in load_plugins
    __import__(module)
ModuleNotFoundError: No module named 'django_coverage_plugin'

phrfpeixoto avatar May 29 '24 20:05 phrfpeixoto

it makes sense, as coverage doesn't run in your env but in the action's own dockerized env.

This caused #370 in the past, and the only way forward I'd see would be doing #347 (which is likely quite some work).

Do you have a better idea?

ewjoachim avatar May 30 '24 07:05 ewjoachim

The best option would be to allow custom package installation, through one of the options set on the action. The entrypoint script would check for that, and install them on demand.

phrfpeixoto avatar May 30 '24 14:05 phrfpeixoto

This would probably lead to a slower action start for users of this feature. It's not a problem per se, but let's keep that in mind.

Also, I imagine we'd soon have people requesting the ability to install custom apt packages because they need them for the python packages etc.

I wonder if there could be a way to select a custom base image instead...

ewjoachim avatar Jun 07 '24 07:06 ewjoachim

That's actually a good call. Why don't we update the base image to include the top 10 most used coverage.py plugins?

phrfpeixoto avatar Jun 07 '24 15:06 phrfpeixoto

Do you want to compare the current base image with, say, what it would be if we installed the plugins advertised in the coverage lib? I'm ok going this way this if this doesn't add more than 30% to the size of the image (gotta put the threshold somewhere).

(haha we're featured on that page, I didn't know that 😅)

ewjoachim avatar Jun 07 '24 22:06 ewjoachim

I'll try to have a look on that this weekend.

phrfpeixoto avatar Jun 08 '24 14:06 phrfpeixoto