Skip to content
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

Add MYPY_CONFIG_FILE_DIR to environment when config file is read (2nd try) #9414

Merged
merged 2 commits into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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