Ejemplo n.º 1
0
def clean_cpp(path):
    # skip code that isn't ours
    if "dependency" in path or "/eigen3/" in path:
        return
    if options.clang_format:
        contents = _run([options.clang_format, "--style=Google", path])
    else:
        contents = open(path, "r").read()
    contents = contents.replace("% template", "%template")
    python_tools.rewrite(path, contents)
Ejemplo n.º 2
0
def clean_cpp(path):
    # skip code that isn't ours
    if "dependency" in path or "/eigen3/" in path:
        return
    if options.clang_format:
        contents = _run([options.clang_format, "--style=Google", path])
    else:
        contents = open(path, "r").read()
    contents = contents.replace("% template", "%template")
    python_tools.rewrite(path, contents)
Ejemplo n.º 3
0
def clean_py(path):
    if options.use_ap and options.autopep8:
        contents = _run([options.autopep8, "--aggressive", "--aggressive",
                         path])
    else:
        r = Reindenter(open(path))
        r.run()
        contents = ''.join(r.after)
    if contents.find("# \\example") != -1:
        contents = "#" + contents
    python_tools.rewrite(path, contents)
Ejemplo n.º 4
0
def clean_py(path):
    if options.use_ap and options.autopep8:
        contents = _run(
            [options.autopep8, "--aggressive", "--aggressive", path])
    else:
        r = Reindenter(open(path))
        r.run()
        contents = ''.join(r.after)
    if contents.find("# \\example") != -1:
        contents = "#" + contents
    python_tools.rewrite(path, contents)
Ejemplo n.º 5
0
def make_files(d):
    output = os.path.join(d, "Files.cmake")
    cppfiles = _get_files(d, ".cpp")
    cudafiles = _get_files(d, ".cu")
    pyfiles = _get_files(d, ".py")
    jsonfiles = _get_files(d, ".json")
    out = ["set(pyfiles \"%s\")" % ";".join(pyfiles),
           "set(cppfiles \"%s\")" % ";".join(cppfiles),
           "set(cudafiles \"%s\")" % ";".join(cudafiles)]
    if len(jsonfiles) > 0:
        out.append("set(jsonfiles \"%s\")" % ";".join(jsonfiles))
    python_tools.rewrite(output, "\n".join(out) + "\n")
Ejemplo n.º 6
0
 def test_rewrite_exists(self):
     """Test rewrite() with an existing file"""
     with utils.TempDir() as tmpdir:
         fname = os.path.join(tmpdir, 'fname')
         utils.write_file(fname, 'foo')
         python_tools.rewrite(fname, 'foo')
         self.assertEqual(utils.read_file(fname), 'foo')
         python_tools.rewrite(fname, 'bar')
         self.assertEqual(utils.read_file(fname), 'bar')
         python_tools.rewrite(fname, 'foo', verbose=True)
         self.assertEqual(utils.read_file(fname), 'foo')
Ejemplo n.º 7
0
 def test_rewrite_exists(self):
     """Test rewrite() with an existing file"""
     with utils.TempDir() as tmpdir:
         fname = os.path.join(tmpdir, 'fname')
         utils.write_file(fname, 'foo')
         python_tools.rewrite(fname, 'foo')
         self.assertEqual(utils.read_file(fname), 'foo')
         python_tools.rewrite(fname, 'bar')
         self.assertEqual(utils.read_file(fname), 'bar')
         python_tools.rewrite(fname, 'foo', verbose=True)
         self.assertEqual(utils.read_file(fname), 'foo')
Ejemplo n.º 8
0
    "_").replace("\\",
                 "_").replace(".",
                              "_").upper()
output.append("#ifndef %s" % guard)
output.append("#define %s" % guard)

for h in sys.argv[3:]:
    if not h.endswith(".h"):
        pat = os.path.join(h, "*.h")
        orig_h = sorted(glob.glob(pat))
        allh = []
        deprecated_allh = []
        for h in orig_h:
            if 'DEPRECATED_HEADER' in open_utf8(h).read():
                deprecated_allh.append(h)
            else:
                allh.append(h)
    else:
        deprecated_allh = []
        allh = [h]
    _add_includes(allh, output)

    if deprecated_allh:
        # SWIG needs all headers (for now)
        output.append("#ifdef IMP_SWIG_WRAPPER")
        _add_includes(deprecated_allh, output)
        output.append("#endif")

output.append("#endif /* %s */" % guard)
python_tools.rewrite(sys.argv[1], "\n".join(output) + "\n")