Skip to content

[per_dir_config] Moved option parsing outside of linter #1886

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

Merged
merged 2 commits into from
Feb 24, 2018

Conversation

AWhetter
Copy link
Contributor

@AWhetter AWhetter commented Feb 18, 2018

This removed the OptionsManagerMixin and OptionsProvider classes, meaning that the ConfigParser classes now handle the option parsing and the Runner organises these parsers.

New Tasks to do:

  • Fix all tests (The API may keep changing so I haven't fixed anything for now.
  • Figure out what API we want to give the PluginRegistry. Currently it's using a linter to pass attribute requests onto but ideally we would have a proper API on the registry which gets given to checkers and reporters. The PluginRegistry would then not need a linter instance.
  • Possibly split (parts of) the message handler mixin and reports handler mixin from the linter. As I've dug into how these classes work I've realised that they all rely on each other. It's probably not required for per directory configurations, but it would be a nice to have.
  • Figure out a better way of registering options. All of the config parsers (the CLIParser and the IniFileParser) need the option definitions and so does the Configuration. Registering a checker means registering options, which means the PluginRegistry needs a callback function to give these options to all of these options.
  • Possibly remove option definitions from Configuration object. Really the ConfigParser objects are responsible for setting the correct value type and on the correct destination, so a Configuration shouldn't need the option definitions. It can do it's merging using dict instead, so it'll behave a bit more like an argparse.Namespace.
  • Added parallel processing back in. For now it's easier to refactor without having to worry about parallel processing.
  • Various TODOs

Closes #972

Copy link
Contributor

@PCManticore PCManticore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AWhetter Looks pretty great! Thanks for the amazing work.
I did a pass through it, the changes seems pretty straightforward, so I left only a couple of nitpicks comments. Looking forward to have this whole refactoring merged in the mainline.

pylint/config.py Outdated
config = Config()
config.add_options(self._option_definitions)
config = Configuration()
config.add_options(six.iteritems(self._option_definitions))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to not use six.iteritems. When this patch will land, we will definitely be on Python 3+ only.

pylint/config.py Outdated
@@ -1014,8 +585,17 @@ def parse(self, file_path, config):
section = section.upper()

for option, value in self._parser.items(section):
if isinstance(value, six.string_types):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

@@ -216,58 +212,8 @@ def _patch_sysmodules():
}


if multiprocessing is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a new issue in the per dir config project, if we don't have one already, for adding this back after we consolidate the changes we need.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pylint/utils.py Outdated
"""
imported = {}
imported = set(('__init__', '__pycache__'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use set literals.

continue
except ImportError as exc:
print("Problem importing module %s: %s" % (filename, exc),
file=sys.stderr)
else:
if hasattr(module, 'register'):
module.register(linter)
imported[base] = 1
module.register(registry)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a note for the future, this will be incompatible with every current pylint plugin out there. Before shipping all these changes, we should have documentation in place on how to update to say pylint 2.0/3.0 (whenever this is going to land) and maybe we should also add some runtime errors that inform the users why their plugin stopped working.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I've added a task to the project for this: https://github.com/PyCQA/pylint/projects/1#card-7678953


option_groups = (
('Messages control', 'Options controlling analysis messages'),
('Reports', 'Options related to output formatting and reporting'),
)

def __init__(self, options=(), reporter=None, option_groups=(),
pylintrc=None):
def __init__(self, config=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one looks so much better

@@ -510,7 +420,7 @@ def _load_reporter(self):
self.set_reporter(reporter_class())

def _load_reporter_class(self):
qname = self._reporter_name
qname = self.config.output_format
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the reporter name equivalent with the format?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Currently PyLinter.set_option does this assignment (https://github.com/PyCQA/pylint/blob/master/pylint/lint.py#L546).

pylint/lint.py Outdated
def guess_lint_path(args):
"""Attempt to determine the file being linted from a list of arguments.

Args:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing, I noticed we are not consistent with the docstring styles, we either use Google's one or restructuredtext, we should probably stick to one or another.

pylint/lint.py Outdated
Yields:
BaseChecker: Each registered checker.
"""
for checkers in six.itervalues(self._checkers):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto regarding Python 3, this could be:

for checkers in self._checkers:
    yield from checkers

@AWhetter AWhetter merged commit fa045cf into per_dir_config Feb 24, 2018
@AWhetter AWhetter deleted the fix_972 branch February 24, 2018 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants