Skip to content

Commit

Permalink
Merge pull request #40 from plone/deprecated-aliases
Browse files Browse the repository at this point in the history
Deprecated aliases
  • Loading branch information
tisto committed Oct 6, 2013
2 parents 7b98e04 + 7b95d77 commit 1b7b9dd
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
10 changes: 9 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Change history
**************

1.0b5 (unreleased)
------------------

- Rename 'deprecated-alias' to 'deprecated-aliases' and keep backward
compatibility.
[hvelarde]


1.0b4 (2013-10-06)
------------------

Expand All @@ -16,7 +24,7 @@ Change history
- Remove unused CSSLINT_IGNORE remainings.
[timo]

- Simpilfy code analysis method and make it more readable.
- Simpifly code analysis method and make it more readable.
[timo]


Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ The recipe supports the following options:
**zptlint-bin**
Set the path to a custom version of zptlint. Default is ``bin/zptlint``.

**deprecated-alias**
If set to True, warnings about deprecated alias will be printed. Default
**deprecated-aliases**
If set to True, warnings about deprecated aliases will be printed. Default
is ``False``.

**utf8-header**
Expand Down
2 changes: 1 addition & 1 deletion buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pre-commit-hook = True
clean-lines = True
csslint = True
debug-statements = True
deprecated-alias = True
deprecated-aliases = True
find-untranslated = True
flake8-max-complexity = 12
i18ndude-bin = ${buildout:directory}/bin/i18ndude
Expand Down
4 changes: 2 additions & 2 deletions plone/recipe/codeanalysis/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ install them on the system::
True


Deprecate method analysis script is installed::
Deprecated aliases analysis script is installed::

>>> '/sample-buildout/bin/code-analysis-deprecated-alias' in buildout_output_lower
>>> '/sample-buildout/bin/code-analysis-deprecated-aliases' in buildout_output_lower
True

The script to check if python files have an utf-8 encoding header is installed::
Expand Down
43 changes: 31 additions & 12 deletions plone/recipe/codeanalysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,19 @@ def __init__(self, buildout, name, options):
self.options.setdefault('zptlint-bin', os.path.join(
self.buildout['buildout']['bin-directory'], 'zptlint'
))
# Warn about usage of deprecated alias
self.options.setdefault('deprecated-alias', 'False')
# Warn about usage of deprecated aliases
self.options.setdefault('deprecated-aliases', 'False')
# XXX: keep compatibility with previous versions
if self.options['deprecated-aliases'] == 'False':
self.options.setdefault('deprecated-alias', 'False')
deprecated_alias = self.options['deprecated-alias']
if deprecated_alias == 'False':
self.options.setdefault('deprecated-methods', 'False')
deprecated_methods = self.options['deprecated-methods']
if deprecated_methods != 'False':
self.options['deprecated-aliases'] = deprecated_methods
else:
self.options['deprecated-aliases'] = deprecated_alias
# utf-8 header
self.options.setdefault('utf8-header', 'False')
# clean lines
Expand Down Expand Up @@ -137,8 +148,8 @@ def install_scripts(self):
{'suffix': 'csslint', },
# bin/code-analysis-zptlint
{'suffix': 'zptlint', },
# bin/code-analysis-deprecated-alias
{'suffix': 'deprecated-alias', },
# bin/code-analysis-deprecated-aliases
{'suffix': 'deprecated-aliases', },
# bin/code-analysis-utf8-header
{'suffix': 'utf8-header', },
# bin/code-analysis-clean-lines
Expand Down Expand Up @@ -225,7 +236,7 @@ def code_analysis(options):
['jshint', code_analysis_jshint(options)],
['csslint', code_analysis_csslint(options)],
['zptlint', code_analysis_zptlint(options)],
['deprecated-alias', code_analysis_deprecated_alias(options)],
['deprecated-aliases', code_analysis_deprecated_aliases(options)],
['utf8-header', code_analysis_utf8_header(options)],
['clean-lines', code_analysis_clean_lines(options)],
['prefer-single-quotes', code_analysis_prefer_single_quotes(options)],
Expand All @@ -250,10 +261,18 @@ def code_analysis(options):
exit(0)


def code_analysis_deprecated_alias(options):
sys.stdout.write('Deprecated alias ')
def code_analysis_deprecated_aliases(options):
sys.stdout.write('Deprecated aliases')
sys.stdout.flush()

# XXX: advice on usage of the right name
if options['deprecated-methods'] != 'False':
sys.stdout.write('deprecated-methods option is deprecated; '
'use deprecated-aliases instead.')
if options['deprecated-alias'] != 'False':
sys.stdout.write('deprecated-alias option is deprecated; '
'use deprecated-aliases instead.')

files = _find_files(options, '.*\.py')
if not files:
print(' [\033[00;32m OK \033[0m]')
Expand All @@ -263,7 +282,7 @@ def code_analysis_deprecated_alias(options):
file_paths = files.strip().split('\n')
for file_path in file_paths:
with open(file_path, 'r') as file_handler:
errors = _code_analysis_deprecated_alias_lines_parser(
errors = _code_analysis_deprecated_aliases_lines_parser(
file_handler.readlines(), file_path)

if len(errors) > 0:
Expand All @@ -279,13 +298,13 @@ def code_analysis_deprecated_alias(options):
return True


def _code_analysis_deprecated_alias_lines_parser(lines, file_path):
def _code_analysis_deprecated_aliases_lines_parser(lines, file_path):
errors = []
linenumber = 0

# Keep adding deprecated alias and its newer counterparts as:
# Keep adding deprecated aliases and its newer counterparts as:
# NEWER_VERSION : (LIST OF OLD METHODS)
deprecated_alias = {
deprecated_aliases = {
'assertEqual': ('failUnlessEqual', 'assertEquals', ), # noqa
'assertNotEqual': ('failIfEqual', ), # noqa
'assertTrue': ('failUnless', 'assert_', ), # noqa
Expand All @@ -304,7 +323,7 @@ def _code_analysis_deprecated_alias_lines_parser(lines, file_path):
if line.find('# noqa') != -1:
continue

for newer_version, old_alias in deprecated_alias.iteritems():
for newer_version, old_alias in deprecated_aliases.iteritems():
for alias in old_alias:
if line.find(alias) != -1:
errors.append(msg.format(
Expand Down

0 comments on commit 1b7b9dd

Please sign in to comment.