forked from coala/coala-bears
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PyromaBear for checking Python packaging best practices. Closes coala#792
- Loading branch information
1 parent
e4daf7e
commit 7f3c97e
Showing
14 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import os | ||
|
||
print(os.__doc__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[egg_info] | ||
tag_build = .dev1 | ||
tag_svn_revision = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.