-
Notifications
You must be signed in to change notification settings - Fork 581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP bears/general: Add CheckmanifestBear #1067
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,4 @@ vim-vint~=0.3.10 | |
vulture~=0.10.0 | ||
yamllint~=1.5 | ||
yapf~=0.14.0 | ||
check-manifest~=0.34 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import os | ||
|
||
from coalib.bearlib.abstractions.Linter import linter | ||
from dependency_management.requirements.PipRequirement import PipRequirement | ||
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY | ||
from coalib.bears.GlobalBear import GlobalBear | ||
from coalib.results.Result import Result | ||
from coalib.misc.Shell import run_shell_command | ||
from coalib.results.Diff import Diff | ||
|
||
|
||
class CheckmanifestBear(GlobalBear): | ||
""" | ||
Check MANIFEST.in in a Python source package for completeness | ||
|
||
Check https://pypi.python.org/pypi/rstcheck for more information. | ||
""" | ||
|
||
LANGUAGES = {'Python MANIFEST.in'} | ||
REQUIREMENTS = {PipRequirement('check-manifest', '0.34')} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Redundancy'} | ||
EXECUTABLE = 'check-manifest' | ||
|
||
def run(self, ignore: list=[]): | ||
""" | ||
Check MANIFEST.in in a Python source package for completeness | ||
|
||
Check https://pypi.python.org/pypi/rstcheck for more information. | ||
|
||
:param ignore: | ||
ignore files/directories matching these comma- | ||
separated patterns | ||
""" | ||
args = '' | ||
if ignore: | ||
args = ('--ignore=' + | ||
','.join(ignore),) | ||
|
||
output_message = 'suggested MANIFEST.in rules:' | ||
output, _ = run_shell_command( | ||
(self.EXECUTABLE,) + tuple(args) + | ||
tuple(os.path.dirname(filename) | ||
for filename in self.file_dict.keys())) | ||
to_search = output_message+'\n' | ||
|
||
temp_output = output.splitlines(1) | ||
if to_search in temp_output: | ||
index = temp_output.index(to_search) | ||
new_output = temp_output[index+1:] | ||
final_output = [x.strip(' ') for x in new_output] | ||
else: | ||
final_output = '' | ||
# Ignore LineLengthBear | ||
output_message = 'lists of files in version control and sdist match!' | ||
|
||
a = Diff(list(self.file_dict.values())[0]) | ||
a.add_lines(len(list(self.file_dict.values())[0]), final_output) | ||
|
||
yield Result(self, output_message, | ||
diffs={list(self.file_dict.keys())[0]: a}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import shutil | ||
import tempfile | ||
import platform | ||
import stat | ||
import os | ||
from os import path | ||
|
||
import unittest | ||
from queue import Queue | ||
from coalib.settings.Section import Section | ||
from coalib.misc.Shell import run_shell_command | ||
from bears.general.CheckmanifestBear import CheckmanifestBear | ||
|
||
|
||
class CheckmanifestBearTest(unittest.TestCase): | ||
|
||
@staticmethod | ||
def run_git_command(*args, stdin=None): | ||
run_shell_command(' '.join(('git',) + args), stdin) | ||
|
||
@staticmethod | ||
def _windows_rmtree_remove_readonly(func, path, excinfo): | ||
os.chmod(path, stat.S_IWRITE) | ||
func(path) | ||
|
||
def setUp(self): | ||
self.queue = Queue() | ||
self.file_dict = {} | ||
self.section = Section('Checkmanifest') | ||
self.uut = CheckmanifestBear(self.file_dict, self.section, | ||
self.queue) | ||
self._old_cwd = os.getcwd() | ||
self.test_dir = tempfile.mkdtemp() | ||
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') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
f.close() | ||
f = open(path.join(self.test_dir, 'unrelated.txt'), 'w') | ||
f.write('Hello from the other side') | ||
f.close() | ||
f = open(path.join(self.test_dir, 'rishu.cpp'), 'w') | ||
f.write('int main') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ouch this burns. Please make it a valid .cpp file. |
||
f.close() | ||
os.chdir(self.test_dir) | ||
self.run_git_command('init') | ||
self.run_git_command('config', 'user.email [email protected]') | ||
self.run_git_command('config', 'user.name coala') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code does not comply to PEP8. PEP8Bear, severity NORMAL, section The issue can be fixed by applying the following patch: --- a/tests/general/CheckmanifestBearTest.py
+++ b/tests/general/CheckmanifestBearTest.py
@@ -51,6 +51,7 @@
self.run_git_command('init')
self.run_git_command('config', 'user.email [email protected]')
self.run_git_command('config', 'user.name coala')
+
def tearDown(self):
os.chdir(self._old_cwd)
if platform.system() == 'Windows': |
||
self.run_git_command('add', '--all') | ||
|
||
def tearDown(self): | ||
os.chdir(self._old_cwd) | ||
if platform.system() == 'Windows': | ||
onerror = self._windows_rmtree_remove_readonly | ||
else: | ||
onerror = None | ||
shutil.rmtree(self.test_dir, onerror=onerror) | ||
|
||
def run_uut(self, *args, **kwargs): | ||
return list(result.message for result in self.uut.run(*args, **kwargs)) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code does not comply to PEP8. PEP8Bear, severity NORMAL, section The issue can be fixed by applying the following patch: --- a/tests/general/CheckmanifestBearTest.py
+++ b/tests/general/CheckmanifestBearTest.py
@@ -74,4 +74,3 @@
invalid_files=(path.join(self.testt_dir, 'MANIFEST.in')),
settings={'ignore':
'unrelated.txt', 'create': 'True', 'update': 'True'})
- |
||
def test_something(self): | ||
self.uut.file_dict = {path.join(self.test_dir, 'MANIFEST.in'): | ||
''} | ||
self.assertEqual(self.run_uut(ignore=['unrelated.txt', 'rishu.cpp']), | ||
['lists of files in version control and sdist match!']) # Ignore LineLengthBear | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you ignoring LineLengthBear ?? you can split this line into two... 😄 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. formatting is not the concern right now.. You can see
|
||
self.assertNotEqual(self.run_uut(), []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
main description missing