Commit Graph

5 Commits

Author SHA1 Message Date
Meghan Lele
34a7b4aabb [tools] Remove newline from clang-format reference hashes (#55328)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/55328

**Summary**
The `clang-format` reference hashes committed in #54737 have newlines at
the end but the locally computed ones do not. This commit removes these
newlines so that the `clang-format` binary verification step doesn't
fail.

**Test Plan**
`./tools/clang_format_all.py`, ran successfully.

**Fixes**
This commit fixes #54790.

Test Plan: Imported from OSS

Reviewed By: nikithamalgifb

Differential Revision: D27577398

Pulled By: SplitInfinity

fbshipit-source-id: e30bee58c2eb5ea96ed0a503480dea4f67b86aca
2021-04-06 17:17:19 -07:00
Chen Lai
7d9a619796 [PyTorch] Fix bin hash comparison failure in clang format script (#55281)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/55281

## Summary

` python3 tools/clang_format_all.py` is complaining that binary is not what expected. Find out the reference hash include an extra new line comparing with the actual hash. In this pr,
1. Use `expr(hash)` to show the raw string, such that it's easier to compare two string.
2. Remove the extra new line.
3. Run `python3 tools/clang_format_all.py `, and it formats `torch/csrc/jit/runtime/static/passes.h`.

Before the change,
```
(base) chenlai@chenlai-mp pytorch % python3 tools/clang_format_all.py -v
Found pre-existing clang-format binary, skipping download
Reference Hash: '5fde7bccf65032da297dfb1f18e4a95e96e278fa397e9dcaf364dfe23ec46353'
Actual Hash: '5fde7bccf65032da297dfb1f18e4a95e96e278fa397e9dcaf364dfe23ec46353'
The downloaded binary is not what was expected!
(base) chenlai@chenlai-mp pytorch %
```

After the change,
```
(base) chenlai@chenlai-mp pytorch % python3 tools/clang_format_all.py -v
Found pre-existing clang-format binary, skipping download
Reference Hash: '5fde7bccf65032da297dfb1f18e4a95e96e278fa397e9dcaf364dfe23ec46353\n'
Actual Hash: '5fde7bccf65032da297dfb1f18e4a95e96e278fa397e9dcaf364dfe23ec46353'
The downloaded binary is not what was expected!
(base) chenlai@chenlai-mp pytorch %
```

After strip the hash str:
```
(base) chenlai@chenlai-mp pytorch % python3 tools/clang_format_all.py -v
Downloading clang-format to /Users/chenlai/pytorch/.clang-format-bin
0% |################################################################| 100%
Reference Hash: '5fde7bccf65032da297dfb1f18e4a95e96e278fa397e9dcaf364dfe23ec46353'
Actual Hash: '5fde7bccf65032da297dfb1f18e4a95e96e278fa397e9dcaf364dfe23ec46353'
Using clang-format located at /Users/chenlai/pytorch/.clang-format-bin/clang-format
```

Test Plan: Imported from OSS

Reviewed By: iseeyuan

Differential Revision: D27556372

Pulled By: cccclai

fbshipit-source-id: 2fd1ba220733e767ffab41ab31e162f0bf3f1d62
2021-04-06 00:33:53 -07:00
kedejesu
53d8778b4d Update clang-format linux hash and yaml import calls (#53932)
Summary:
Fixing Bandit security issues.
- yaml_load: Use of unsafe yaml load. Allows instantiation of arbitrary objects. Consider yaml.safe_load().
Test ID: B506
Severity: MEDIUM
Confidence: HIGH
File: ./caffe2/contrib/aten/gen_op.py
More info: https://bandit.readthedocs.io/en/latest/plugins/b506_yaml_load.html
235 if __name__ == '__main__':
236     decls = yaml.load(read(os.path.join(args.yaml_dir, 'Declarations.yaml')), Loader=Loader)
237     factory_methods = find_factory_methods(decls)

- Blacklist: Use of insecure MD2 (6149a26adb), MD4 (fc7f026980), MD5 (7ea9d9af4e), or SHA1 hash function.
Test ID: B303
Severity: MEDIUM
Confidence: HIGH
File: ./tools/clang_format_utils.py
More info: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b303-md5
36
37     hash = hashlib.sha1()
38

Pull Request resolved: https://github.com/pytorch/pytorch/pull/53932

Reviewed By: jbschlosser

Differential Revision: D27072017

Pulled By: malfet

fbshipit-source-id: 2fef0119388797aee3cacdc880fc345bd2ba68ce
2021-03-18 17:11:58 -07:00
Nikita Shulga
627ec8badf Type-annotate tools/generate_torch_version (#51637)
Summary:
And add it to mypy.ini

Pull Request resolved: https://github.com/pytorch/pytorch/pull/51637

Reviewed By: janeyx99

Differential Revision: D26225123

Pulled By: malfet

fbshipit-source-id: d70d539ae58a14321e82f4592aaa44b3ce6b6358
2021-02-03 18:07:01 -08:00
Michael Suo
cf77e56938 clang-format don't run on master (#37058)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/37058

We shouldn't add advisory checks to master, because PRs will get
reverted if they fail. This PR makes the following changes:

1. Factor out the binary fetch logic into `clang_format_utils.py`
2. Copypasta the canonical git integration from llvm and modify it to
use our binary fetcher. No more bikeshedding about how to integrate,
we just use the standard integration.
3. Change the CI job to run on pull-requests only and use
`git-clang-format`.
4. The original `clang_format.py` is now renamed `clang_format_all.py`
to reflect its purpose.
5. The pre-commit hook has been changed to use `git-clang-format`.

For pre-commit hook users: no changes required.
For others: add `tools/git-clang-format` to your PATH and you can do `git clang-format` to format your working tree.

Test Plan: Imported from OSS

Differential Revision: D21180893

Pulled By: suo

fbshipit-source-id: f8358fb7ce26f11585226aaac5ed89d379257bfb
2020-04-22 11:37:22 -07:00