Unable to run nbqa on notebooks present in directory without __init__.py
See original GitHub issueOS: 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?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
nbQA Documentation
Now, you'll be able to run the command from the previous section with just nbqa black notebook.ipynb. Much simpler!
Read more >python - Why can I import successfully without __init__.py?
While looking for a module or package named "foo", for each directory in the parent path: If <directory>/foo/__init__.py is found, a regular ...
Read more >How can I import code from the parent directory into ... - Reddit
If you run this before importing 'my_package', the notebook will be able to import utils.py - (you'll need an empty __init__.py file in...
Read more >How to Get NBA Data Using the nba_api Python Module ...
After this tutorial, you should be able to install the nba_api module ... look a few other starter notebooks that you can use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @MarcoGorelli, I am interested in contributing to this library. I use VSCode as IDE. I was going through nbqa library dev ecosystem, setting up its dependencies in VSCode. I have made some minor changes during this process. I have my local setup ready now, I will soon be sending out smaller PRs as mentioned.
Thanks @MarcoGorelli . I updated to latest release (0.1.22) and I didn’t face this issue.