Repository navigation
Convert config to a builder pattern - #11976
Conversation
| class ConfigBuilder(object): | ||
| """wptserve config | ||
|
|
||
| Inherits from Mapping for backwards compatibility with the old dict-based config""" |
There was a problem hiding this comment.
This docstring should belong to Config. And ConfigBuilder needs a new docstring of itself.
| hosts must be a list of all hosts to appear on the certificate, with | ||
| the primary hostname first.""" | ||
| hosts = tuple(sorted(hosts, key=lambda x:-len(x))) | ||
| hosts = tuple(sorted(hosts, key=lambda x:len(x))) |
There was a problem hiding this comment.
Why this change? (Although I don't know why it was originally sorted inversely, either.)
There was a problem hiding this comment.
I think this is expained in the commit message; we sort in order to get the top-level domain first. That wasn't what was happening ;)
There was a problem hiding this comment.
Ahh I didn't read the commit messages. Not sure if you plan to squash or rebase merge this, but as long as the message goes to the final history I'm happy.
| **kwargs): | ||
|
|
||
| self.log_level = kwargs.get("log_level", "DEBUG") | ||
| self._data = self._default.copy() |
There was a problem hiding this comment.
Nit: perhaps we can make self._default a frozendict for an extra layer of safety.
There was a problem hiding this comment.
Not sure it's worth implementing this or importing a third party package just for this.
| class ConfigBuilder(config.ConfigBuilder): | ||
| """serve config | ||
|
|
||
| this subclasses wptserve.config.Config to add serve config options""" |
There was a problem hiding this comment.
...subclasses wptserv.config.ConfigBuilder*...
| ssl={"type":"none"}) | ||
|
|
||
| print(make_hosts_file(config, kwargs["address"])) | ||
| with config_builder.get() as config: |
There was a problem hiding this comment.
I might have missed something but where is ConfigBuilder.get defined?
There was a problem hiding this comment.
That's just a bug; the initial iteration had a .get method. I'm surprised the tests didn't catch this.
There was a problem hiding this comment.
Sorry please disregard. I wrote too much code in blinkpy (which uses frozendict a lot) to the point I somehow thought PEP 416 was implemented...
There was a problem hiding this comment.
Reviewable status: 0 of 22 files reviewed, 8 unresolved discussions (waiting on @Hexcles, @jgraham, @dhdavvie, and @gsnedders)
tools/wptrunner/wptrunner/environment.py, line 107 at r1 (raw file):
self.cache_manager.__exit__(exc_type, exc_val, exc_tb) self.stash.__exit__() self.config_ctx.__exit__(exc_type, exc_val, exc_tb)
Is there any reason for this now being after self.stash.__exit__()? Or is the order arbitrary?
tools/wptrunner/wptrunner/wptrunner.py, line 39 at r1 (raw file):
""" print sslutils.__file__
stray print statement by the looks of it
61f224e to
e9d132b
Compare
| def ws_doc_root(self): | ||
| if self._ws_doc_root is not None: | ||
| return self._ws_doc_root | ||
| def _get_ws_doc_root(self, data): |
There was a problem hiding this comment.
I'm confused by this; we appear to have a private getter never called from anywhere?
There was a problem hiding this comment.
(Oh, it comes out of self.computed_properties. I'd much rather this more obvious rather than it appearing like this never gets called ever, especially when the call site is far away.)
There was a problem hiding this comment.
OK, so what do you suggest? The requirements are
- Properties must be computed in a defined order, since later properties often depend on earlier ones.
- Subclasses must be able to add to the list of properties in a relatively straightforward manner.
We could just have a list of methods to call on the class, but that's a bit ugly because they have to be defined at the bottom of the class definition whereas it's more usual to define data properties at the top.
There was a problem hiding this comment.
A comment pointing at how it gets called and turned into an actual property would probably be useful?
There was a problem hiding this comment.
Added something to the docstring for the class describing the protocol.
The names are expected to be sorted shortest first, but had the order reversed.
Hexcles
left a comment
There was a problem hiding this comment.
Reviewed 17 of 22 files at r1, 9 of 9 files at r2, 1 of 1 files at r3.
Reviewable status: 25 of 26 files reviewed, 3 unresolved discussions (waiting on @Hexcles and @jgraham)
tools/wpt/run.py, line 100 at r2 (raw file):
with config_builder as config: expected_hosts = set(config.domains_set) is_windows = platform.uname()[0] == "Windows"
Could you move this statement back (out of the with block)?
tools/wptrunner/wptrunner/wptrunner.py, line 39 at r1 (raw file):
Previously, dhdavvie (David H) wrote…
stray print statement by the looks of it
ping @jgraham
We have two sets of problems with the config: * It has to go to some lengths to be thread/process safe since several attributes are lazilly computed, and cached, by whichever thread happens to be first to access them. * The OpenSSL-based certificate implementation is totally broken because this class needs to be used as a context manager in order to initialise some resources associated with the fake CA used to generate the certificates. This suggests that the design is not really correct. We really want to generate the configuration once in a single process, and then share the generated configuration across multiple processes. We also want to ensure that the ssl environment is initialised once in the main process using a context manager. This patch introduces a ConfigBuilder object which allows configuration properties to be set. When used as a context manager, it computes the generated configuration, initalises the SSL environment, and updates the configuration with that data, and returns a config object with the final, immutable, configuration which may then be shared across processes.
This is fully obtainable from the config object.
Hexcles
left a comment
There was a problem hiding this comment.
Reviewable status: 23 of 26 files reviewed, 2 unresolved discussions (waiting on @Hexcles, @jgraham, and @dhdavvie)
The suite was broken by PR #11976 where the config class was changed. The suite uses a hack to get the default config of wptserve. This commit fixes the hack, but unfortunately does not find a less hacky way to get the default config.
The suite was broken by PR #11976 where the config class was changed. The suite uses a hack to get the default config of wptserve. This commit fixes the hack, but unfortunately does not find a less hacky way to get the default config.
This solves several problems with the curent design, notably:
This change is