Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I ended up spending an absurd amount of time on this, bouncing back and forth between abstracting away ConfigParser as much as possible, and integrating with ConfigParser as much as possible. At one point I had a pretty cool config section validation mechanism going based on
attrs
and type annotations (it lives tagged over here, I couldn't bear to outright delete it). What I've settled on feels somewhere between the two. Goals included:Change Summary
This "final" version makes these major changes:
diff-file
option to not create a diff file if the option isn't set.diff-file
option using the{{ section_option }}
syntax it supports.BandersnatchConfig
to not use the singleton pattern:BandersnatchConfig
to be a subclass ofConfigParser
:BandersnatchConfig
were just accessing the.config
attribute anyway, and I found this simplified some things.optionxform
inBandersnatchConfig
to allow either-
or_
in option names:_
and some using-
; this way makes it a user style preference, the ConfigParser will ingest either.default.conf
into two files:default.conf
andexample.conf
:example.conf
is the originaldefault.conf
renamed. It retains all the in-file comments and is the file written to disk by the main method if the config file path fromsys.argv
doesn't exist.default.conf
contains the default values for every option in the[mirror]
section, sans thedirectory
option.[mirror]
configuration default values fromdefault.conf
:mirror.directory
, all other options in the user'smirror
configuration replace the default values if specified.log-config
anddiff-file
where the default value is "nothing", but we still want to consistently allow safely reading these options without having to specify a default at the usage site. (As a concrete example,ConfigParser.has_option
no longer works to distinguish whetherlog-config
is set, because it will have a default value of""
.)TypedDict
class for the mirror section of the config file (bandersnatch.configuration.mirror_options
):TypedDict
seems minimally invasive since options can still be access through theMapping
interface supported by configparser'sSectionProxy
, and I had done enough damage to theBandersnatchMirror
initializer already.PurePath
- an "abstract" path representation that can be passed to a storage plugin'sPATH_BACKEND
.Enum
types are converted to that type.str
,int
,float
, andbool
use the underlying configparser "getters".str
values that can't be empty are checkedint
andfloat
values are range checked (non-negative, max values forworkers
andverifiers
)BandersnatchConfig
gets a method to run the validation/conversion function and caches the result, so the validated options can be accessed through that method multiple times without re-running the validationSingleton
, changing how defaults get loaded, and addingMirrorOptions
, most of the unit tests were changed somehow. Many are mechanical transformations in test setup steps. The configuration tests were rewritten from unittest to pytest since I needed to update or replace the majority of those tests regardless.Tasks
Some things still left to do...
delete
andverify
subcommands fetching of mirror optionsexample.conf
to include barebones plugin configurationRelated Issues