Getting diff apis for tools/sampcd_processor.py (#22817)

revert-22710-feature/integrated_ps_api
zhangchunle 5 years ago committed by GitHub
parent 0d463d3bf7
commit 3715379c31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -445,13 +445,9 @@ def test(file_list):
return process_result return process_result
def get_filenames(path): def get_filenames():
''' '''
Given a path ``path``, this function will this function will get the modules that pending for check.
get the modules that pending for check.
Args:
path(path): the path of API.spec
Returns: Returns:
@ -461,11 +457,11 @@ def get_filenames(path):
filenames = [] filenames = []
global methods global methods
methods = [] methods = []
API_spec = '%s/%s' % (os.path.abspath(os.path.join(os.getcwd(), "..")), get_incrementapi()
path) API_spec = 'dev_pr_diff_api.spec'
with open(API_spec) as f: with open(API_spec) as f:
for line in f.readlines(): for line in f.readlines():
api = line.split(' ', 1)[0] api = line.replace('\n', '')
try: try:
module = eval(api).__module__ module = eval(api).__module__
except AttributeError: except AttributeError:
@ -499,9 +495,40 @@ def get_filenames(path):
method = method + name method = method + name
if method not in methods: if method not in methods:
methods.append(method) methods.append(method)
os.remove(API_spec)
return filenames return filenames
def get_incrementapi():
'''
this function will get the apis that difference between API_DEV.spec and API_PR.spec.
'''
def get_api_md5(path):
api_md5 = {}
API_spec = '%s/%s' % (os.path.abspath(os.path.join(os.getcwd(), "..")),
path)
with open(API_spec) as f:
for line in f.readlines():
api = line.split(' ', 1)[0]
md5 = line.split("'document', ")[1].replace(')', '').replace(
'\n', '')
api_md5[api] = md5
return api_md5
dev_api = get_api_md5('paddle/fluid/API_DEV.spec')
pr_api = get_api_md5('paddle/fluid/API_PR.spec')
with open('dev_pr_diff_api.spec', 'w') as f:
for key in pr_api:
if key in dev_api:
if dev_api[key] != pr_api[key]:
f.write(key)
f.write('\n')
else:
f.write(key)
f.write('\n')
''' '''
Important constant lists: Important constant lists:
@ -720,9 +747,16 @@ else:
if not os.path.isdir("./samplecode_temp"): if not os.path.isdir("./samplecode_temp"):
os.mkdir("./samplecode_temp") os.mkdir("./samplecode_temp")
cpus = multiprocessing.cpu_count() cpus = multiprocessing.cpu_count()
filenames = get_filenames('paddle/fluid/API_PR.spec') filenames = get_filenames()
filenames.remove('../python/paddle/fluid/core_avx.py') if len(filenames) == 0:
print("-----API_PR.spec is the same as API_DEV.spec-----")
exit(0)
elif '../python/paddle/fluid/core_avx.py' in filenames:
filenames.remove('../python/paddle/fluid/core_avx.py')
print("API_PR is diff from API_DEV: %s" % filenames)
one_part_filenum = int(math.ceil(len(filenames) / cpus)) one_part_filenum = int(math.ceil(len(filenames) / cpus))
if one_part_filenum == 0:
one_part_filenum = 1
divided_file_list = [ divided_file_list = [
filenames[i:i + one_part_filenum] filenames[i:i + one_part_filenum]
for i in range(0, len(filenames), one_part_filenum) for i in range(0, len(filenames), one_part_filenum)

Loading…
Cancel
Save