Skip to content

Commit

Permalink
WIP bears/general: Add CheckmanifestBear
Browse files Browse the repository at this point in the history
Adds CheckmanifestBear for https://pypi.python.org/pypi/check-manifest
to check MANIFEST.in for completeness.

Closes #798
  • Loading branch information
aptrishu committed Nov 27, 2016
1 parent 2988531 commit f6d0b48
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
46 changes: 46 additions & 0 deletions bears/general/CheckmanifestBear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os

from coalib.bearlib.abstractions.Linter import linter
from coalib.bears.requirements.PipRequirement import PipRequirement
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY


@linter(executable='check-manifest',
output_format='corrected',)
class CheckmanifestBear:
"""
Check MANIFEST.in in a Python source package for completeness
Check <https://pypi.python.org/pypi/rstcheck> for more information.
"""

LANGUAGES = {'MANIFEST.in'}
REQUIREMENTS = {PipRequirement('check-manifest', '0.34')}
AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'[email protected]'}
LICENSE = 'AGPL-3.0'
CAN_DETECT = {'Redundancy'}

@staticmethod
def create_arguments(filename, file, config_file,
create: bool=False, update: bool=False,
ignore: list=None):
"""
:param create:
create a MANIFEST.in if missing.
:param update:
append suggestions to MANIFEST.in (implies --create).
:param ignore:
ignore files/directories matching these comma-
separated patterns
"""
extra = ''
if create:
extra += '-c '
if update:
extra += '-u '
args = ()
if ignore:
args = (extra + '--ignore=' +
','.join(ignore),)
return args + (os.path.dirname(filename),)
47 changes: 47 additions & 0 deletions tests/general/CheckmanifestBearTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import shutil
import tempfile
from os import path
import unittest

from bears.general.CheckmanifestBear import CheckmanifestBear
from tests.LocalBearTestHelper import verify_local_bear


class TestExample(unittest.TestCase):

def setUp(self):
self.test_dir = tempfile.mkdtemp()

def tearDown(self):
shutil.rmtree(self.test_dir)

def test_something(self):
with open(path.join(self.test_dir, 'setup.py'), 'w') as f:
f.write("from setuptools import setup\n")
f.write("setup(name='sample', py_modules=['sample'])\n")
f.close()
with open(path.join(self.test_dir, 'sample.py'), 'w') as f:
f.write("# wow. such code. so amaze\n")
f.close()
f = open(path.join(self.test_dir, 'MANIFEST.in'), 'w')
f.close()
f = open(path.join(self.test_dir, 'unrelated.txt'), 'w')
f.write('Hello from the other side')
f.close()
# Start ignoring LineLengthBear
CheckmanifestBearTest_suggestion = verify_local_bear(
CheckmanifestBear, valid_files=(),
invalid_files=(path.join(self.test_dir,
'MANIFEST.in')))
CheckmanifestBearTest_suggestion = verify_local_bear(
CheckmanifestBear,
valid_files=(
path.join(self.test_dir,
'MANIFEST.in')),
invalid_files=(),
settings={"ignore":
"unrelated.txt"})
# Stop ignoring

if __name__ == '__main__':
unittest.main

0 comments on commit f6d0b48

Please sign in to comment.