Git Product home page Git Product logo

action-mypy's Introduction

action-mypy

Test reviewdog depup release GitHub release (latest SemVer) action-bumpr supported

github-pr-review demo github-pr-check demo

This is a action-mypy repository for reviewdog action with release automation.

Limitation: mypy report multiline error, but now, multiline error cannot be handled in one unit. It handles the error line by line. see Issue.

Notice: This action is composition action.

You accept below one:

  • Your workflow manually setup to run pip install -r requirements.txt or other setup method.
  • This action automatic run pip install mypy.

Input

inputs:
  github_token:
    description: 'GITHUB_TOKEN'
    required: false
    default: '${{ github.token }}'
  workdir:
    description: |
      Working directory of where to run mypy command.
      Relative to the root directory.
    required: false
    default: '.'
  target:
    description: |
      Target files and/or directories of mypy command.
      Enumerate in a space-separated list.
      Relative to the working directory.
    required: false
    default: '.'
  ### Flags for setup/execute ###
  execute_command:
    description: |
      mypy execute command.
      Normally it is "mypy", but for example "poetry run mypy"
      if you want to run at Poetry without activating the virtual environment.
    required: false
    default: 'mypy'
  setup_command:
    description: |
      mypy setup command.
      Runs when "setup_method" is "install" or required by "adaptive".
      If you want to fix the version of mypy, set the value as in the following example.
      "pip install mypy==1.6.0"
    required: false
    default: 'pip install mypy'
  setup_method:
    description: |
      mypy setup method. Select from below.
      "nothing" - no setup process.
      This option expects the user to prepare the environment
      (ex. previous workflow step executed "pip install -r requirements.txt").
      If you do not want immediately package installation (e.g., in a poetry environment), must be this.
      "adaptive" - Check "execute_command" with "--version" is executable.
      If it can be executed, do the same as "nothing", otherwise do the same as "install".
      "install" - execute "setup_command".

      Incorrect values behave as "adaptive".
    required: false
    default: 'nothing'
  install_types:
    description: |
      Pre-run mypy and check for missing stubs.
      Then perform stub installation.
      (ex. ${execute_command} --install-types)
    required: false
    default: 'true'
  ### Flags for reviewdog ###
  level:
    description: 'Report level for reviewdog [info,warning,error]'
    required: false
    default: 'error'
  reporter:
    description: 'Reporter of reviewdog command [github-pr-check,github-pr-review].'
    required: false
    default: 'github-pr-check'
  filter_mode:
    description: |
      Filtering mode for the reviewdog command [added,diff_context,file,nofilter].
      Default is added.
    required: false
    default: 'added'
  fail_on_error:
    description: |
      Exit code for reviewdog when errors are found [true,false]
      Default is `false`.
    required: false
    default: 'false'
  reviewdog_flags:
    description: 'Additional reviewdog flags'
    required: false
    default: ''
  ### Flags for mypy ###
  mypy_flags:
    description: 'mypy options (default: <none>)'
    required: false
    default: ''
  tool_name:
    description: 'Tool name to use for reviewdog reporter'
    default: 'mypy'
  ignore_note:
    description: |
      Ignore note entry.
      mypy report some error with optional note entry.
      This option is workaround.
    default: 'true'

Input note

mypy_flags is used for workflow setting. (eg '--strict --strict-equality').

But when this flag as set, ignore and do not affect setup.cfg or other mypy's settings file parameters.

Use this flag when you want to check a workflow that is different from the project settings.

Usage

name: reviewdog
on: [pull_request]
jobs:
  mypy:
    name: runner / mypy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: tsuyoshicho/action-mypy@v4
        with:
          github_token: ${{ secrets.github_token }}
          # Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
          reporter: github-pr-review
          # Change reporter level if you need.
          # GitHub Status Check won't become failure with warning.
          level: warning
          # Change the current directory to run mypy command.
          # mypy command reads setup.cfg or other settings file in this path.
          workdir: src

Using with Poetry

If you use mypy with Poetry, you can use it with the following settings (poetry shell do not work in GitHub workflow, see issue 66).

Example setting:

name: reviewdog
on: [pull_request]
jobs:
  mypy:
    name: runner / mypy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: tsuyoshicho/action-mypy@v4
        with:
          github_token: ${{ secrets.github_token }}
          reporter: github-pr-review
          level: warning
          workdir: src
          execute_command: 'poetry run mypy'

Debug output

You can set the "-tee" flag in the reviewdog_flags to log the process.

Development

Release

You can bump version on merging Pull Requests with specific labels (bump:major,bump:minor,bump:patch). Pushing tag manually by yourself also work.

This action updates major/minor release tags on a tag push. e.g. Update v1 and v1.2 tag when released v1.2.3. ref: https://help.github.com/en/articles/about-actions#versioning-your-action

Lint - reviewdog integration

This reviewdog action mypy itself is integrated with reviewdog to run lints which is useful for Docker container based actions.

reviewdog integration

Dependencies Update Automation

This repository uses haya14busa/action-depup to update reviewdog version.

reviewdog depup demo

action-mypy's People

Contributors

bernhardkaindl avatar dependabot[bot] avatar github-actions[bot] avatar milly avatar renovate-bot avatar renovate[bot] avatar sjust-seerbio avatar tsuyoshicho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

action-mypy's Issues

"Running mypy with reviewdog ๐Ÿถ ..." does not comment and shows no error, despite errors.

I run into the same issue as the 2nd issue reported in #111:

Second, the step "Running mypy with reviewdog ๐Ÿถ ..." shows no output and passes without errors, even when there are typing errors in the project:

I enabled mypy --verbose and see that mypy is issuing two warnings for a file (it mentions two times that it has a warning about a place in the file), in the step "Running mypy with reviewdog ๐Ÿถ ...", but the action hides the actual errors and does not add a comment to the PR.

Multiple reviews generated for multiline mypy error

I'm using action with following step configuration:

    - name: Mypy review
      uses: tsuyoshicho/action-mypy@v3
      with:
        reporter: github-pr-review
        level: warning
        fail_on_error: true

As an example, following is a multi-line mypy error when overriding superclass property in an incompatible way:

/home/runner/.../file.pyi:28:6: error: Signature of "error_log" incompatible with supertype "_Validator"
/home/runner/.../file.pyi:28:6: note:      Superclass:
/home/runner/.../file.pyi:28:6: note:          def error_log(self) -> _ErrorLog
/home/runner/.../file.pyi:28:6: note:      Subclass:
/home/runner/.../file.pyi:28:6: note:          @overload
/home/runner/.../file.pyi:28:6: note:          def error_log(self) -> int
/home/runner/.../file.pyi:29:5: error: Return type "int" of "error_log" incompatible with return type "_ErrorLog" in supertype "_Validator"

The error came from a single diff hunk, so I was expecting a single reviewdog action. Instead, it generated 7 independent reviews on the same pull request, each containing one line, and all of them are attached to the same diff.

Type checking with third party packages

I have a project with multiple dependencies from PyPI. How can I use this such that mypy will find my dependencies? Installing into the virtualenv provided by actions/setup-python@v2 doesn't help.

Running mypy with reviewdog has no output

I am trying to use your action in another project, but I have problems making it work:

  • First, if an error occurs during the action setup (installation, install_types, etc), the action happily returns an ok status and does nothing.
  • Second, the step "Running mypy with reviewdog ๐Ÿถ ..." shows no output and passes without errors, even when there are typing errors in the project:

Suggestion: Allow user to choose mypy version manually

Sometimes people may not want to use the latest mypy for testing, because mypy can change its type checking output format (for example, Tuple[...] is changed to tuple[...] in 1.4, and Union[a, b] becomes a | b) . People who run automatic test suite would want to pin to a very specific mypy version.

Indeed, it is possible to pin to a specific action-mypy commit in GitHub workflow instead, but that also means people are unable to use any new features in latest action-mypy.

To be concise, I mean something like:

- name: workflow name
  uses: tsuyoshicho/action-mypy@v3
  with:
    mypy_version: '1.2.0'

Feature request: Multiple targets for mypy

Hi @tsuyoshicho, first of all, thank you for this very useful action!

I had a little problem using it in my GitHub workflow because it only supports a single target at the moment. I tried putting multiple files separated by white space in the target input of the action (like file1 file2), but I saw that this line quotes the target and therefore mypy looks for a single file (or directory) with the name file1 file2, i.e., containing the white space.

The context of why I'd like to do this is that I identify the changed or added files in a pull request using the GitHub action dorny/paths-filter. It supports outputting all changed files in a shell-like list, i.e., with white space as delimiter. I'd like mypy to only lint the changed/added files and not the whole repository because linting issues that weren't introduced by the current PR shouldn't block it from being merged.
As a workaround, I tried setting target to "" and putting the list of files in the mypy flags input. Unfortunately, that doesn't work either because then the default value of "." is inserted in the same line I linked above.

Do you think your action could support this use case?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/depup.yml
  • actions/checkout v4
  • haya14busa/action-depup v1
  • peter-evans/create-pull-request v6
.github/workflows/release-check.yml
  • actions/checkout v4
  • haya14busa/action-bumpr v1
.github/workflows/release.yml
  • actions/checkout v4
  • haya14busa/action-bumpr v1
  • haya14busa/action-update-semver v1
  • haya14busa/action-cond v1
  • softprops/action-gh-release v2
.github/workflows/reviewdog.yml
  • actions/checkout v4
  • haya14busa/action-cond v1
  • reviewdog/action-shellcheck v1
  • actions/checkout v4
  • reviewdog/action-misspell v1
  • actions/checkout v4
  • reviewdog/action-alex v1
.github/workflows/test.yml
  • actions/checkout v4
  • actions/setup-python v5
  • actions/checkout v4
  • actions/setup-python v5
  • actions/checkout v4
  • actions/setup-python v5
  • actions/checkout v4
  • actions/setup-python v5
  • actions/checkout v4
  • actions/setup-python v5
.github/workflows/update_semver.yml
  • actions/checkout v4
  • haya14busa/action-update-semver v1
pip_requirements
requirements.txt
  • mypy ==1.10.0
testdata/requirements.txt
  • build ==1.2.1
  • certifi ==2024.2.2
  • charset-normalizer ==3.3.2
  • click ==8.1.7
  • colorama ==0.4.6
  • idna ==3.7
  • packaging ==24.0
  • pip-tools ==7.4.1
  • pyproject-hooks ==1.1.0
  • requests ==2.32.2
  • urllib3 ==2.2.1
  • wheel ==0.43.0
testerror/requirements.txt
  • build ==1.2.1
  • certifi ==2024.2.2
  • charset-normalizer ==3.3.2
  • click ==8.1.7
  • idna ==3.7
  • packaging ==24.0
  • pip-tools ==7.4.1
  • pyproject-hooks ==1.1.0
  • requests ==2.32.2
  • urllib3 ==2.2.1
  • wheel ==0.43.0
pyenv
.python-version
  • python 3.12.3

  • Check this box to trigger a request for Renovate to run again on this repository

Deps are not installed

Hi, I try to use the actual action to perform the mypy one, but it didn't works because the actual setup does not install the packages deps, are least no with a pure pyproject.toml, which means there is no requirements.txt.

name: reviewdog
on: [pull_request]
jobs:
  mypy:
    name: runner / mypy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: tsuyoshicho/action-mypy@v3
        with:
          github_token: ${{ secrets.github_token }}
          # Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
          reporter: github-pr-review
          # Change reporter level if you need.
          # GitHub Status Check won't become failure with warning.
          level: warning
          # Change the current directory to run mypy command.
          # mypy command reads setup.cfg or other settings file in this path.
          workdir: src
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "test"
version = "01.23.01.2024"
dependencies = [
  "pandas",
  "pandas-stubs",
  "pyarrow", #https://github.com/pandas-dev/pandas/issues/54466
  "sqlalchemy",
  "scipy",
  "numpy",
  "matplotlib",
  "mypy"
]
description = "spam spam!"
readme = "README.md"

I got similar to this ones:

Library stubs not installed for "pandas" [import-untyped]

Thx!

Some mypy errors are ignored

I have a mypy error that looks like this:

importer/flows/helpers/__init__.py: error: Duplicate module named "helpers" (also at "<snip>")

Currently this gets ignored because it doesn't have the line and column numbers that -efm="%f:%l:%c: %t%*[^:]: %m" expects.

Tentatively winnielabs@42d4817 fixes this, but I haven't really tested this thoroughly to see what other effects that has.

I'm suspecting that if mypy gets json output (as per #38), then that would fix this as well. But the upstream PR is a year old now and there's no decision-making from the core mypy team about what would be needed for it to get merged, so I'm not hopeful about that happening soon.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)

Next major release

  • Change default option value

    • setup_method: nothing
      • install support specific version
    • ignore_note: enable
  • Change internal function

    • automatic install stub
      need preflight running(generate cache) and run as follow command
      mypy --install-types --non-interactive
      
      default on option

one >53 errrors to report, reviewdog aborts GitHubActionLogWriter: "reported too many annotation"

TODO / Remaining bug:

When more than 53 errors are reported by mypy and are not filtered, reviewdog gives up and aborts with the message:

GitHubActionLogWriter: "reported too many annotation"

The error is buried in the middle of the long output:

  /home/runner/work/xen-api/xen-api/scripts/plugins/extauth-hook-AD.py:70:19: error: If x = b'abc' then f"{x}" or "{}".format(x) produces "b'abc'", not "abc". If this is desired behavior, use f"{x!r}" or "{!r}".format(x). Otherwise, decode the bytes  [str-bytes-safe]
  Warning: [mypy] reported by reviewdog ๐Ÿถ
  In function "fresh_name":
  
  Raw Output:
  /home/runner/work/xen-api/xen-api/scripts/static-vdis: note: In function "fresh_name":
  reviewdog: GitHubActionLogWriter: reported too many annotation (N=53)
  + reviewdog_exit_val=1
  + echo ::endgroup::
  + [[ false == \t\r\u\e ]]
  Error: [mypy] reported by reviewdog ๐Ÿถ
  Incompatible types in assignment (expression has type "str", variable has type "int")  [assignment]
  
  Raw Output:

I know the current GitHub limits, they are also printed in the log:

   Error: reviewdog: Too many results (annotations) in diff.
  You may miss some annotations due to GitHub limitation for annotation created by logging command.
  Please check GitHub Actions log console to see all results.
  
  Limitation:
  - 10 warning annotations and 10 error annotations per step
  - 50 annotations per job (sum of annotations from all the steps)
  - 50 annotations per run (separate from the job annotations, these annotations aren't created by users)

However, reviewdog should do it's best to report 10 error annotations and 10 warning annotations (and it should also support 10 notice annotations, btw) and if > 10 annotations, the 10th annotation of each kind should be a message that there are more than 10 annotations, which GitHub does not support.

The same may also apply to review comments, but I am not aware of such limit. However, to prevent a DoS from reviewdog, it is likely best if reviewdog replaces the last comment it would be able to add with a "Giving up due to GitHub limit".

In case of too many errors, it may also be nice to merge several erros of the same kind into one error and add "more of the same are omitted due to GitHub annotation limits of 10 annotations per type and step".

Another nice feature would be to mark less important errors not as errors but as warings and notices, so in total 30 annotations could be issued per step.

The biggest problem is that the action-mypy does not fail CI in this case, so the error goes unnoticed:

https://github.com/xenserver-next/xen-api/actions/runs/7706543512/job/21002295649

Running via Poetry doesn't seem to work

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)

Custom MyPy binary

When installing dependencies with Poetry, the mypy ... command is not available and instead one should use poetry run mypy ....

It would be nice to be able to add an option for the binary used for the mypy invocation (and potentially an option to skip installing mypy without checking if it is installed).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.