-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eliminate drivers and refactor configuration #259
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The drivers are an unnecessary copy-n-past complication. They can be replaced by a single classmethod which feeds the configuration directly to the constructor of the relevant class. To make this work smoothly, the constructor parameter names must match the config file parameter names exactly. While working on this change, we decided that we want a single source of parameter values. At present, any parameter value might come from the config file or from various constructor defaults. This will lead to confusion and subtle errors. So we have started to eliminate the default values in the constructors ... ... but then the units disappear, so we want units to be stated explicitly in the config file, which requires the config file parser to be rewritten to understand units.
The first step is to make it work for Irene. The other Cities will follow. The config file is now written in Python syntax and parsed with `exec`. Like this we do not need write our own parsers, for our own dodgy syntax with lots of dodgy exceptions. In short, DO NOT REINVENT THE WHEEL. Config file parsing is done in the context of `system_of_units`, this allowing specification of units simply by multiplying the value by any available unit, without qualification. Compound units are trivially catered for in this scheme. It's just pure Python. my_value = 12 * nm / s Consequently, everything disappears from the constructors: + parameter names + units + etc. The config file is now the sole source of documentation of the city parameters. The driver functions (same name as city, but uppercase) now disappear: a single `drive` method in the base city replaces them all.
We are no longer using our own parser: we let Python do the job for us.
These were used in combination with files_in and files out to to produce the final files_in and files_out settings used by the cities. This gained us nothing besides unnecessary complication of configuration parsing and handling.
s12_selector.conf is added as part of the configuration tree, in spite that there is no s12_selector city. It turns out that selectors are a different species than cities in sofar that they cannot be passed by inheritance (this would require double inheritance, something we want to avoid) but at the same time they can be re-used by several cities. Thus, it make sense to define default parameters for each selector we introduce. Several configuration files have been fixed to overwrite parameters such as input/output file name, which are city-specific (although a default is inherited from city).
It seems that skip is not used anywhere. Can it be removed? Verbosity isn't used either, but at least it's clear how it *might* be used.
The `--do-not-run` option has been added to allow inspection of a configuration without running the given city. By default, when an option is set in more than one place (multiple places in the same config file, or in an included file aswell as an including file), the printer shows the overridden values (the ones which were specified before the last one). This can be switched off with the `--no-overrides` option. By default, the names of the files in which any value was set (incuding overridden ones) is shown. By default, just the basename of the file (everything after the last `/`) is shown. Whether and how these file names are displayed can be controlled with the options + `--no-files` : do not show the names at all + `--full-files` : show fully qualified file names By default, the configuration is printed when any city is run. This can be suppressed with `--hide-config`.
It is a mandatory argument, and it is the *only* mandatory argument. Thus it makes sense to make it the only positional argument on the CLI.
jjgomezcadenas
approved these changes
Jun 28, 2017
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A major advance in the code. Good and well!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The driver functions for each city (the city name in uppercase) have been removed. They are all replaced with a single
drive
classmethod inCity
. This simplifies the code considerably and removes the copy-n-paste mess that has been growing an each new city was added.The city constructors no longer take and pass arguments explicitly by name, this is now achieved with
**kwds
. This closes Cities init method arguments #143 and has a number of consequencesThe config files are now written in Python syntax and parsed with Python's built-in parser. Our custom config parser for our ad-hoc config syntax has been thrown away and replaced with Python's parser. Do not re-invent the wheel.
The ability to inculde config files within other config files has been added, allowing the use of hierarchical configurations. Thus the default configuration of some base city does not need to be repeated in each concrete city's config file, as in can be included.
A new configuration printer has been added with the key abilities to
Improvements to the config printer are envisaged:
The mandatory
-c
(config file) command line option has been turned into a positional argument.(#203 has not been addressed at all here.)