Skip to content
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

Move argument validation outside of argparse #279

Merged

Conversation

@stadelmanma
Copy link
Contributor

stadelmanma commented Sep 9, 2018

Extracts the command line api configuration out into a separate module (configuration.py). The GcovrConfigOption classes store all of the necessary information to add themselves to an argparse parser and make that information easily accessible for any future configuration schemes. (The objects produced by add_argument are rather opaque.)

Todo:

  • Add unit tests (integration tests are probably already covered)

This is a building block for eventually addressing #229

@codecov

This comment has been minimized.

Copy link

codecov bot commented Sep 11, 2018

Codecov Report

Merging #279 into master will decrease coverage by 0.36%.
The diff coverage is 89.39%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #279      +/-   ##
==========================================
- Coverage   91.63%   91.27%   -0.37%     
==========================================
  Files          13       14       +1     
  Lines        1566     1581      +15     
  Branches      269      283      +14     
==========================================
+ Hits         1435     1443       +8     
- Misses         82       88       +6     
- Partials       49       50       +1
Impacted Files Coverage Δ
gcovr/__main__.py 94.53% <100%> (-1.26%) ⬇️
gcovr/configuration.py 86.79% <86.79%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d1e8cac...3e2bf79. Read the comment docs.

Copy link
Member

latk left a comment

A few minor concerns, mostly related to pre-3.6 compatibility.

If you want to you can address them, otherwise I'll fix them before merging. I'll try to merge on Friday. As part of that I'll force-push a simplified commit history onto your pull request branch.

key in the GCOVR_CONFIG_OPTION_GROUPS dictionary.
"""

def __init__(self, name, *flags, **kwargs):

This comment has been minimized.

Copy link
@latk

latk Sep 12, 2018

Member

Do we have to use **kwargs here, or can we enumerate all supported option-fields? Due to Python-2 restrictions we can't really combine *flags varargs with explicit keyword-only arguments, so we'd have to pass in an explicit list/tuple of flags. Something like:

def __init__(self, name, flags=(), group=None, help=None, action=None):

...
GcovrConfigOption('foo', ['--foo'], help="frobnicate something", action='store_true')

… and so on, where everything after flags is intended to be used as a keyword-argument. This would allow us to get rid of some hasattr()/getattr() calls later, and clarifies the intended API.

kwargs = dict(self.__dict__)
for key in ["name", "flags", "group"]:
del kwargs[key]
kwargs = ['{k}={v!r}'.format(k=k, v=v) for k, v in kwargs.items()]

This comment has been minimized.

Copy link
@latk

latk Sep 12, 2018

Member

dict iteration order is undefined prior to Python 3.6. To get a stable repr() across runs we should sort the entries, e.g. [... for k, v in sorted(kwargs.items())].

parser.add_argument(self.name, **kwargs)


GCOVR_CONFIG_OPTION_GROUPS = {

This comment has been minimized.

Copy link
@latk

latk Sep 12, 2018

Member

dict order is undefined prior to Python 3.6. We can use collections.OrderedDict here so that the groups are always in the correct order

stadelmanma and others added 3 commits Jul 2, 2018
This creates an GcovrConfigOption class to handle the configuration. It
was designed with argparse in mind but it can also be adapted to other
systems. All config options are stored in the GCOVR_CONFIG_OPTIONS
list.

Initially there was also a class representing parsed values, so that we
can check whether a value has been set. Instead, argparse.SUPPRESS is
used to avoid a default assignment of None when the option has not been
provided.
  - explicitly specify all arguments instead of using kwargs

  - avoid unspecified dict iteration order prior to Python 3.6
@latk latk force-pushed the stadelmanma:move-argument-validation-outside-of-argparse branch from 3e2bf79 to d332597 Sep 14, 2018
The Travis/Python-3.4 build failed with an error within pkg_resources,
i.e. setuptools/pip infrastructure:
    AttributeError: _DistInfoDistribution__dep_map
Online sources indicate updating pip first should help.

The problem is that pytest depends on setuptools, and also on other
modules that require up to date setuptools during their installation.
Since their installation order is undefined, installation can fail if
setuptools isn't updated first.
@latk
latk approved these changes Sep 14, 2018
@latk latk merged commit 807bfea into gcovr:master Sep 14, 2018
4 checks passed
4 checks passed
codecov/patch 97.36% of diff hit (target 91.63%)
Details
codecov/project 91.64% (+<.01%) compared to d1e8cac
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.