From 165b31eb7f6ff9f5725a1afdd3b7ebef34c33e78 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 3 Sep 2020 19:47:30 -0700 Subject: [PATCH 1/2] Add MYPY_CONFIG_FILE_DIR to environment when config file is read (2nd try) Let's see what it will take to make CI pass. Resubmit of #9403. Fixes #7968. Co-authored-by: aghast --- mypy/config_parser.py | 3 +++ mypy/test/testcmdline.py | 1 + test-data/unit/envvars.test | 11 +++++++++++ 3 files changed, 15 insertions(+) create mode 100644 test-data/unit/envvars.test 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 + From 5a63508fee0995fe8a062665751e722f934b4292 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 3 Sep 2020 21:16:08 -0700 Subject: [PATCH 2/2] Change dots back into spaces --- test-data/unit/envvars.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-data/unit/envvars.test b/test-data/unit/envvars.test index 12835e6f1f7cf..0d78590e57a52 100644 --- a/test-data/unit/envvars.test +++ b/test-data/unit/envvars.test @@ -2,9 +2,9 @@ [case testEnvvar_MYPY_CONFIG_FILE_DIR] # cmd: mypy --config-file=subdir/mypy.ini [file bogus.py] -FOO = 'x'. # type: int +FOO = 'x' # type: int [file subdir/good.py] -BAR = 0. # type: int +BAR = 0 # type: int [file subdir/mypy.ini] \[mypy] files=$MYPY_CONFIG_FILE_DIR/good.py