Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
ConfigOptionParser Class Reference
Inheritance diagram for ConfigOptionParser:
Collaboration diagram for ConfigOptionParser:

Public Member Functions

None __init__ (self, *Any args, str name, bool isolated=False, **Any kwargs)
 
Any check_default (self, optparse.Option option, str key, Any val)
 
optparse.Values get_default_values (self)
 
None error (self, str msg)
 
- Public Member Functions inherited from CustomOptionParser
optparse.OptionGroup insert_option_group (self, int idx, *Any args, **Any kwargs)
 
List[optparse.Option] option_list_all (self)
 

Data Fields

 name
 
 config
 
 values
 
 defaults
 

Protected Member Functions

Generator[Tuple[str, Any], None, None_get_ordered_configuration_items (self)
 
Dict[str, Any] _update_defaults (self, Dict[str, Any] defaults)
 

Detailed Description

Custom option parser which updates its defaults by checking the
configuration files and environmental variables

Definition at line 154 of file parser.py.

Constructor & Destructor Documentation

◆ __init__()

None __init__ (   self,
*Any  args,
str  name,
bool   isolated = False,
**Any  kwargs 
)

Definition at line 158 of file parser.py.

164 ) -> None:
165 self.name = name
166 self.config = Configuration(isolated)
167
168 assert self.name
169 super().__init__(*args, **kwargs)
170
for i

Referenced by Protocol.__init_subclass__().

Here is the caller graph for this function:

Member Function Documentation

◆ _get_ordered_configuration_items()

Generator[Tuple[str, Any], None, None] _get_ordered_configuration_items (   self)
protected

Definition at line 178 of file parser.py.

180 ) -> Generator[Tuple[str, Any], None, None]:
181 # Configuration gives keys in an unordered manner. Order them.
182 override_order = ["global", self.name, ":env:"]
183
184 # Pool the options into different groups
185 section_items: Dict[str, List[Tuple[str, Any]]] = {
186 name: [] for name in override_order
187 }
188 for section_key, val in self.config.items():
189 # ignore empty values
190 if not val:
192 "Ignoring configuration key '%s' as it's value is empty.",
193 section_key,
194 )
195 continue
196
197 section, key = section_key.split(".", 1)
198 if section in override_order:
199 section_items[section].append((key, val))
200
201 # Yield each group in their override order
202 for section in override_order:
203 for key, val in section_items[section]:
204 yield key, val
205

References ConfigOptionParser.config, BaseConfigurator.config, HTTPAdapter.config, Theme.config(), i, MunitParameterEnum.name, MunitParameter.name, MunitTest.name, MunitArgument_.name, Command.name, ConfigOptionParser.name, TransformedHit.name, _PackageInfo.name, InvalidWheel.name, BaseEntryPoint.name(), BasePath.name(), EntryPoint.name, InstallationCandidate.name, VcsInfo.name, ArchiveInfo.name, DirInfo.name, LinkHash.name, Wheel.name, LazyZipOverHTTP.name(), FrozenRequirement.name, InstallationResult.name, InstallRequirement.name(), InstallRequirement.name, Requirement.name(), Candidate.name(), _InstallRequirementBackedCandidate.name(), _InstallRequirementBackedCandidate.name, AlreadyInstalledCandidate.name, AlreadyInstalledCandidate.name(), ExtrasCandidate.name(), RequiresPythonCandidate.name(), ExplicitRequirement.name(), SpecifierRequirement.name(), RequiresPythonRequirement.name(), UnsatisfiableRequirement.name(), Bazaar.name, Mercurial.name, Subversion.name, VcsSupport.name, VersionControl.name, CodingStateMachineDict.name, Language.name, _Cache.name, Distribution.name, InstalledDistribution.name, EggInfoDistribution.name, LegacyMetadata.name, Metadata.name, ResourceBase.name, ExportEntry.name, Matcher.name, LinuxDistribution.name(), Formatter.name, BBCodeFormatter.name, GroffFormatter.name, HtmlFormatter.name, ImageFormatter.name, GifImageFormatter.name, JpgImageFormatter.name, BmpImageFormatter.name, IRCFormatter.name, LatexFormatter.name, NullFormatter.name, RawTokenFormatter.name, TestcaseFormatter.name, PangoMarkupFormatter.name, RtfFormatter.name, SvgFormatter.name, TerminalFormatter.name, Terminal256Formatter.name, TerminalTrueColorFormatter.name, Lexer.name, PythonLexer.name, Python2Lexer.name, _PythonConsoleLexerBase.name, PythonConsoleLexer.name, PythonTracebackLexer.name, Python2TracebackLexer.name, CythonLexer.name, DgLexer.name, NumPyLexer.name, ParserElement.name(), EditablePartial.name(), ElementState.name, LookupDict.name, Color.name, Emoji.name, Splitter.name, RowSplitter.name, ColumnSplitter.name, Layout.name, Tag.name, StockKeepingUnit.name, _Reader.name(), Frame.name, _LazyDescr.name, _SixMetaPathImporter.name, and Encoding.name.

Here is the call graph for this function:

◆ _update_defaults()

Dict[str, Any] _update_defaults (   self,
Dict[str, Any]  defaults 
)
protected
Updates the given defaults with values from the config files and
the environ. Does a little special handling for certain types of
options (lists).

Definition at line 206 of file parser.py.

206 def _update_defaults(self, defaults: Dict[str, Any]) -> Dict[str, Any]:
207 """Updates the given defaults with values from the config files and
208 the environ. Does a little special handling for certain types of
209 options (lists)."""
210
211 # Accumulate complex default state.
212 self.values = optparse.Values(self.defaults)
213 late_eval = set()
214 # Then set the options with those values
215 for key, val in self._get_ordered_configuration_items():
216 # '--' because configuration supports only long names
217 option = self.get_option("--" + key)
218
219 # Ignore options not present in this parser. E.g. non-globals put
220 # in [global] by users that want them to apply to all applicable
221 # commands.
222 if option is None:
223 continue
224
225 assert option.dest is not None
226
227 if option.action in ("store_true", "store_false"):
228 try:
229 val = strtobool(val)
230 except ValueError:
231 self.error(
232 "{} is not a valid value for {} option, " # noqa
233 "please specify a boolean value like yes/no, "
234 "true/false or 1/0 instead.".format(val, key)
235 )
236 elif option.action == "count":
237 with suppress(ValueError):
238 val = strtobool(val)
239 with suppress(ValueError):
240 val = int(val)
241 if not isinstance(val, int) or val < 0:
242 self.error(
243 "{} is not a valid value for {} option, " # noqa
244 "please instead specify either a non-negative integer "
245 "or a boolean value like yes/no or false/true "
246 "which is equivalent to 1/0.".format(val, key)
247 )
248 elif option.action == "append":
249 val = val.split()
250 val = [self.check_default(option, key, v) for v in val]
251 elif option.action == "callback":
252 assert option.callback is not None
254 opt_str = option.get_opt_string()
255 val = option.convert_value(opt_str, val)
256 # From take_action
257 args = option.callback_args or ()
258 kwargs = option.callback_kwargs or {}
259 option.callback(option, opt_str, val, self, *args, **kwargs)
260 else:
261 val = self.check_default(option, key, val)
262
263 defaults[option.dest] = val
264
265 for key in late_eval:
266 defaults[key] = getattr(self.values, key)
267 self.values = None
268 return defaults
269

◆ check_default()

Any check_default (   self,
optparse.Option  option,
str  key,
Any  val 
)

Definition at line 171 of file parser.py.

171 def check_default(self, option: optparse.Option, key: str, val: Any) -> Any:
172 try:
173 return option.check_value(key, val)
174 except optparse.OptionValueError as exc:
175 print(f"An error occurred during configuration: {exc}")
176 sys.exit(3)
177

References i.

◆ error()

None error (   self,
str  msg 
)

Definition at line 292 of file parser.py.

292 def error(self, msg: str) -> None:
293 self.print_usage(sys.stderr)
294 self.exit(UNKNOWN_ERROR, f"{msg}\n")

References i.

◆ get_default_values()

optparse.Values get_default_values (   self)
Overriding to make updating the defaults after instantiation of
the option parser possible, _update_defaults() does the dirty work.

Definition at line 270 of file parser.py.

270 def get_default_values(self) -> optparse.Values:
271 """Overriding to make updating the defaults after instantiation of
272 the option parser possible, _update_defaults() does the dirty work."""
273 if not self.process_default_values:
274 # Old, pre-Optik 1.5 behaviour.
275 return optparse.Values(self.defaults)
276
277 # Load the configuration, or error out in case of an error
278 try:
279 self.config.load()
280 except ConfigurationError as err:
281 self.exit(UNKNOWN_ERROR, str(err))
282
283 defaults = self._update_defaults(self.defaults.copy()) # ours
284 for option in self._get_all_options():
285 assert option.dest is not None
286 default = defaults.get(option.dest)
287 if isinstance(default, str):
288 opt_str = option.get_opt_string()
289 defaults[option.dest] = option.check_value(opt_str, default)
290 return optparse.Values(defaults)
291

Field Documentation

◆ config

◆ defaults

defaults

Definition at line 275 of file parser.py.

◆ name

name

Definition at line 165 of file parser.py.

Referenced by AlreadyInstalledCandidate.__eq__(), Distribution.__eq__(), ExportEntry.__eq__(), _LazyDescr.__get__(), Distribution.__hash__(), ElementState.__init__(), Requirement.__init__(), LinkHash.__post_init__(), InstallationCandidate.__repr__(), Distribution.__repr__(), Metadata.__repr__(), ExportEntry.__repr__(), Encoding.__repr__(), Color.__rich_repr__(), Layout.__rich_repr__(), InstallationCandidate.__str__(), InstalledDistribution.__str__(), EggInfoDistribution.__str__(), Requirement.__str__(), ParserElement.__str__(), Tag.__str__(), _SixMetaPathImporter._add_module(), Matcher._check_compatible(), InstallRequirement._get_archive_name(), Wheel._get_extensions(), _SixMetaPathImporter._get_module(), ConfigOptionParser._get_ordered_configuration_items(), Distribution._get_requirements(), _Cache.add(), InstallRequirement.archive(), LinkHash.as_dict(), LinkHash.as_hashes(), Wheel.build(), _Cache.clear(), Wheel.filename(), Layout.get(), InstallRequirement.get_dist(), InstalledDistribution.get_distinfo_file(), RequirementCommand.get_requirements(), Wheel.get_wheel_metadata(), InstallRequirement.install(), Wheel.install(), SpecifierRequirement.is_satisfied_by(), LinuxDistribution.linux_distribution(), Wheel.metadata(), Distribution.name_and_version(), InstallRequirement.prepare_metadata(), Distribution.provides(), Metadata.provides(), VcsSupport.register(), VersionControl.run_command(), InstallRequirement.uninstall(), Wheel.update(), and Wheel.verify().

◆ values

values

Definition at line 212 of file parser.py.


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