Skip to content

Commit

Permalink
Merge 39e2f43 into 26ec262
Browse files Browse the repository at this point in the history
  • Loading branch information
gforcada committed Dec 31, 2015
2 parents 26ec262 + 39e2f43 commit 4407145
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
10 changes: 8 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Change history
==============

2.1.1 (unreleased)
------------------
2.2 (unreleased)
----------------

- Allow to pass a folder where to run code analysis against.
[gforcada]
Expand All @@ -11,6 +11,12 @@ Change history
checks with exceptions in plugins as passed.
[do3cc]

- Add a zest.releaser entry point to run code-analysis before releasing.
It allows to save the output on a ``status.rst`` file meant to be
added on the package's long description (so it shows up on PyPI).
Fixes https://github.com/plone/plone.recipe.codeanalysis/issues/154
[gforcada]

2.1 (2015-09-21)
----------------

Expand Down
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,14 @@ system:
Allows you to specify directories and/or files which you don't want to be
checked. Default is none.

zest.releaser plugin
====================

plone.recipe.codeanalysis integrates with `zest.releaser`_ on the pre-release stage.

It runs code-analysis, it shows the result to the user and it allows to write them on a ``status.rst``.

This file is meant to be used to add it on setup.py's long description so that it shows up on PyPI.

Known Issues
============
Expand Down Expand Up @@ -469,3 +477,4 @@ Upgrade JSHint to latest version (>= 2.1.6) to fix this issue, e.g.::
.. _`Unit testing framework documentation`: http://docs.python.org/2/library/unittest.html#deprecated-aliases
.. _`Mockup`: https://github.com/plone/mockup
.. _`jscs website`: https://www.npmjs.org/package/jscs
.. _`zest.releaser`: https://pypi.python.org/pypi/zest.releaser
1 change: 1 addition & 0 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ zptlint-bin = ${buildout:directory}/bin/zptlint
[releaser]
recipe = zc.recipe.egg
eggs =
plone.recipe.codeanalysis [recommended]
zc.rst2
zest.releaser

Expand Down
57 changes: 57 additions & 0 deletions plone/recipe/codeanalysis/entry_points.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
from tempfile import mkdtemp

import os
import subprocess
import sys


def check(data):
"""Run p.r.codeanalysis when releasing with zest.releaser."""
from zest.releaser.utils import ask
if not ask('Run code analysis before tagging?'):
return

filename = '{0}/status.rst'.format(os.path.realpath(mkdtemp()))
try:
with open(filename, 'w') as output:
subprocess.call(['bin/code-analysis'], stdout=output)
with open(filename) as output:
print(''.join(output.readlines()))
except Exception as e:
print(e)
msg = 'Something went wrong when running "bin/code-analysis". ' \
'Do you want to continue despite that?'
if not ask(msg, default=False):
sys.exit(1)
else:
msg = 'Do you want to write code analysis result on status.rst?'
if ask(msg, default=True):
with open(filename) as output:
status_text = [
clean_line(line)
for line in output.readlines()
]

with open('status.rst', 'w') as code_analyis_file:
code_analyis_file.write(' ')
code_analyis_file.write(' '.join(status_text))

# It's nice to clean up the temporal file, but if something happens while
# trying to remove it, just ignore it
try:
os.remove(filename)
except Exception:
pass


def clean_line(line):
"""Remove console coloring from lines."""
# error (codes taken from Analyser.log)
line = line.replace('\033[00;31m', '')
line = line.replace('\033[0m', '')

# ok (codes taken from Analyser.colors)
line = line.replace('\033[00;32m', '')
line = line.replace('\033[0m', '')
return line
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ def read(*rnames):
entry_points = {
'zc.buildout': [
'default = {0:s}'.format(entry_point)
]
],
'zest.releaser.prereleaser.before': [
'run_prcodeanalysis = plone.recipe.codeanalysis.entry_points:check',
],
}

setup(name='plone.recipe.codeanalysis',
Expand Down Expand Up @@ -80,6 +83,7 @@ def read(*rnames):
'flake8-quotes',
'flake8-string-format',
'flake8-todo',
'zest.releaser',
],
},
test_suite='plone.recipe.codeanalysis.tests.test_docs.test_suite',
Expand Down

0 comments on commit 4407145

Please sign in to comment.