Skip to content

Commit

Permalink
Add MYPY_CONFIG_FILE_DIR to environment when config file is read (#9403)
Browse files Browse the repository at this point in the history
Fixes #7968
  • Loading branch information
aghast authored Sep 4, 2020
1 parent 5a2c3c2 commit 652aca9
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

7 comments on commit 652aca9

@aghast
Copy link
Contributor Author

@aghast aghast commented on 652aca9 Sep 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like dots after 'x' and 0, should be spaces.

@gvanrossum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch. I hate that. My browser has started doing this (apparently copying cell phones).

@gvanrossum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Do you want to resubmit this yourself, so you get full GitHub credit?)

@gvanrossum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(And sorry for the screw-up.)

@aghast
Copy link
Contributor Author

@aghast aghast commented on 652aca9 Sep 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's coming. Gotta get those internet points!

Also, can I get a "GvR broke my code!" tee shirt?

@gvanrossum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn’t see your PR yet?

@gvanrossum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh, I just merged. You still get credit for the first commit anyway. :-)

Please sign in to comment.