diff_api.py 980 字节
Newer Older
Y
yuyang18 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/usr/bin/env python
from __future__ import print_function
import difflib
import sys

with open(sys.argv[1], 'r') as f:
    origin = f.read()
    origin = origin.splitlines()

with open(sys.argv[2], 'r') as f:
    new = f.read()
    new = new.splitlines()

differ = difflib.Differ()
result = differ.compare(origin, new)

error = False
Z
Zeng Jinle 已提交
18
diffs = []
Y
yuyang18 已提交
19 20 21 22
for each_diff in result:
    if each_diff[0] in ['-', '?']:  # delete or change API is not allowed
        error = True
    elif each_diff[0] == '+':
23
        error = True
Y
yuyang18 已提交
24 25

    if each_diff[0] != ' ':
Z
Zeng Jinle 已提交
26 27 28 29
        diffs.append(each_diff)
'''
If you modify/add/delete the API files, including code and comment, 
please follow these steps in order to pass the CI:
Y
yuyang18 已提交
30

Z
Zeng Jinle 已提交
31 32 33 34
  1. cd ${paddle_path}, compile paddle;
  2. pip install build/python/dist/(build whl package);
  3. run "python tools/print_signatures.py paddle.fluid> paddle/fluid/API.spec"
'''
Y
yuyang18 已提交
35
if error:
Z
Zeng Jinle 已提交
36 37 38
    print('API Difference is: ')
    for each_diff in diffs:
        print(each_diff)