tsuyoshicho/action-mypy

Running via Poetry doesn't seem to work

borice opened this issue · 10 comments

Hello,

Per the README, I'm using

      - name: Run mypy
        uses: tsuyoshicho/action-mypy@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          reporter: github-pr-review
          # level: warning
          execute_command: 'poetry run mypy'

(I also tried setting the execute_command to poetry run mypy . -- which is actually what I'd use to run it at my shell)

This resulted in the following run:

image

which seems to report that all is OK, but in reality, running the command at my shell in the project folder on that same ref gives of around 6 errors.

$ poetry run mypy . 
htrc/ef/api.py:62: error: Incompatible types in assignment (expression has type "Optional[Dict[Any, Any]]", variable has type "Dict[Any, Any]")  [assignment]
htrc/ef/api.py:77: error: Item "None" of "Optional[Dict[Any, Any]]" has no attribute "__iter__" (not iterable)  [union-attr]
htrc/ef/api.py:87: error: Item "None" of "Optional[Dict[Any, Any]]" has no attribute "__iter__" (not iterable)  [union-attr]
htrc/ef/api.py:108: error: Item "None" of "Optional[Dict[Any, Any]]" has no attribute "__iter__" (not iterable)  [union-attr]
htrc/torchlite/worksets.py:29: error: Incompatible types in assignment (expression has type "Optional[Workset]", variable has type "Workset")  [assignment]
htrc/torchlite/worksets.py:42: error: Incompatible return value type (got "Optional[List[Volume]]", expected "List[Volume]")  [return-value]
Found 6 errors in 2 files (checked 16 source files)

I'm late, I'll check it out

hi @borice san,

Although I considered it, it should have been executed: poetry run mypy.

As a factor that can be considered, the filter mode setting may not match the CI you wanted to check.

By default added, which only reacts to code added in PRs.
If there is no problem in the added part of the CI, it will not be output.

I would like you to try a different mode or try checking with a PR that has an error in the difference.

see https://github.com/reviewdog/reviewdog#filter-mode

Since there is no response, I will close it for now.

If the output is still not correct after creating a difference in PR or changing the detection mode, please create an issue again.
If possible, have a test(reporuduce) repository/PR that you can check.

rtizzy commented

@tsuyoshicho

I'm seeing a similar issue executing this via a PR with poetry.

I made a change in the PR that caused things to break (intentionally)

This will output review comments.

      - uses: tsuyoshicho/action-mypy@v3
        with:
          reporter: github-pr-review
          level: error
          setup_method: nothing
          fail_on_error: true
          filter_mode: nofilter
          workdir: src
          execute_command: poetry run mypy

This WILL NOT output review comments (or even output info via CLI) but does fail

      - uses: tsuyoshicho/action-mypy@v3
        with:
          reporter: github-pr-review
          level: error
          setup_method: nothing
          fail_on_error: true
          filter_mode: added
          workdir: src
          execute_command: poetry run mypy

Is that expected behavior?

rtizzy commented

Note that it also seems to work with filter_mode: file.

rtizzy commented

Although with either filter_mode: file or filter_mode: nofilter both seem to output using the check API and not a comment :(

image

@rtizzy
Please see reviewdog option
https://github.com/reviewdog/reviewdog#filter-mode

filter_mode is PR's diff result check method for reviewdog.

Defualt add is check only added code in PR.
file is changed files in PR.
nofilter is all check mode.

Please check the changes in PR.

rtizzy commented

@tsuyoshicho

EDIT: See next comment, this may be some unexpected mypy behavior

Yep, I want to confirm that I checked that.

To my understanding here is how pr-review works with filter_mode: added

  1. You have a branch with change
  2. You open a PR.
  3. Any changes to code in that PR will be filtered out and shown in the PR Review after tests run
  4. You continue to make changes to the branch with an open PR
  5. CI/Reviewdog continues to run and updates the PR.

If that is correct then I can say at least in my case, something does not seem to be working properly.

rtizzy commented

For posterity:

At least in my case this was caused by some confusing behavior with how mypy grabs configs.

From what I can tell, mypy does not move up the directory tree to search for config files.

I configure with a pyproject.toml(Supported by mypy) stored in the root of the repository with the code held in src/ which currently only enables strict mode.

This worked properly in my case

      - uses: tsuyoshicho/action-mypy@v3
        with:
          reporter: github-pr-review
          level: error
          setup_method: nothing
          fail_on_error: true
          filter_mode: added
          workdir: src
# Note addition of config file
          execute_command: poetry run mypy --config-file ../pyproject.toml

Thanks for the help and for creating this package @tsuyoshicho

Hi, @rtizzy .
I see, there was such a problem.
understood.

In that case, instead of specifying "src" as workdir (current directory), how about specifying "src" as target (target files/directories) and running from the top directory (workdir is ".")?

name: reviewdog
on: [pull_request]
jobs:
  mypy:
    runs-on: ubuntu-latest
    steps:
      - uses: tsuyoshicho/action-mypy@v3
        with:
          github_token: ${{ secrets.github_token }}
          # do not define workdir (default .)
          # snip
          target: src

I'm glad the problem was resolved.

The sample may not be good, so I will try to improve it.