-
Notifications
You must be signed in to change notification settings - Fork 560
Add infrastructure to apply outstanding PT PRs. #183
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
CDIR=$(dirname $0) | ||
XDIR=$CDIR/.. | ||
PTDIR=$XDIR/.. | ||
|
||
python $CDIR/cond_patch.py \ | ||
$XDIR/torch_patches \ | ||
$PTDIR |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/usr/bin/env python | ||
|
||
from __future__ import print_function | ||
|
||
import argparse | ||
import glob | ||
import os | ||
import re | ||
import subprocess | ||
import sys | ||
|
||
|
||
def get_log(repo_folder, depth): | ||
return subprocess.check_output( | ||
['git', '-C', repo_folder, 'log', '-{}'.format(depth)]).decode('utf-8') | ||
|
||
|
||
def is_applied(log, revno): | ||
revrx = 'Pull Request resolved: .*[/#]{}'.format(revno) | ||
return re.search(revrx, log) | ||
|
||
|
||
def select_patches(patch_folder, repo_folder, depth): | ||
log = get_log(repo_folder, depth) | ||
files = sorted(glob.glob(os.path.join(patch_folder, '*.diff'))) | ||
selected = [] | ||
for ppath in files: | ||
revno = os.path.splitext(os.path.basename(ppath))[0] | ||
# Patches which are not all digits (PR numbers) are always applied. | ||
if not re.match(r'\d+$', revno) or not is_applied(log, revno): | ||
selected.append(ppath) | ||
return selected | ||
|
||
|
||
def apply_patch(ppath, repo_folder, level): | ||
return subprocess.call([ | ||
'patch', '-d', repo_folder, '-p{}'.format(level), '-i', ppath, '-E', '-l', | ||
'-r', '-', '-s', '--no-backup-if-mismatch' | ||
]) | ||
|
||
|
||
def patch_repo(args): | ||
patches = select_patches( | ||
os.path.normpath(args.patch_folder), os.path.normpath(args.repo_folder), | ||
args.log_depth) | ||
for ppath in patches: | ||
print('Applying patch file: {}'.format(ppath), file=sys.stderr) | ||
apply_patch(ppath, os.path.normpath(args.repo_folder), args.level) | ||
|
||
|
||
if __name__ == '__main__': | ||
arg_parser = argparse.ArgumentParser() | ||
arg_parser.add_argument('--level', type=int, default=1) | ||
arg_parser.add_argument('--log_depth', type=int, default=1000) | ||
arg_parser.add_argument( | ||
'patch_folder', | ||
type=str, | ||
metavar='PATCH_FOLDER', | ||
help='The path to the folder containing the patches') | ||
arg_parser.add_argument( | ||
'repo_folder', | ||
type=str, | ||
metavar='REPO_FOLDER', | ||
help='The path to the root folder of the repo to be patched') | ||
args, files = arg_parser.parse_known_args() | ||
patch_repo(args) |
Empty file.
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Guidelines For Patch File Names | ||
|
||
The only files which are considered by the apply script are the ones with extension '.diff'. | ||
|
||
A file for PyTorch PR _N_ needs to be named 'N.diff'. | ||
|
||
Patch files which are not related to PyTorch PRs, should begin with an 'X' character, | ||
followed by a two digit number, followed by a dash ('-'), a name, and '.diff'. | ||
Example: | ||
|
||
``` | ||
X10-optimizer.diff | ||
``` | ||
|
||
Patch file are alphabetically ordered, so PyTorch PR patches are always applied | ||
before the non PyTorch ones. | ||
|
File renamed without changes.
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.
Doesn't
kokoro/ubuntu/common.sh
need the same change?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.
Yeah