Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
SelfCheckState Class Reference

Public Member Functions

None __init__ (self, str cache_dir)
 
str key (self)
 
Optional[str] get (self, datetime.datetime current_time)
 
None set (self, str pypi_version, datetime.datetime current_time)
 

Data Fields

 key
 

Protected Attributes

 _statefile_path
 
 _state
 

Detailed Description

Definition at line 43 of file self_outdated_check.py.

Constructor & Destructor Documentation

◆ __init__()

None __init__ (   self,
str  cache_dir 
)

Definition at line 44 of file self_outdated_check.py.

44 def __init__(self, cache_dir: str) -> None:
45 self._state: Dict[str, Any] = {}
46 self._statefile_path = None
47
48 # Try to load the existing state
49 if cache_dir:
50 self._statefile_path = os.path.join(
51 cache_dir, "selfcheck", _get_statefile_name(self.key)
52 )
53 try:
54 with open(self._statefile_path, encoding="utf-8") as statefile:
55 self._state = json.load(statefile)
56 except (OSError, ValueError, KeyError):
57 # Explicitly suppressing exceptions, since we don't want to
58 # error out if the cache file is invalid.
59 pass
60
for i

References SelfCheckState._state, CharSetGroupProber._state, CharSetProber._state, EscCharSetProber._state, EUCJPProber._state, Latin1Prober._state, MacRomanProber._state, MultiByteCharSetProber._state, SingleByteCharSetProber._state, SJISProber._state, UTF1632Prober._state, UTF8Prober._state, and GzipDecoder._state.

Referenced by Protocol.__init_subclass__().

Here is the caller graph for this function:

Member Function Documentation

◆ get()

Optional[str] get (   self,
datetime.datetime  current_time 
)
Check if we have a not-outdated version loaded already.

Definition at line 65 of file self_outdated_check.py.

65 def get(self, current_time: datetime.datetime) -> Optional[str]:
66 """Check if we have a not-outdated version loaded already."""
67 if not self._state:
68 return None
69
70 if "last_check" not in self._state:
71 return None
72
73 if "pypi_version" not in self._state:
74 return None
75
76 seven_days_in_seconds = 7 * 24 * 60 * 60
77
78 # Determine if we need to refresh the state
79 last_check = datetime.datetime.strptime(self._state["last_check"], _DATE_FMT)
80 seconds_since_last_check = (current_time - last_check).total_seconds()
81 if seconds_since_last_check > seven_days_in_seconds:
82 return None
83
84 return self._state["pypi_version"]
85

References SelfCheckState._state, CharSetGroupProber._state, CharSetProber._state, EscCharSetProber._state, EUCJPProber._state, Latin1Prober._state, MacRomanProber._state, MultiByteCharSetProber._state, SingleByteCharSetProber._state, SJISProber._state, UTF1632Prober._state, UTF8Prober._state, GzipDecoder._state, and i.

Referenced by LegacyMetadata.__getitem__(), Layout.__getitem__(), LegacyMetadata.check(), ThemeStack.push_theme(), and LegacyMetadata.write_file().

Here is the caller graph for this function:

◆ key()

str key (   self)

Definition at line 62 of file self_outdated_check.py.

62 def key(self) -> str:
63 return sys.prefix
64

References i.

Referenced by Matcher.__eq__(), Matcher.__hash__(), and SelfCheckState.set().

Here is the caller graph for this function:

◆ set()

None set (   self,
str  pypi_version,
datetime.datetime  current_time 
)

Definition at line 86 of file self_outdated_check.py.

86 def set(self, pypi_version: str, current_time: datetime.datetime) -> None:
87 # If we do not have a path to cache in, don't bother saving.
88 if not self._statefile_path:
89 return
90
91 # Check to make sure that we own the directory
92 if not check_path_owner(os.path.dirname(self._statefile_path)):
93 return
94
95 # Now that we've ensured the directory is owned by this user, we'll go
96 # ahead and make sure that all our directories are created.
97 ensure_dir(os.path.dirname(self._statefile_path))
98
99 state = {
100 # Include the key so it's easy to tell which pip wrote the
101 # file.
102 "key": self.key,
103 "last_check": current_time.strftime(_DATE_FMT),
104 "pypi_version": pypi_version,
105 }
106
107 text = json.dumps(state, sort_keys=True, separators=(",", ":"))
108
109 with adjacent_tmp_file(self._statefile_path) as f:
111
112 try:
113 # Since we have a prefix-specific state file, we can just
114 # overwrite whatever is there, no need to check.
115 replace(f.name, self._statefile_path)
116 except OSError:
117 # Best effort.
118 pass
119
120
121@dataclass

References SelfCheckState._statefile_path, i, SelfCheckState.key, SelfCheckState.key(), Distribution.key, Matcher.key, VersionScheme.key, Distribution.key(), and Requirement.key.

Referenced by LegacyMetadata.__setitem__(), RequestsCookieJar.__setitem__(), Flags.finalize_pending(), LegacyMetadata.read_file(), and LegacyMetadata.update().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ _state

◆ _statefile_path

_statefile_path
protected

Definition at line 46 of file self_outdated_check.py.

Referenced by SelfCheckState.set().

◆ key

key

Definition at line 51 of file self_outdated_check.py.

Referenced by Matcher.__eq__(), Matcher.__hash__(), and SelfCheckState.set().


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