Skipping __init__.py files with iSort

1.5k Views Asked by At

I am working on a python package and in order to format imports I run isort on all the python files. I would like iSort to skip __init__.py files as in some (rare) cases the order of the imports is critical and does not line up with isort's ordering scheme.

I tried playing around with different configuration options in my pyproject.toml file and I believe I am looking for the extend_skip_glob configuration option. However, the issue is I am unable to figure out a glob pattern that matches any __init__.py file located in any subdirectory of src (where the code lives) located at any depth (I believe that's part of the issue I am experiencing).

I have tried a few combinations listed below, but none of them appear to be working.

[tool.isort]
# option 1
extend_skip_glob = ["__init__.py"]

# option 2
extend_skip_glob = ["src/**/__init__.py"]

# option 3
extend_skip_glob = ["src/**/*init__.py"]

Has anybody encountered something like this before and figured out a way to solve it?

1

There are 1 best solutions below

0
On

I think you should use skip instead. In pyproject.toml file for example,

[tool.isort]  
skip = ["__init__.py"]