-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Walk up for all config files and handle precedence #18482
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
450de8a
Handle precedence correctly when searching for config file
hauntsaninja 00c6274
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ebc9b2f
.
hauntsaninja 1d8fdb5
delete a line
hauntsaninja f1d0d91
.
hauntsaninja c694ea6
.
hauntsaninja 58f389b
.
hauntsaninja cb1f686
.
hauntsaninja d220466
.
hauntsaninja b09c6a4
.
hauntsaninja cf3eded
Update docs/source/config_file.rst
hauntsaninja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,50 +12,15 @@ | |
# mypy, at least version PYTHON3_VERSION is needed. | ||
PYTHON3_VERSION_MIN: Final = (3, 8) # Keep in sync with typeshed's python support | ||
|
||
CACHE_DIR: Final = ".mypy_cache" | ||
|
||
def find_pyproject() -> str: | ||
"""Search for file pyproject.toml in the parent directories recursively. | ||
|
||
It resolves symlinks, so if there is any symlink up in the tree, it does not respect them | ||
|
||
If the file is not found until the root of FS or repository, PYPROJECT_FILE is used | ||
""" | ||
|
||
def is_root(current_dir: str) -> bool: | ||
parent = os.path.join(current_dir, os.path.pardir) | ||
return os.path.samefile(current_dir, parent) or any( | ||
os.path.isdir(os.path.join(current_dir, cvs_root)) for cvs_root in (".git", ".hg") | ||
) | ||
|
||
# Preserve the original behavior, returning PYPROJECT_FILE if exists | ||
if os.path.isfile(PYPROJECT_FILE) or is_root(os.path.curdir): | ||
return PYPROJECT_FILE | ||
|
||
# And iterate over the tree | ||
current_dir = os.path.pardir | ||
while not is_root(current_dir): | ||
config_file = os.path.join(current_dir, PYPROJECT_FILE) | ||
if os.path.isfile(config_file): | ||
return config_file | ||
parent = os.path.join(current_dir, os.path.pardir) | ||
current_dir = parent | ||
|
||
return PYPROJECT_FILE | ||
|
||
CONFIG_NAMES: Final = ["mypy.ini", ".mypy.ini"] | ||
SHARED_CONFIG_NAMES: Final = ["pyproject.toml", "setup.cfg"] | ||
|
||
CACHE_DIR: Final = ".mypy_cache" | ||
CONFIG_FILE: Final = ["mypy.ini", ".mypy.ini"] | ||
PYPROJECT_FILE: Final = "pyproject.toml" | ||
PYPROJECT_CONFIG_FILES: Final = [find_pyproject()] | ||
SHARED_CONFIG_FILES: Final = ["setup.cfg"] | ||
USER_CONFIG_FILES: Final = ["~/.config/mypy/config", "~/.mypy.ini"] | ||
if os.environ.get("XDG_CONFIG_HOME"): | ||
USER_CONFIG_FILES.insert(0, os.path.join(os.environ["XDG_CONFIG_HOME"], "mypy/config")) | ||
|
||
CONFIG_FILES: Final = ( | ||
CONFIG_FILE + PYPROJECT_CONFIG_FILES + SHARED_CONFIG_FILES + USER_CONFIG_FILES | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, simply change the order here to |
||
) | ||
|
||
# This must include all reporters defined in mypy.report. This is defined here | ||
# to make reporter names available without importing mypy.report -- this speeds | ||
# up startup. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that the files
mypy.ini
and.mypy.ini
in the parent directories will work?I don't think it's a good idea. It violates the rule of thumb that those files are used to work only from the current directory.
It's a too-wide change.
I suggest make a precedence for local files, then use pyproject.toml, and then use user-defined files.