diff --git a/mypy/config_parser.py b/mypy/config_parser.py index 7e1f16f56b25b..e5f769f0986b2 100644 --- a/mypy/config_parser.py +++ b/mypy/config_parser.py @@ -135,6 +135,9 @@ def parse_config_file(options: Options, set_strict_flags: Callable[[], None], else: return + os.environ['MYPY_CONFIG_FILE_DIR'] = os.path.dirname( + os.path.abspath(config_file)) + if 'mypy' not in parser: if filename or file_read not in defaults.SHARED_CONFIG_FILES: print("%s: No [mypy] section in config file" % file_read, file=stderr) diff --git a/mypy/test/testcmdline.py b/mypy/test/testcmdline.py index 8d6a0d1fdc968..9ae6a0eb70761 100644 --- a/mypy/test/testcmdline.py +++ b/mypy/test/testcmdline.py @@ -25,6 +25,7 @@ cmdline_files = [ 'cmdline.test', 'reports.test', + 'envvars.test', ] diff --git a/test-data/unit/envvars.test b/test-data/unit/envvars.test new file mode 100644 index 0000000000000..12835e6f1f7cf --- /dev/null +++ b/test-data/unit/envvars.test @@ -0,0 +1,11 @@ +# Test cases related to environment variables +[case testEnvvar_MYPY_CONFIG_FILE_DIR] +# cmd: mypy --config-file=subdir/mypy.ini +[file bogus.py] +FOO = 'x'. # type: int +[file subdir/good.py] +BAR = 0. # type: int +[file subdir/mypy.ini] +\[mypy] +files=$MYPY_CONFIG_FILE_DIR/good.py +