MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / classify_file

Function classify_file

graphify/detect.py:553–589  ·  view source on GitHub ↗
(path: Path)

Source from the content-addressed store, hash-verified

551
552
553def classify_file(path: Path) -> FileType | None:
554 # Package manifests (apm.yml, pyproject.toml, Cargo.toml, go.mod, pom.xml) are parsed
555 # deterministically, so route them to the AST path (CODE) rather than the LLM
556 # document path — otherwise apm.yml (a .yml "document") would be LLM-extracted
557 # and a package would split into duplicate file-anchored nodes (#1377).
558 from graphify.manifest_ingest import is_package_manifest_path
559 if is_package_manifest_path(path):
560 return FileType.CODE
561 # Compound extensions must be checked before simple suffix lookup
562 if path.name.lower().endswith(".blade.php"):
563 return FileType.CODE
564 # A project may declare what an ambiguous extension means to it
565 # (.graphifyrc `language.inc=php`, #2961); classify by the declared one.
566 ext = effective_suffix(path).lower()
567 if not ext:
568 return _shebang_file_type(path)
569 if ext in CODE_EXTENSIONS:
570 return FileType.CODE
571 if ext in PAPER_EXTENSIONS:
572 # PDFs inside Xcode asset catalogs are vector icons, not papers
573 if any(part.endswith(tuple(_ASSET_DIR_MARKERS)) for part in path.parts):
574 return None
575 return FileType.PAPER
576 if ext in IMAGE_EXTENSIONS:
577 return FileType.IMAGE
578 if ext in DOC_EXTENSIONS:
579 # Check if it's a converted paper
580 if _looks_like_paper(path):
581 return FileType.PAPER
582 return FileType.DOCUMENT
583 if ext in OFFICE_EXTENSIONS:
584 return FileType.DOCUMENT
585 if ext in GOOGLE_WORKSPACE_EXTENSIONS:
586 return FileType.DOCUMENT
587 if ext in VIDEO_EXTENSIONS:
588 return FileType.VIDEO
589 return None
590
591
592# Missing-pypdf is a process-global condition, not per-file, so warn at most

Calls 4

is_package_manifest_pathFunction · 0.90
effective_suffixFunction · 0.90
_shebang_file_typeFunction · 0.85
_looks_like_paperFunction · 0.85