diff --git a/.gitignore b/.gitignore index c03e2b09ccda7..e6200865d319f 100644 --- a/.gitignore +++ b/.gitignore @@ -257,8 +257,10 @@ cmake-build-debug # Below files are not deleted by "setup.py clean". # Visual Studio Code files -.vscode .vs +/.vscode/* +!/.vscode/extensions.json +!/.vscode/settings_recommended.json # YouCompleteMe config file .ycm_extra_conf.py diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000000000..9c4cf774157ac --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "ms-python.python" + ] +} diff --git a/.vscode/settings_recommended.json b/.vscode/settings_recommended.json new file mode 100644 index 0000000000000..e9eae8ead3c9b --- /dev/null +++ b/.vscode/settings_recommended.json @@ -0,0 +1,12 @@ +{ + "[python]": { + "editor.tabSize": 4 + }, + "files.eol": "\n", + "files.insertFinalNewline": true, + "files.trimFinalNewlines": true, + "files.trimTrailingWhitespace": true, + "python.formatting.provider": "none", + "python.linting.enabled": true, + "python.linting.flake8Enabled": true +} diff --git a/mypy-strict.ini b/mypy-strict.ini index e8bc2c2554d3c..f3c5c136bc531 100644 --- a/mypy-strict.ini +++ b/mypy-strict.ini @@ -38,6 +38,7 @@ strict_equality = True files = .github/scripts/generate_binary_build_matrix.py, benchmarks/instruction_counts, + tools/actions_local_runner.py, tools/autograd/*.py, tools/clang_tidy.py, tools/codegen, @@ -47,20 +48,20 @@ files = tools/pyi, tools/stats_utils, tools/test_history.py, + tools/test/test_actions_local_runner.py, tools/test/test_extract_scripts.py, tools/test/test_mypy_wrapper.py, tools/test/test_test_history.py, tools/test/test_trailing_newlines.py, - tools/test/test_actions_local_runner.py, tools/test/test_translate_annotations.py, tools/trailing_newlines.py, tools/translate_annotations.py, - tools/actions_local_runner.py, + tools/vscode_settings.py, torch/testing/_internal/framework_utils.py, + torch/utils/_pytree.py, torch/utils/benchmark/utils/common.py, torch/utils/benchmark/utils/timer.py, - torch/utils/benchmark/utils/valgrind_wrapper, - torch/utils/_pytree.py + torch/utils/benchmark/utils/valgrind_wrapper # Specifically enable imports of benchmark utils. As more of `torch` becomes # strict compliant, those modules can be enabled as well. diff --git a/tools/README.md b/tools/README.md index 558607ec03493..880532ab4f7b5 100644 --- a/tools/README.md +++ b/tools/README.md @@ -64,10 +64,14 @@ Developer tools which you might find useful: trailing newline, exit with status 1 if no output printed or 0 if some filenames were printed. * [translate_annotations.py](translate_annotations.py) - Read [Flake8][] or - [clang-tidy][] warnings (according to a `--regex`) from a `--file`, convert - to the JSON format accepted by [pytorch/add-annotations-github-action], and - translate line numbers from `HEAD` back in time to the given `--commit` by - running `git diff-index --unified=0` appropriately. + [clang-tidy][] warnings (according to a `--regex`) from a `--file`, convert to + the JSON format accepted by [pytorch/add-annotations-github-action], and + translate line numbers from `HEAD` back in time to the given `--commit` by + running `git diff-index --unified=0` appropriately. +* [vscode_settings.py](vscode_settings.py) - Merge + `.vscode/settings_recommended.json` into your workspace-local + `.vscode/settings.json`, preferring the former in case of conflicts but + otherwise preserving the latter as much as possible. Important if you want to run on AMD GPU: diff --git a/tools/vscode_settings.py b/tools/vscode_settings.py new file mode 100755 index 0000000000000..88dbfb4fedf9c --- /dev/null +++ b/tools/vscode_settings.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +import json +from pathlib import Path + + +def main() -> None: + folder = Path('.vscode') + recommended = json.loads((folder / 'settings_recommended.json').read_text()) + path = folder / 'settings.json' + try: + current = json.loads(path.read_text()) + except Exception: + current = {} + with open(path, 'w') as f: + json.dump({**current, **recommended}, f, indent=2) + f.write('\n') + + +if __name__ == '__main__': + main()