-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any way to pass in ENV variables? #25
Comments
Hey @halfnibble, for some reason I missed this issue, sorry. Does this problem happen also when you run mypy outside of VSCode? If yes, then this issue is not related to mypy-vscode, but to mypy itself. If no, then can you please include the relevant portion of your code so that I can reproduce the issue? |
Hi, I'm closing this issue for now, please reopen if needed. |
Can I re-open this? I need to get vs-code to run mypy with certain envvars set.
Outside of VS-Code it's easy to set the envvars:
but when VS-Code runs the same mypy command it fails because the envvars are not set. |
@dave-mclean ok, re-opened! Can you explain your use case? Why do you need environment vars to be set when mypy is run? As far as I know mypy shouldn't be importing your code so how come it's getting this error? Can you show me a minimal example to reproduce the issue? |
In my case, I use the django plugin, which when it runs my app.settings file fails on a key error for the environment variable 'VIRTUAL_ENV' |
Ah, ok. Interesting use case. I could add this feature quite easily |
sorry for the slow response! Yes, this is exactly it. We use the django-plugin which imports settings, which in-turn tries to access an envvar. I could refactor my app but it looks like it's easy enough to give mypy the envvars it needs |
FWIW this is a minimal example: # reproducer.py
from mypy.plugin import Plugin
import os
class CustomPlugin(Plugin):
def get_function_hook(self, fullname):
os.environ["FOO"] # attempts to access the env during type checking
def plugin(version: str):
return CustomPlugin # mypy.ini
[mypy]
plugins = reproducer.py Now executing
|
Basically, my python code reads environment variables.
Locally, I can get this working by setting them in my session. I even created a bash script to auto set them.
However, mypy (installed via the instructions for Mac) does not seem to find my environment variables, which leads to errors like "SESSION_NAME" not defined, etc.
What I tried:
The text was updated successfully, but these errors were encountered: