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 0c0aa0f
Show file tree
Hide file tree
Showing 2 changed files with 123 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),)
77 changes: 77 additions & 0 deletions tests/general/CheckmanifestBearTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import shutil
import tempfile
from os import path
import unittest

from queue import Queue

from coalib.settings.Section import Section
from coalib.settings.Setting import Setting
from bears.general.CheckmanifestBear import CheckmanifestBear
from tests.LocalBearTestHelper import verify_local_bear


class CheckmanifestBearTest(unittest.TestCase):

def setUp(self):
self.test_dir = tempfile.mkdtemp()
self.testt_dir = tempfile.mkdtemp()
self.queue = Queue()
self.file_dict = {}
self.section = Section('test')
self.section.add_or_create_setting(Setting('ignore', 'unrelated.txt'))
self.uut = CheckmanifestBear(self.file_dict, self.section,
self.queue)

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

def run_uut(self, *args, **kwargs):
return list(result.message for result in self.uut.run())

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.testt_dir, 'setup.py'), 'w')
f.write('from setuptools import setup\n')
f.write("setup(name='sample', py_modules=['sample'])\n")
f.close()
with open(path.join(self.testt_dir, 'sample.py'), 'w') as f:
f.write('# wow. such code. so amaze\n')
f.close()

f = open(path.join(self.testt_dir, 'MANIFEST.in'), 'w')
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()
CheckmanifestBearTest_suggestion = verify_local_bear(
CheckmanifestBear, valid_files=(path.join(self.testt_dir,
'MANIFEST.in')),
invalid_files=(path.join(self.test_dir,
'MANIFEST.in')))

self.file_dict = {path.join(self.testt_dir, 'MANIFEST.in'):
""}
self.assertEqual(self.run_uut(), [])

f = open(path.join(self.testt_dir, 'unrelated.txt'), 'w')
f.write('Hello from the other side')
f.close()

CheckmanifestBearTest_suggestion = verify_local_bear(
CheckmanifestBear,
valid_files=(
path.join(self.test_dir,
'MANIFEST.in')),
invalid_files=(path.join(self.testt_dir, 'MANIFEST.in')),
settings={'ignore':
'unrelated.txt', 'create': 'True', 'update': 'True'})

0 comments on commit 0c0aa0f

Please sign in to comment.