def run(self) -> YieldFlake8Error: """Run the check plugin.""" has_errors = False for err in Nitpick.current_app().init_errors: has_errors = True yield Nitpick.as_flake8_warning(err) if has_errors: return [] current_python_file = Path(self.filename) if current_python_file.absolute() != Nitpick.current_app( ).main_python_file.absolute(): # Only report warnings once, for the main Python file of this project. LOGGER.info("Ignoring file: %s", self.filename) return [] LOGGER.info("Nitpicking file: %s", self.filename) yield from itertools.chain(Nitpick.current_app().config.merge_styles(), self.check_files(True), self.check_files(False)) has_errors = False for err in Nitpick.current_app().style_errors: has_errors = True yield Nitpick.as_flake8_warning(err) if has_errors: return [] for checker_class in get_subclasses(BaseFile): checker = checker_class() yield from checker.check_exists() return []
def run(self) -> YieldFlake8Error: """Run the check plugin.""" # An __init__() function is already provided by @attr.s self.config = NitpickConfig().get_singleton() # pylint: disable=attribute-defined-outside-init if not self.config.find_root_dir(self.filename): yield self.flake8_error(1, "No root dir found (is this a Python project?)") return [] if not self.config.find_main_python_file(): yield self.flake8_error( 2, "None of those Python files was found in the root dir" + " {}: {}".format(self.config.root_dir, ", ".join(ROOT_PYTHON_FILES)), ) return [] current_python_file = Path(self.filename) if current_python_file.absolute() != self.config.main_python_file.absolute(): # Only report warnings once, for the main Python file of this project. LOGGER.info("Ignoring file: %s", self.filename) return [] LOGGER.info("Nitpicking file: %s", self.filename) yield from itertools.chain(self.config.merge_styles(), self.check_absent_files()) for checker_class in get_subclasses(BaseFile): checker = checker_class() yield from checker.check_exists() return []
def load_fixed_dynamic_classes(cls) -> None: """Separate classes with fixed file names from classes with dynamic files names.""" cls.fixed_name_classes = set() cls.dynamic_name_classes = set() for subclass in get_subclasses(BaseFile): if subclass.file_name: cls.fixed_name_classes.add(subclass) else: cls.dynamic_name_classes.add(subclass)
def test_get_subclasses(): """Test subclasses.""" # pylint: disable=missing-docstring,too-few-public-methods class Vehicle: pass class Car(Vehicle): pass class Audi(Car): pass class Bicycle(Vehicle): pass assert_conditions(get_subclasses(Vehicle) == [Car, Audi, Bicycle])
def generate_config_files_rst(): """Generate config_files.rst with the docstrings from BaseFile classes.""" rst_file = docs_dir / "config_files.rst" # type: Path template = """ .. _{link}: {header} {dashes} {description} """ clean_template = dedent(template).strip() blocks = [] for file_class in file_classes: header = file_class.file_name if not header: # module_name = file_class.__module__ module = import_module(file_class.__module__) header = module.__doc__.strip(" .") stripped_lines = [ line.strip() for line in file_class.__doc__.split("\n") ] blocks.append("") blocks.append( clean_template.format( link=slugify(file_class.__name__), header=header, dashes="-" * len(header), description="\n".join(stripped_lines).strip(), )) write_rst(rst_file, blocks) existing = set(get_subclasses(BaseFile)) documented = set(file_classes) something_missing = existing - documented for missing_class in something_missing: click.secho( "ERROR: Add missing base file {} to the 'file_classes' var in '{}'." .format(missing_class.__name__, __file__), fg="red", ) if something_missing: sys.exit(1)