Skip to content

Commit

Permalink
PyromaBear: Add PyromaBear
Browse files Browse the repository at this point in the history
Add PyromaBear for checking Python packaging
best practices.

Closes coala#792
  • Loading branch information
pratyushprakash committed Jan 21, 2017
1 parent e4daf7e commit 7f3c97e
Show file tree
Hide file tree
Showing 14 changed files with 190 additions and 0 deletions.
1 change: 1 addition & 0 deletions bear-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pycodestyle~=2.2
pydocstyle~=1.1
pyflakes~=1.4.0
pylint~=1.6
pyroma~=2.2.0
pyyaml~=3.12
radon==1.4.0
requests~=2.12
Expand Down
43 changes: 43 additions & 0 deletions bears/python/PyromaBear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os.path
import pyroma

from coalib.bears.GlobalBear import GlobalBear
from dependency_management.requirements.PipRequirement import PipRequirement
from coalib.results.Result import Result


class PyromaBear(GlobalBear):
LANGUAGES = {'Python', 'Python 3'}
REQUIREMENTS = {PipRequirement('pyroma', '2.2.0')}
AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'[email protected]'}
LICENSE = 'AGPL-3.0'

def run(self):
"""
Checks for Python packaging best practices using `pyroma`.
Pyroma rhymes with aroma, and is a product aimed at giving a rating of
how well a Python project complies with the best practices of the
Python packaging ecosystem, primarily PyPI, pip, Distribute etc,
as well as a list of issues that could be improved.
See <https://bitbucket.org/regebro/pyroma/> for more information.
"""

setup_files = [setup_file for setup_file in self.file_dict
if os.path.basename(setup_file) == 'setup.py']

if not setup_files:
yield Result(self, 'Your package does'
' not contain a setup file.')
else:
for setup_file in setup_files:
data = pyroma.projectdata.get_data(os.path.dirname(setup_file))
rating = pyroma.ratings.rate(data)
messages = rating[1]

for message in messages:
yield Result.from_values(origin=self,
message=message,
file=setup_file)
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ norecursedirs =
.vendor
vendor
tests/python/bandit_test_files
tests/python/pyroma_test_files
python_files = *Test.py
python_classes = *Test
python_functions = *_test
Expand Down
59 changes: 59 additions & 0 deletions tests/python/PyromaBearTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import unittest
import os.path
from queue import Queue

from coalib.settings.Section import Section
from bears.python.PyromaBear import PyromaBear


def get_testdir_path(name):
return os.path.join(os.path.dirname(__file__), 'pyroma_test_files', name)


def get_message_list(results):
return [result.message for result in results]


class PyromaBearTest(unittest.TestCase):

def setUp(self):
self.section = Section('name')
self.queue = Queue()
self.file_dict = {}

def get_results(self, name):
setup_file = os.path.join(get_testdir_path(name), 'setup.py')
if os.path.isfile(setup_file):
self.file_dict[setup_file] = ''
self.uut = PyromaBear(self.file_dict, self.section, self.queue)
return list(self.uut.run())

def test_complete(self):
results = self.get_results('complete')
self.assertEqual(results, [])

def test_no_setup(self):
results = self.get_results('no_setup')
message_list = get_message_list(results)
self.assertEqual(message_list,
['Your package does not contain a setup file.'])

def test_minimal(self):
results = self.get_results('minimal')
message_list = get_message_list(results)
self.assertEqual(message_list, [
"The package's version number does not comply "
'with PEP-386 or PEP-440.',
"The package's description should be longer than 10 characters.",
"The package's long_description is quite short.",
'Your package does not have classifiers data.',
'You should specify what Python versions you support.',
'Your package does not have keywords data.',
'Your package does not have author data.',
'Your package does not have author_email data.',
'Your package does not have url data.',
'Your package does not have license data.',
'You are using Setuptools or Distribute but do not specify if '
'this package is zip_safe or not. You should specify it, as it '
'defaults to True, which you probably do not want.',
])
Empty file.
3 changes: 3 additions & 0 deletions tests/python/pyroma_test_files/complete/complete/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import os

print(os.__doc__)
7 changes: 7 additions & 0 deletions tests/python/pyroma_test_files/complete/complete/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import unittest


class PackageDataTest(unittest.TestCase):

def test_test(self):
pass
3 changes: 3 additions & 0 deletions tests/python/pyroma_test_files/complete/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[egg_info]
tag_build = .dev1
tag_svn_revision = false
51 changes: 51 additions & 0 deletions tests/python/pyroma_test_files/complete/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from setuptools import setup, find_packages

version = '1.0'

long_description = """
This is a long descpription.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed porttitor, neque
at dignissim condimentum, libero est dictum dolor, sit amet tempor urna
diam eget velit. Suspendisse at odio quam, ut vestibulum ipsum. Nulla
facilisi. Nullam nunc dolor, tempus in vulputate id, fringilla eget metus.
Pellentesque nulla nisl, imperdiet ac vulputate non, commodo tincidunt
purus. Aenean sollicitudin orci eget diam dignissim scelerisque. Donec quis
neque nisl, eu adipiscing velit. Aenean convallis ante sapien. Etiam vitae
viverra libero. Nullam ac ligula erat. Aliquam pellentesque, est eget
faucibus pharetra, urna orci rhoncus nisi, adipiscing elementum liber
lectus ut odio. Duis tincidunt mi quam, quis interdum enim. Nunc sed urna
urna, id lacinia turpis. Quisque malesuada, velit ut tincidunt lacinia,
dolor augue varius velit, in ultrices lectus enim et dolor. Fusce augue eros,
aliquet ac dapibus at, tincidunt vitae leo. Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Vivamus sapien neque, fermentum sed ultrices
sit amet, fermentum nec est. Pellentesque imperdiet enim nec velit posuere
id dignissim massa molestie.
"""

setup(name='complete',
version=version,
description='This is a test package for pyroma.',
long_description=long_description,
classifiers=['Development Status :: 6 - Mature',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.1',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
],
keywords=['pypi', 'quality', 'example'],
author='Jon Smith',
author_email='[email protected]',
url='http://jonsmith.com',
license='MIT',
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
include_package_data=True,
install_requires=['zope.event'],
tests_require=['six'],
setup_requires=['setuptools'],
zip_safe=True,
test_suite='complete',
)
Empty file.
Empty file.
22 changes: 22 additions & 0 deletions tests/python/pyroma_test_files/minimal/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from setuptools import setup, find_packages

version = '0.0foo'

setup(name='minimal',
version=version,
description='Test',
classifiers=[],
keywords='',
author='',
author_email='',
url='',
license='',
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
include_package_data=True,
install_requires=[
# -*- Extra requirements: -*-
],
entry_points="""
# -*- Entry points: -*-
""",
)
Empty file.
Empty file.

0 comments on commit 7f3c97e

Please sign in to comment.