Skip to content

Commit

Permalink
Add MYPY_CONFIG_FILE_DIR to environment when config file is read
Browse files Browse the repository at this point in the history
Let's see what it will take to make CI pass.

Resubmit of #9403.

Fixes #7968.

Co-authored-by: blueyed
  • Loading branch information
gvanrossum committed Sep 4, 2020
1 parent 57d3473 commit 27ce032
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mypy/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions mypy/test/testcmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
cmdline_files = [
'cmdline.test',
'reports.test',
'envvars.test',
]


Expand Down
11 changes: 11 additions & 0 deletions test-data/unit/envvars.test
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 27ce032

Please sign in to comment.