コード例 #1
0
    def test_find(self):
        workspace_dir, relpaths = find_all_sources("drake")

        # Sanity-check workspace_dir.  Most of the correctness assertions are
        # already embedded within the subroutine itself.
        with open(os.path.join(workspace_dir, "WORKSPACE"), "r") as contents:
            workspace_lines = contents.readlines()
        self.assertTrue('workspace(name = "drake")\n' in workspace_lines)

        # Sanity-check relpaths.
        # TODO(jwnimmer-tri) Ideally, sanity checking of the paths (e.g., their
        # len() like we check just below) could live within find_all_sources,
        # but projects other than Drake might need different heuristics.
        self.assertGreater(len(relpaths), 1_000)
        self.assertLess(len(relpaths), 10_000)
        self.assertTrue('.bazelproject' in relpaths)
        self.assertTrue('setup/ubuntu/install_prereqs.sh' in relpaths)
        THIRD_PARTY_SOURCES_ALLOWED_TO_BE_FOUND = [
            "third_party/BUILD.bazel",
            "third_party/README.md",
        ]
        for one_relpath in relpaths:
            self.assertTrue(".git/" not in one_relpath, one_relpath)
            if one_relpath.startswith("third_party/"):
                self.assertTrue(
                    one_relpath in THIRD_PARTY_SOURCES_ALLOWED_TO_BE_FOUND
                    or one_relpath.startswith("."),
                    one_relpath + " has been mis-identified as a source file")
コード例 #2
0
    def test_find(self):
        workspace_dir, relpaths = find_all_sources("drake")

        # Sanity-check workspace_dir.
        self.assertGreater(len(workspace_dir), 10)
        workspace = os.path.join(workspace_dir, "WORKSPACE")
        self.assertTrue(os.path.exists(workspace))
        with open(workspace, "r") as workspace_contents:
            workspace_lines = workspace_contents.readlines()
        self.assertTrue('workspace(name = "drake")\n' in workspace_lines)

        # Sanity-check relpaths.
        self.assertGreater(len(relpaths), 1000)
        self.assertTrue('.bazelproject' in relpaths)
        self.assertTrue('setup/ubuntu/16.04/install_prereqs.sh' in relpaths)
        THIRD_PARTY_SOURCES_ALLOWED_TO_BE_FOUND = [
            "third_party/BUILD.bazel.bazel",
            "third_party/README.md",
        ]
        for one_relpath in relpaths:
            self.assertTrue(".git/" not in one_relpath, one_relpath)
            if one_relpath.startswith("third_party/"):
                self.assertTrue(
                    one_relpath in THIRD_PARTY_SOURCES_ALLOWED_TO_BE_FOUND
                    or one_relpath.startswith("."),
                    one_relpath + " has been mis-identified as a source file")
コード例 #3
0
ファイル: util_test.py プロジェクト: carismoses/drake
    def test_find(self):
        workspace_dir, relpaths = find_all_sources("drake")

        # Sanity-check workspace_dir.
        self.assertGreater(len(workspace_dir), 10)
        workspace = os.path.join(workspace_dir, "WORKSPACE")
        self.assertTrue(os.path.exists(workspace))
        with open(workspace, "r") as workspace_contents:
            workspace_lines = workspace_contents.readlines()
        self.assertTrue('workspace(name = "drake")\n' in workspace_lines)

        # Sanity-check relpaths.
        self.assertGreater(len(relpaths), 1000)
        self.assertTrue('.bazelproject' in relpaths)
        self.assertTrue('setup/ubuntu/16.04/install_prereqs.sh' in relpaths)
        THIRD_PARTY_SOURCES_ALLOWED_TO_BE_FOUND = [
            "third_party/BUILD.bazel",
            "third_party/README.md",
        ]
        for one_relpath in relpaths:
            self.assertTrue(".git/" not in one_relpath, one_relpath)
            if one_relpath.startswith("third_party/"):
                self.assertTrue(
                    one_relpath in THIRD_PARTY_SOURCES_ALLOWED_TO_BE_FOUND or
                    one_relpath.startswith("."),
                    one_relpath + " has been mis-identified as a source file")
コード例 #4
0
ファイル: buildifier.py プロジェクト: ethanweber/atlas-drake
def _find_buildifier_sources(workspace_name):
    """Return a list of all filenames to be covered by buildifier."""
    workspace, sources_relpath = find_all_sources(workspace_name)
    exact_filenames = ["BUILD.bazel", "WORKSPACE"]
    extensions = ["bazel", "bzl", "BUILD.bazel"]
    return [
        os.path.join(workspace, relpath) for relpath in sources_relpath
        if os.path.splitext(relpath)[1][1:] in extensions
        or os.path.basename(relpath) in exact_filenames
    ]
コード例 #5
0
ファイル: buildifier.py プロジェクト: RobotLocomotion/drake
def _find_buildifier_sources(workspace_name):
    """Return a list of all filenames to be covered by buildifier."""
    workspace, sources_relpath = find_all_sources(workspace_name)
    exact_filenames = ["BUILD", "WORKSPACE"]
    extensions = ["bazel", "bzl", "BUILD"]
    return [
        os.path.join(workspace, relpath)
        for relpath in sources_relpath
        if os.path.splitext(relpath)[1][1:] in extensions or
        os.path.basename(relpath) in exact_filenames
    ]
コード例 #6
0
def main(workspace_name="drake"):
    parser = argparse.ArgumentParser(prog='clang-format-includes',
                                     description=__doc__)
    parser.add_argument('filenames',
                        metavar='filename',
                        type=str,
                        nargs='*',
                        help='full path to filename to reformat in place')
    parser.add_argument(
        '--all',
        action='store_true',
        default=False,
        help='reformat all first-party sources within the project')
    parser.add_argument(
        '--check-only',
        action='store_true',
        default=False,
        help='check if the file(s) are formatted correctly; do not edit')
    args = parser.parse_args()

    if args.all:
        workspace_dir, relpaths = find_all_sources(workspace_name)
        extensions = ["cc", "h", "cpp"]
        filenames = [
            os.path.join(workspace_dir, relpath) for relpath in relpaths
            if os.path.splitext(relpath)[1][1:] in extensions
            and not relpath.startswith("third_party")
        ]
        print(f"This will reformat {len(filenames)} files "
              f"within {workspace_dir}")
        if input("Are you sure [y/N]? ") not in ["y", "Y"]:
            print("... canceled")
            sys.exit(1)
    else:
        filenames = args.filenames

    num_errors = 0
    for filename in filenames:
        tool = IncludeFormatter(filename)
        tool.format_includes()
        if tool.is_same_as_original():
            continue
        if args.check_only:
            num_errors += 1
        else:
            tool.rewrite_file()

    if num_errors > 0:
        return 1

    return 0
コード例 #7
0
def main(workspace_name="drake"):
    parser = argparse.ArgumentParser(
        prog='clang-format-includes',
        description=__doc__)
    parser.add_argument(
        'filenames', metavar='filename', type=str, nargs='*',
        help='full path to filename to reformat in place')
    parser.add_argument(
        '--all', action='store_true', default=False,
        help='reformat all first-party sources within the project')
    parser.add_argument(
        '--check-only', action='store_true', default=False,
        help='check if the file(s) are formatted correctly; do not edit')
    args = parser.parse_args()

    if args.all:
        workspace_dir, relpaths = find_all_sources(workspace_name)
        extensions = ["cc", "h", "cpp"]
        filenames = [
            os.path.join(workspace_dir, relpath)
            for relpath in relpaths
            if os.path.splitext(relpath)[1][1:] in extensions and
            not relpath.startswith("third_party") and
            not relpath.startswith("matlab")
        ]
    else:
        filenames = args.filenames

    num_errors = 0
    for filename in filenames:
        tool = IncludeFormatter(filename)
        tool.format_includes()
        if tool.is_same_as_original():
            continue
        if args.check_only:
            num_errors += 1
        else:
            tool.rewrite_file()

    if num_errors > 0:
        return 1

    return 0
コード例 #8
0
ファイル: util_test.py プロジェクト: zapplelove/drake
    def test_find(self):
        workspace_dir, relpaths = find_all_sources("drake")

        # Sanity-check workspace_dir.  Most of the correctness assertions are
        # already embedded within the subroutine itself.
        with open(os.path.join(workspace_dir, "WORKSPACE"), "r") as contents:
            workspace_lines = contents.readlines()
        self.assertTrue('workspace(name = "drake")\n' in workspace_lines)

        # Sanity-check relpaths.
        self.assertGreater(len(relpaths), 1_000)
        self.assertTrue('.bazelproject' in relpaths)
        self.assertTrue('setup/ubuntu/install_prereqs.sh' in relpaths)
        THIRD_PARTY_SOURCES_ALLOWED_TO_BE_FOUND = [
            "third_party/BUILD.bazel",
            "third_party/README.md",
        ]
        for one_relpath in relpaths:
            self.assertTrue(".git/" not in one_relpath, one_relpath)
            if one_relpath.startswith("third_party/"):
                self.assertTrue(
                    one_relpath in THIRD_PARTY_SOURCES_ALLOWED_TO_BE_FOUND or
                    one_relpath.startswith("."),
                    one_relpath + " has been mis-identified as a source file")