Skip to content

Commit

Permalink
Eliminate drivers, refactor config and city constructors
Browse files Browse the repository at this point in the history
1. The driver functions for each city (the city name in uppercase)
   have been removed. They are all replaced with a single drive
   classmethod in City. This simplifies the code considerably and
   removes the copy-n-paste mess that has been growing an each new
   city was added.

2. The city constructors no longer take and pass arguments explicitly
   by name, this is now achieved with **kwds. This closes next-exp#143 and has
   a number of consequences Significant noise reduction in constructor
   definitions.  The config files become the sole source of

   + values of the parameters
   + documentation of what parameters are needed by each kind of city

3. The 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.

4. 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.

5. A new configuration printer has been added with the key abilities
   to

   + report the config file which provides any given value in an
     active configuration

   + highlight cases where a value set in one config file is
     overridden by a setting in another one.

    Improvements to the config printer are envisaged:

    + Displaying the comments from the config files.

    + Displaying the units used in the config files.

6. The mandatory -c (config file) command line option has been turned
   into a positional argument.

(next-exp#203 has not been addressed at all here.)
  • Loading branch information
jacg committed Jun 28, 2017
2 parents 95884ec + 263dc53 commit 07fb236
Show file tree
Hide file tree
Showing 33 changed files with 881 additions and 1,454 deletions.
9 changes: 6 additions & 3 deletions bin/city
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
from sys import argv
from importlib import import_module

_, city, *args = argv
_, *args = argv

city_name = args[0]

try:
command = getattr(import_module('invisible_cities.cities.'+city), city.upper())
module_name = 'invisible_cities.cities.' + city_name
city_class = getattr(import_module(module_name), city_name.capitalize())
except ModuleNotFoundError:
print('available cities: <TODO look at contents of config directory>')
print('usage TODO: <get this from our config parser>')
else:
command(['city {city}'.format(**locals())] + args)
city_class.drive(args)
Loading

0 comments on commit 07fb236

Please sign in to comment.