Skip to content
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

Discover Python files in dirs without Fixes #790 #951

merged 1 commit into from May 24, 2019
Changes from all commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.


Just for now

@@ -11,7 +11,8 @@
from .bulk_create import BulkCreateChecker
from .objects_update import ObjectsUpdateChecker
from .tags import TagsChecker
from .empty_module import EmptyModuleChecker
from .empty import EmptyModuleChecker
from .empty import ModuleInDirectoryWithoutInitChecker
from .nested_definition import NestedDefinitionChecker
from .missing_permissions import MissingPermissionsChecker

@@ -26,5 +27,6 @@ def register(linter):
@@ -0,0 +1,75 @@
# Copyright (c) 2018 Alexander Todorov <>

# Licensed under the GPL 2.0:

import os

from pylint import interfaces
from pylint import checkers
from pylint.checkers import utils

class EmptyModuleChecker(checkers.BaseChecker):
__implements__ = (interfaces.IAstroidChecker,)

name = 'empty-module-checker'

msgs = {'E4481': ("Remove empty module from git!",
"Kiwi TCMS doesn't need to carry around modules which are empty. "
"They must be removed from the source code!")}

def visit_module(self, node):
if not node.body and not node.path[0].endswith(''):
self.add_message('remove-empty-module', node=node)

class ModuleInDirectoryWithoutInitChecker(checkers.BaseChecker):
__implements__ = (interfaces.IAstroidChecker,)

name = 'dir-without-init-checker'

msgs = {'R4482': ("File '%s' is in directory without",
"Python module is found inside a directory which is "
"missing! This will lead to missing packages when "
"tarball is built for distribution on PyPI! See "

project_root = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..', 'tcms'))

# NOTE: this works against tcms/ directory and will not take into account
# if we want to examine only a sub-dir or a few files
# all files found by os.walk
all_python_files = set()
# all modules found by pylint, which conveniently skips files/dirs
# with missing
discovered_python_files = set()

def open(self):
for root, _dirs, files in os.walk(self.project_root, topdown=False):
# skip migrations
if root.find('migrations') > -1:

for file_name in files:
if file_name.endswith('.py'):
os.path.join(self.project_root, root, file_name))

def visit_module(self, node):
for file_name in node.path:

def close(self):
diff = self.all_python_files - self.discovered_python_files
diff = list(diff)

dir_prefix = os.path.dirname(self.project_root) + '/'
for fname in diff:
fname = fname.replace(dir_prefix, '')
self.add_message('module-in-directory-without-init', args=(fname,))

This file was deleted.

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.