mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Summary: Uses the Python standard library 2to3 script to convert a number of Python 2 files to Python 3. This facilitates code maintenance such as dropping unused imports in D25500422. Pull Request resolved: https://github.com/pytorch/pytorch/pull/49351 Test Plan: Standard sandcastle tests Reviewed By: xush6528 Differential Revision: D25499576 fbshipit-source-id: 0c44718ac734771ce0758b1cb30676cc3d76ac10
57 lines
2.0 KiB
Python
57 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
## @package process
|
|
# Module doxygen.process
|
|
# Script to insert preamble for doxygen and regen API docs
|
|
|
|
import os
|
|
import shutil
|
|
|
|
# Module caffe2...caffe2.python.control_test
|
|
def insert(originalfile, first_line, description):
|
|
with open(originalfile, 'r') as f:
|
|
f1 = f.readline()
|
|
if(f1.find(first_line) < 0):
|
|
docs = first_line + description + f1
|
|
with open('newfile.txt', 'w') as f2:
|
|
f2.write(docs)
|
|
f2.write(f.read())
|
|
os.rename('newfile.txt', originalfile)
|
|
else:
|
|
print('already inserted')
|
|
|
|
# move up from /caffe2_root/doxygen
|
|
os.chdir("..")
|
|
os.system("git checkout caffe2/contrib/.")
|
|
os.system("git checkout caffe2/distributed/.")
|
|
os.system("git checkout caffe2/experiments/.")
|
|
os.system("git checkout caffe2/python/.")
|
|
|
|
for root, dirs, files in os.walk("."):
|
|
for file in files:
|
|
if (file.endswith(".py") and not file.endswith("_test.py") and not file.endswith("__.py")):
|
|
filepath = os.path.join(root, file)
|
|
print(("filepath: " + filepath))
|
|
directory = os.path.dirname(filepath)[2:]
|
|
directory = directory.replace("/", ".")
|
|
print("directory: " + directory)
|
|
name = os.path.splitext(file)[0]
|
|
first_line = "## @package " + name
|
|
description = "\n# Module " + directory + "." + name + "\n"
|
|
print(first_line, description)
|
|
insert(filepath, first_line, description)
|
|
|
|
if os.path.exists("doxygen/doxygen-python"):
|
|
print("Looks like you ran this before, so we need to cleanup those old files...")
|
|
shutil.rmtree("doxygen/doxygen-python")
|
|
else:
|
|
os.makedirs("doxygen/doxygen-python")
|
|
|
|
if os.path.exists("doxygen/doxygen-c"):
|
|
print("Looks like you ran this before, so we need to cleanup those old files...")
|
|
shutil.rmtree("doxygen/doxygen-c")
|
|
else:
|
|
os.makedirs("doxygen/doxygen-c")
|
|
|
|
os.system("doxygen .Doxyfile-python")
|
|
os.system("doxygen .Doxyfile-c")
|