Skip to content

Commit

Permalink
Merge branch 'bug/163' into 'master'
Browse files Browse the repository at this point in the history
Update setuptools integration for setup.cfg

*Description of changes*

Allow setuptools to parse config options from setup.cfg and pass them along via the attributes on our Flake8 command.

*Related to:*  #163

See merge request !67
  • Loading branch information
sigmavirus24 committed Jul 9, 2016
2 parents f93a3f3 + ae794fb commit 2e5100d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/flake8/main/setuptools_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from flake8.main import application as app

UNSET = object()


class Flake8(setuptools.Command):
"""Run Flake8 via setuptools/distutils for registered modules."""
Expand All @@ -21,11 +23,25 @@ class Flake8(setuptools.Command):

def initialize_options(self):
"""Override this method to initialize our application."""
pass
self.flake8 = app.Application()
self.flake8.initialize([])
options = self.flake8.option_manager.options
for option in options:
if option.parse_from_config:
setattr(self, option.config_name, UNSET)

def finalize_options(self):
"""Override this to parse the parameters."""
pass
options = self.flake8.option_manager.options
for option in options:
if option.parse_from_config:
name = option.config_name
value = getattr(self, name, UNSET)
if value is UNSET:
continue
setattr(self.flake8.options,
name,
option.normalize_from_setuptools(value))

def package_files(self):
"""Collect the files/dirs included in the registered modules."""
Expand Down Expand Up @@ -72,6 +88,5 @@ def distribution_files(self):

def run(self):
"""Run the Flake8 application."""
flake8 = app.Application()
flake8.run(list(self.distribution_files()))
flake8.exit()
self.flake8.run_checks(list(self.distribution_files()))
self.flake8.exit()
13 changes: 13 additions & 0 deletions src/flake8/options/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ def normalize(self, value):
return utils.parse_comma_separated_list(value)
return value

def normalize_from_setuptools(self, value):
"""Normalize the value received from setuptools."""
value = self.normalize(value)
if self.type == 'int' or self.action == 'count':
return int(value)
if self.action in ('store_true', 'store_false'):
value = str(value).upper()
if value in ('1', 'T', 'TRUE', 'ON'):
return True
if value in ('0', 'F', 'FALSE', 'OFF'):
return False
return value

def to_optparse(self):
"""Convert a Flake8 Option to an optparse Option."""
if self._opt is None:
Expand Down

0 comments on commit 2e5100d

Please sign in to comment.