leinardi / mypy-pycharm

A plugin providing both real-time and on-demand scanning of Python files with Mypy from within PyCharm/IDEA.
Apache License 2.0
187 stars 30 forks source link

Use mypy within docker #28

Open Euphorbium opened 5 years ago

Euphorbium commented 5 years ago

Step 1: Are you in the right place?

Step 2: Describe your environment

Step 3: Describe the problem:

Steps to reproduce:

  1. When using project interpreter in docker compose, it is impossible to specify mypy executable path, and I am constantly getting popups saying that mypy is missing. I have set up it to use my host system mypy, and even installed it in the docker interpreter, but the pop ups continue.

Expected Results:

it should be possible to use mypy within docker.

10:55   Packages installed successfully: Installed packages: 'mypy'

10:58   Mypy Plugin (Mypy missing)
            The project interpreter is missing Mypy, which is needed to properly check the imports.
            Install Mypy
hmoravec commented 5 years ago

I also agree this is an important feature as a typical user of Mypy is a professional developer who also uses Docker/Vagrant for development environment. It would be nice if it would be at least possible to use Mypy executable from environment that is different than the project environment.

There is also the same problem for the Pylint plugin: https://github.com/leinardi/pylint-pycharm/issues/36

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had activity in the last 60 days.

aguestuser commented 4 years ago

+1. our team would love to see this issue re-opened and worked on. we are dying to use this plugin, but the lack of support for dockerized virtualenvs is an absolute deal-breaker.

except for this one defect, we would be using your plugin instead of the dropbox plugin, which we think is strictly worse, but which can be configured to be compatible with our dockerized virutalenvs. so we're using the other plugin, even though we like it a LOT LESS than yours!

do maintainers have any plans to pick this up? would you accept contributions to help move it forward?

gaqzi commented 4 years ago

I got this working by making a little naïve wrapper script that invokes any command in a container for me (based on the name of the calling command).

Given the following script named .execute-in-docker.sh:

#!/bin/bash

: ${DEV_CONTAINER:=code_1}
SCRIPT_NAME=$(basename $0)

# Certain commands from IntelliJ issues absolute paths from the
# local filesystem, but the container has the root of the source
# tree set as the working directory. So just remove all the local
# paths and it'll all work out
PROJECT_ROOT_DIRECTORY="$(git rev-parse --show-toplevel)/"
function relativize() {
    echo $@ | sed "s#${PROJECT_ROOT_DIRECTORY}##"
}

function relativize-all-the-arguments() {
    local args=""

    for i in $@; do
        i=$(relativize "$i")
        args="${args} ${i}"
    done

    echo ${args}
}

exec /usr/local/bin/docker exec ${DEV_CONTAINER} \
    /usr/bin/env ${SCRIPT_NAME} $(relativize-all-the-arguments $@)

Then I went ahead and created symlinks for all the commands I want to run in my container:

$ cd bin
$ ln -s .execute-in-docker.sh mypy
$ ln -s .execute-in-docker.sh isort
$ cd ../
$ bin/mypy src/my_funky_tool.py
src/my_funky_tool.py:38:5: error: No return value expected
src/my_funky_tool.py:40:1: error: Argument 1 to "hello" has incompatible type "int"; expected "str"
$ bin/isort src/my_funky_tool.py

In case it helps someone else that is looking to make this plugin work with Docker :)

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had activity in the last 60 days.

rommguy commented 4 years ago

@leinardi Thank you very much for this plugin, it is super helpful Perhaps it is possible to add interpreter settings to the plugin settings? This would solve the problem of running in a docker, since I want PyCharm to use the remote interpreter but the plugin to use the local interpreter I'd be happy to submit a PR if you can give me some guidance

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had activity in the last 60 days.

jaredtkatz commented 4 years ago

Any progress here? Kinda frustrating :/