A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/nbQA-dev/nbQA/issues/164 below:

Unable to run nbqa on notebooks present in directory without __init__.py · Issue #164 · nbQA-dev/nbQA · GitHub

OS: Ubuntu 18.04
nbqa version: 0.1.21

I have a notebook present in a directory which is not a python package. When i try to run the following command nbqa black <my_notebook_file>, I get a StopIteration exception traceback. I looked into the code and I was able to figure out why it is raising this exception.

def _create_blank_init_files(notebook: Path, tmpdirname: str) -> None:
    parts = notebook.resolve().relative_to(Path.cwd()).parts

    for idx in range(1, len(parts)):
        # next on directory with no __init__.py raises StopIteration exception
        init_file = next(Path(os.path.join(*parts[:idx])).glob("__init__.py"))
        if init_file is not None:
            Path(tmpdirname).joinpath(init_file).parent.mkdir(
                parents=True, exist_ok=True
            )
            Path(tmpdirname).joinpath(init_file).touch()

I fixed the code locally and ran isort, black, flake8 and mypy. This is the fix I made locally

import contextlib

def _create_blank_init_files(notebook: Path, tmpdirname: str) -> None:
    parts = notebook.resolve().relative_to(Path.cwd()).parts

    for idx in range(1, len(parts)):
        with contextlib.suppress(StopIteration):
            init_file = next(Path(os.path.join(*parts[:idx])).glob("__init__.py"))
            if init_file is not None:
                Path(tmpdirname).joinpath(init_file).parent.mkdir(parents=True, exist_ok=True)
                Path(tmpdirname).joinpath(init_file).touch()

Are you mandating the presence of __init__.py file in the directory of notebooks to run nbqa?


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4