Selfie
Loading...
Searching...
No Matches
selfie_lib.CommentTracker.CommentTracker Class Reference

Public Member Functions

 __init__ (self)
 
Iterable[TypedPathpaths_with_once (self)
 
bool hasWritableComment (self, CallStack call, SnapshotFileLayout layout)
 

Static Public Member Functions

tuple[str, int] commentString (TypedPath typedPath)
 

Public Attributes

 lock
 

Detailed Description

Definition at line 20 of file CommentTracker.py.

Constructor & Destructor Documentation

◆ __init__()

selfie_lib.CommentTracker.CommentTracker.__init__ (   self)

Definition at line 21 of file CommentTracker.py.

21 def __init__(self):
22 self.cache: dict[TypedPath, WritableComment] = {}
23 self.lock = threading.Lock()
24

Member Function Documentation

◆ commentString()

tuple[str, int] selfie_lib.CommentTracker.CommentTracker.commentString ( TypedPath  typedPath)
static

Definition at line 44 of file CommentTracker.py.

44 def commentString(typedPath: TypedPath) -> tuple[str, int]:
45 comment, line = CommentTracker.__commentAndLine(typedPath)
46 if comment == WritableComment.NO_COMMENT:
47 raise ValueError("No writable comment found")
48 elif comment == WritableComment.ONCE:
49 return ("#selfieonce", line)
50 elif comment == WritableComment.FOREVER:
51 return ("#SELFIEWRITE", line)
52 else:
53 raise ValueError("Invalid comment type")
54

◆ hasWritableComment()

bool selfie_lib.CommentTracker.CommentTracker.hasWritableComment (   self,
CallStack  call,
SnapshotFileLayout  layout 
)

Definition at line 33 of file CommentTracker.py.

33 def hasWritableComment(self, call: CallStack, layout: SnapshotFileLayout) -> bool:
34 path = layout.sourcefile_for_call(call.location)
35 with self.lock:
36 if path in self.cache:
37 return self.cache[path].writable
38 else:
39 new_comment, _ = self.__commentAndLine(path)
40 self.cache[path] = new_comment
41 return new_comment.writable
42

◆ paths_with_once()

Iterable[TypedPath] selfie_lib.CommentTracker.CommentTracker.paths_with_once (   self)

Definition at line 25 of file CommentTracker.py.

25 def paths_with_once(self) -> Iterable[TypedPath]:
26 with self.lock:
27 return [
28 path
29 for path, comment in self.cache.items()
30 if comment == WritableComment.ONCE
31 ]
32

Member Data Documentation

◆ lock

selfie_lib.CommentTracker.CommentTracker.lock

Definition at line 23 of file CommentTracker.py.


The documentation for this class was generated from the following file: