This repository was archived by the owner on Mar 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathfile.py
More file actions
57 lines (42 loc) · 1.45 KB
/
file.py
File metadata and controls
57 lines (42 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from pathlib import Path
from tree_sitter import Node, Tree
from api.entities.entity import Entity
class File:
"""
Represents a file with basic properties like path, name, and extension.
"""
def __init__(self, path: Path, tree: Tree) -> None:
"""
Initialize a File object.
Args:
path (Path): The full path to the file.
tree (Tree): The parsed AST of the file content.
"""
self.path = path
self.tree = tree
self.entities: dict[Node, Entity] = {}
self.imports: list[Node] = []
self.resolved_imports: set[Entity] = set()
def add_entity(self, entity: Entity):
entity.parent = self
self.entities[entity.node] = entity
def add_import(self, import_node: Node):
"""
Add an import statement node to track.
Args:
import_node (Node): The import statement node.
"""
self.imports.append(import_node)
def add_resolved_import(self, resolved_entity: Entity):
"""
Add a resolved import entity.
Args:
resolved_entity (Entity): The resolved entity that is imported.
"""
self.resolved_imports.add(resolved_entity)
def __str__(self) -> str:
return f"path: {self.path}"
def __eq__(self, other) -> bool:
if not isinstance(other, File):
return False
return self.path == other.path