MCPcopy
hub / github.com/github/awesome-copilot / detect_project_language

Function detect_project_language

skills/quality-playbook/quality_gate.py:683–724  ·  view source on GitHub ↗

Walk up to 3 dirs deep, return first language whose extension is present. Mirrors bash `find -maxdepth 3 -not -path ...` behavior.

(repo_dir)

Source from the content-addressed store, hash-verified

681
682
683def detect_project_language(repo_dir):
684 """Walk up to 3 dirs deep, return first language whose extension is present.
685
686 Mirrors bash `find -maxdepth 3 -not -path ...` behavior.
687 """
688 language_order = [
689 ("go", ".go"),
690 ("py", ".py"),
691 ("java", ".java"),
692 ("kt", ".kt"),
693 ("rs", ".rs"),
694 ("ts", ".ts"),
695 ("js", ".js"),
696 ("scala", ".scala"),
697 ("c", ".c"),
698 ("agc", ".agc"),
699 ]
700 excluded = {"vendor", "node_modules", ".git", "quality", "repos"}
701
702 def present(base, target_ext):
703 stack = [(Path(base), 1)]
704 while stack:
705 curr, depth = stack.pop()
706 try:
707 for entry in os.scandir(curr):
708 name = entry.name
709 if entry.is_dir(follow_symlinks=False):
710 if name in excluded:
711 continue
712 if depth < 3:
713 stack.append((Path(entry.path), depth + 1))
714 elif entry.is_file(follow_symlinks=False):
715 if name.endswith(target_ext):
716 return True
717 except (OSError, PermissionError):
718 continue
719 return False
720
721 for lang, ext in language_order:
722 if present(repo_dir, ext):
723 return lang
724 return ""
725
726
727def count_source_files(repo_dir):

Callers 1

Calls 1

presentFunction · 0.85

Tested by

no test coverage detected