Skip to content

Commit

Permalink
Improve warning message when a section contains unused options.
Browse files Browse the repository at this point in the history
This fixes #483
  • Loading branch information
jugmac00 committed Mar 29, 2021
1 parent b7c3849 commit 9b2a7d7
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 21 deletions.
1 change: 1 addition & 0 deletions news/483.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve warning message when a section contains unused options. (#483)
7 changes: 5 additions & 2 deletions src/zc/buildout/buildout.py
Original file line number Diff line number Diff line change
Expand Up @@ -2010,8 +2010,11 @@ def _check_for_unused_options_in_section(buildout, section):
unused = [option for option in sorted(options._raw)
if option not in options._data]
if unused:
buildout._logger.warning("Unused options for %s: %s."
% (section, ' '.join(map(repr, unused)))
buildout._logger.warning(
"Section `%s` contains unused option(s): %s.\n"
"This may be an indication for either a typo in the option's name "
"or a bug in the used recipe." %
(section, ' '.join(map(repr, unused)))
)

_usage = """\
Expand Down
3 changes: 2 additions & 1 deletion src/zc/buildout/tests/allowhosts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ https://bugs.launchpad.net/zc.buildout/+bug/239212::
... ''')
>>> print_('XX'); print_(system(buildout), end='') # doctest: +ELLIPSIS
X...
Unused options for buildout: 'foo'.
Section `buildout` contains unused option(s): 'foo'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.
Installing python...
Generated interpreter '/sample-buildout/bin/python'.

Expand Down
42 changes: 28 additions & 14 deletions src/zc/buildout/tests/extends-cache.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
Trying the same online, we can:

>>> print_(system(buildout))
Unused options for buildout: 'foo'.
Section `buildout` contains unused option(s): 'foo'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.

As long as we haven't said anything about caching downloaded configuration,
nothing gets cached. Offline mode will still cause the buildout to fail:
Expand All @@ -74,7 +75,8 @@ being a hash of the complete URL):
... """ % server_url)

>>> print_(system(buildout))
Unused options for buildout: 'foo'.
Section `buildout` contains unused option(s): 'foo'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.

>>> cache = join(sample_buildout, 'cache')
>>> ls(cache)
Expand All @@ -89,7 +91,8 @@ foo = bar
We can now run buildout offline as it will read base.cfg from the cache:

>>> print_(system(buildout + ' -o'))
Unused options for buildout: 'foo'.
Section `buildout` contains unused option(s): 'foo'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.

The cache is being used purely as a fall-back in case we are offline or don't
have access to a configuration file to be downloaded. As long as we are
Expand All @@ -105,23 +108,27 @@ base.cfg from the cache:
... """)

>>> print_(system(buildout + ' -o'))
Unused options for buildout: 'foo'.
Section `buildout` contains unused option(s): 'foo'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.

.. verify same behavior for install-from-cache:

>>> print_(system(buildout + ' install-from-cache=true download-cache=.'))
Unused options for buildout: 'foo'.
Section `buildout` contains unused option(s): 'foo'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.

In online mode, buildout will download and use the modified version:

>>> print_(system(buildout))
Unused options for buildout: 'bar'.
Section `buildout` contains unused option(s): 'bar'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.

Trying offline mode again, the new version will be used as it has been put in
the cache now:

>>> print_(system(buildout + ' -o'))
Unused options for buildout: 'bar'.
Section `buildout` contains unused option(s): 'bar'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.

Clean up:

Expand Down Expand Up @@ -212,7 +219,8 @@ Buildout will now assemble its configuration from all of these 6 files,
defaults first. The online resources end up in the respective extends caches:

>>> print_(system(buildout))
Unused options for buildout: 'foo'.
Section `buildout` contains unused option(s): 'foo'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.

>>> ls('user-cache')
- 10e772cf422123ef6c64ae770f555740
Expand Down Expand Up @@ -258,7 +266,8 @@ Let's rewrite the config files, clean out the caches and re-run buildout:
>>> remove('cache', os.listdir('cache')[0])

>>> print_(system(buildout))
Unused options for buildout: 'foo'.
Section `buildout` contains unused option(s): 'foo'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.

>>> ls('user-cache')
- 0548bad6002359532de37385bb532e26
Expand Down Expand Up @@ -336,7 +345,8 @@ Error: Couldn't download 'http://localhost/base.cfg' in offline mode.
... offline = true
... """ % server_url)
>>> print_(system(buildout))
Unused options for buildout: 'foo'.
Section `buildout` contains unused option(s): 'foo'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.

The ``install-from-cache`` option is treated accordingly:

Expand Down Expand Up @@ -429,7 +439,8 @@ A change to ``base.cfg`` is picked up on the next buildout run:
... foo = bar
... """)
>>> print_(system(buildout + " -n"))
Unused options for buildout: 'foo'.
Section `buildout` contains unused option(s): 'foo'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.
>>> cat('cache', os.listdir(cache)[0])
[buildout]
parts =
Expand All @@ -443,7 +454,8 @@ already present in the extends cache will not be updated:
... parts =
... """)
>>> print_(system(buildout + " -N"))
Unused options for buildout: 'foo'.
Section `buildout` contains unused option(s): 'foo'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.
>>> cat('cache', os.listdir(cache)[0])
[buildout]
parts =
Expand Down Expand Up @@ -472,7 +484,8 @@ used:
... extends = %sbaseA.cfg %sbaseB.cfg
... """ % (server_url, server_url))
>>> print_(system(buildout + " -n"))
Unused options for buildout: 'bar' 'foo'.
Section `buildout` contains unused option(s): 'bar' 'foo'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.

(XXX We patch download utility's API to produce readable output for the test;
a better solution would re-use the logging already done by the utility.)
Expand All @@ -489,7 +502,8 @@ The URL http://localhost/baseA.cfg was downloaded.
The URL http://localhost/base.cfg was downloaded.
The URL http://localhost/baseB.cfg was downloaded.
Not upgrading because not running a local buildout command.
Unused options for buildout: 'bar' 'foo'.
Section `buildout` contains unused option(s): 'bar' 'foo'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.

>>> zc.buildout.download.Download.download = old_download

Expand Down
9 changes: 6 additions & 3 deletions src/zc/buildout/tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,8 @@ def bug_92891_bootstrap_crashes_with_egg_recipe_in_buildout_section():
Generated script '/sample-bootstrap/bin/buildout'.
>>> print_(system(os.path.join('bin', 'buildout')), end='')
Unused options for buildout: 'scripts' 'eggs'.
Section `buildout` contains unused option(s): 'eggs' 'scripts'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.
"""

Expand Down Expand Up @@ -1659,9 +1660,11 @@ def whine_about_unused_options():
>>> print_(system(buildout), end='')
Develop: '/sample-buildout/.'
Unused options for buildout: 'a'.
Section `buildout` contains unused option(s): 'a'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.
Installing foo.
Unused options for foo: 'z'.
Section `foo` contains unused option(s): 'z'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.
'''

def abnormal_exit():
Expand Down
3 changes: 2 additions & 1 deletion src/zc/buildout/tests/update.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ directory:
Restarting.
Generated script '/sample-buildout/bin/buildout'.
Develop: '/sample-buildout/showversions'
Unused options for buildout: 'relative-paths'.
Section `buildout` contains unused option(s): 'relative-paths'.
This may be an indication for either a typo in the option's name or a bug in the used recipe.
Updating show-versions.
zc.buildout 99.99

Expand Down

0 comments on commit 9b2a7d7

Please sign in to comment.